ty
Katalon Apprentice
01/08/2018

How to pass user defined parameters from command line

Katalon has some defined properties that you can set the value to be pass as  parameters from the command line.  However, how do you defined and pass user-defined parameters into katalon.  Example, i want to use and pass a variable such as MYCONFIGFILE=test-aws.json into katalon so that inside my code, I can set that value to be used inside my script.  Any ideas?
Upvote
Quote

Comments

  • Liam B
    Katalon Moderator
    01/09/2018
    ty said:
    Katalon has some defined properties that you can set the value to be pass as  parameters from the command line.  However, how do you defined and pass user-defined parameters into katalon.  Example, i want to use and pass a variable such as MYCONFIGFILE=test-aws.json into katalon so that inside my code, I can set that value to be used inside my script.  Any ideas?
    Hello Ty,

    Currently, Katalon Studio doesn't support passing defined parameters from the command line into Katalon Studio. I have logged this request to the development queue for further discussion. 

    If you have any further inputs, feel free to add so Katalon team better understand the brought value.

    Thank you for using Katalon Studio,
    Liam 
    Upvote
    Quote
  • ty
    Katalon Apprentice
    01/09/2018
    By allowing user to passed in user defined parameters, this will support scenario where the user wants to pass in a parameter to be used inside the scripts.  By the same convention already used,  the solution would either allow users to define their own parameters via command line or as part of the properties file.  Once the parameter is defined, then have a way to access that parameter inside the script.
    Upvote
    Quote
  • Radford Software Ltd.
    Katalon Apprentice
    01/10/2018
    We currently work around this by assigning Global variables to parameters and then just modifying the values of the GlobalVariables.glbl file in the project folder before running the tests. Not sure if that helps. 
    Upvote
    Quote
  • Manuel Wenk
    Katalon Apprentice
    02/05/2018
    We're currently evaluating Katalon. The location of our AUT does change, so I did create a Global-Variable called rootUrl. I would like to set the value from the command line (maybe something like this "katalon ... /set:rootUrl=https://stagingServer:4322"  to enable our build server to handle different urls.  
    Is this possible somehow? Can I use some other mechanism to do this?

    Cheers,
    Manuel

    Upvote
    Quote
  • Alexey Marin
    Katalon Apprentice
    02/09/2018
    I am also in need of this feature. Currently I replace `GlobalVariables.glbl` to work around this limitation, but a more straightforward way to pass parameters to the test suite will be much appreciated

    Upvote
    Quote
  • Russ Thomas
    Katalon Evangelist
    02/12/2018
    Upvote
    Quote
  • Dusko
    Katalon Apprentice
    02/15/2018
    +1
    Upvote
    Quote
  • Rasko Pjesivac
    Katalon Ambassador
    03/05/2018
    +10 :)
    Ideally, we could set all global variables via command line execution..
    something like this..
    katalon -noSplash  -runMode=console -projectPath="C:\Workspace\ABCTest\ABCTest.prj" -retry=0 -testSuitePath="Test Suites/QuickTests" -browserType="Chrome" -gURL="http://10.10.10.10" -gTitle="Passing Parameters from Jenkins to Katalon"

    where gURL and gTitle would be already defined global variables.

    Upvote
    Quote
  • Liam B
    Katalon Moderator
    03/06/2018
    Hey guys,

    As this feature request getting more traction, I will bring it up again with the team for sooner consideration. We actually have planned this feature in our roadmap. 

    Thank you for choosing and supporting Katalon products,
    Liam
    Upvote
    Quote
  • François Grossin
    Katalon Ambassador
    03/06/2018
    edited March 6
    +1
    Yes ! I do need to pass parameters as I do with Maven : -Dtest.environment=SIT

    This would be perfect.
    Upvote
    Quote
  • Rasko Pjesivac
    Katalon Ambassador
    03/13/2018
    I would still like a clean support from Katalon Studion on this but in the meantime this is a solution we have (and it works pretty nicely) and maybe some can find it useful.

    For example if we need to inject new test host (IP) address during Jenkins execution we do following.
    1. Create a Test Case (TC) that takes parameters. (local variable: BASEURL)
    2. Create a simple CSV data source file (inputDataFile.csv) with header BASEURL and maybe default value.
    3. Create a Test Suite (TS) and add our TC into the TS. Bind TC to data source from 2.

    Then as a part of Jenkins execution, before we execute our tests, we delete the inputDataFile.csv and we create a new one like this: (IP address is the new IP address we got from Jenkins)
      sudo echo BASEURL  >./FILELOCATION/inputFile.csv ;
      sudo echo http://192.227.63.72/ >>./FILELOCATION/inputFile.csv ; 
    and then we run the tests. Test will bind to a new value and it executes properly.

    Of course, this way you can add as many parameters as you need to your test case.


    Rasko
    Upvote
    Quote
  • kazurayam
    Katalon Evangelist
    03/27/2018
  • kazurayam
    Katalon Evangelist
    03/27/2018
  • Prasad Pomaji
    Katalon Apprentice
    04/06/2018
    edited April 6
    +10 :)
    Ideally, we could set all global variables via command line execution..
    something like this..
    katalon -noSplash  -runMode=console -projectPath="C:\Workspace\ABCTest\ABCTest.prj" -retry=0 -testSuitePath="Test Suites/QuickTests" -browserType="Chrome" -gURL="http://10.10.10.10" -gTitle="Passing Parameters from Jenkins to Katalon"

    where gURL and gTitle would be already defined global variables.

    Hi Rasko, I tried this appoach by passing global variables via command line, however the global variables are not actually updated in the Project. The katalon user guild for command line also does not mention passing properties with -g notation. Would be a good approach if this works. 
    Upvote
    Quote
  • kazurayam
    Katalon Evangelist
    04/07/2018
    edited April 7
    Here is my approach to the same issue:
    https://forum.katalon.com/discussion/5796/command-line-argument-dkatalon-user-home-xxxx

    I hope a single option -Dkatalon.user.home=<properties file path> supported by future Katalon Studio Console Mode 
    >.\katalon.exe -Dkatalon.user.home=C:\Users\myname\tmp\blue ...

    in the properties file you want to write whatever parameters you like:

    GlobalVariable.URL=http://10.10.10.10
    GlobalVariable.Title=Passing Parameters from Jenkins to Katalon

    In the TestLister, you can write code to load the properties and overwrite the Global variables yourself. My post describes how I implemented this.

    https://forum.katalon.com/discussion/5780/katalon-properties-file-and-jvm-system-property-katalon-user-home

    Upvote
    Quote
  • Robert Massa
    Katalon Apprentice
    04/10/2018
    Hello, just another +1 from us. We need this feature to be able to pass different variables from our CI environment to the test(s).
    Upvote
    Quote
  • Gaetano Claudio Cipriano
    Katalon Apprentice
    06/04/2018
    Another +1
    Upvote
    Quote
  • krishnaprasad
    Katalon Apprentice
    06/05/2018
    kazurayam said:
    Here is my approach to the same issue:
    https://forum.katalon.com/discussion/5796/command-line-argument-dkatalon-user-home-xxxx

    I hope a single option -Dkatalon.user.home=<properties file path> supported by future Katalon Studio Console Mode 
    >.\katalon.exe -Dkatalon.user.home=C:\Users\myname\tmp\blue ...

    in the properties file you want to write whatever parameters you like:

    GlobalVariable.URL=http://10.10.10.10
    GlobalVariable.Title=Passing Parameters from Jenkins to Katalon

    In the TestLister, you can write code to load the properties and overwrite the Global variables yourself. My post describes how I implemented this.

    https://forum.katalon.com/discussion/5780/katalon-properties-file-and-jvm-system-property-katalon-user-home

    Here, katalon.user.home will have path to the blue environment file and value from this file will be over written to global variables ..correct?


    Upvote
    Quote
  • kazurayam
    Katalon Evangelist
    06/05/2018
    edited June 6
    krishnaprasad,

    Here, katalon.user.home will have path to the blue environment file and value from this file will be over written to global variables ..correct?

    Yes, you understand correctly what I hoped at March 2018.

    Let me note:

    1. In April 2018, Katalon Studio 5.4.0 introduced the -executionPropfile=<profile name> switch as described at https://docs.katalon.com/display/KD/Console+Mode+Execution
    2. Katalon Studio 5.4+ does NOT support the -Dkatalon.user.home=<properties file path> switch which I proposed.
    Both ideas (-executionProfile and -Dkatalon.user.home) intended to implement a feature of overwriting global variables dynamically at runtime. These 2 approaches are similar, but not identical. The -executionProfile approach requires the new settings is still managed by Katalon Studio. The -Dkatalon.user.home approach accepts the new settings from anywhere: out of Katalon Studio's control.The Katalon team has chosen the -executionProfile approach and I respect it. 
    Upvote
    Quote
  • kazurayam
    Katalon Evangelist
    06/05/2018
    edited June 6
    The -executionProfile=<profile name> approach requires the new settings are still managed by Katalon Studio. If you want to set a credential (username/password pair) in the Execution Profile, you will want to encrypt it. Katalon Studio does provide a encryption feature as described at https://docs.katalon.com/display/KD/Working+with+Sensitive+Text

    However some people argue that the Katalon's encryption is not strong enough:
    https://forum.katalon.com/discussion/comment/16261#Comment_16261

    I think that it would be best secure if you entirely exclude the credential information out of the Katalon's project. My -Dkatalon.user.home=<properties file path> approach is meant for that.

    It depends how much of security you require for the testing fixtures. I do not like a username/password pair in the testing fixture to be visible as plain text. But I would accept it if encrypted even though the Katalon's encryption method is not superior. Because, in my case, the credentials in my testing fixture are not so much serious.
    Upvote
    Quote
  • Sergii Tyshchenko
    Katalon Apprentice
    06/11/2018
    edited June 11
    You can also define environment variable (with path to external configuration or properties file) in the session will be used to execute Katalon studio and then in the TestListener read the value of variable (path to the file), load that file and override settings for project, Global variables etc. To create new GlobalVariable I used metaprogramming:

    void addGlobalVariable(String name, def value) {
    MetaClass mc = script.evaluate("internal.GlobalVariable").metaClass
    String getterName = "get" + name.capitalize()
    mc.static."$getterName" = { -> return value }
    //mc.static."$name" = value
    }

    It's possible to add getter/setter as new methods to GlobalVariable class or add new field (commented in this example)
    Than in the script code you can use GlobalVariable.VarName where the VarName you new variable.
    Upvote
    Quote
  • Russ Thomas
    Katalon Evangelist
    06/11/2018
    That's pretty sweet, @Sergii

    Upvoted.
    Upvote
    Quote
  • Trong Bui
    Katalon Moderator
    07/10/2018
    You can also define environment variable (with path to external configuration or properties file) in the session will be used to execute Katalon studio and then in the TestListener read the value of variable (path to the file), load that file and override settings for project, Global variables etc. To create new GlobalVariable I used metaprogramming:

    void addGlobalVariable(String name, def value) {
    MetaClass mc = script.evaluate("internal.GlobalVariable").metaClass
    String getterName = "get" + name.capitalize()
    mc.static."$getterName" = { -> return value }
    //mc.static."$name" = value
    }

    It's possible to add getter/setter as new methods to GlobalVariable class or add new field (commented in this example)
    Than in the script code you can use GlobalVariable.VarName where the VarName you new variable.
    What is the 'script' variable in your example? It would be nice if others can execute your script for their cases.
    Upvote
    Quote
  • Jonathan Yeung
    Katalon Apprentice
    07/11/2018
    +1
    I would love to be able to pass user defined parameters to the test suite through the command line. Currently, I am running a test suite through Jenkins, and I would like to take advantage of parameterizing my Jenkins job so that my test suite can execute more accurately to my needs. I would use the parameters defined in my Jenkins job, and pass them into the batch command line for the test suite to use.
    Upvote
    Quote
  • Neacsu Cornel
    Katalon Apprentice
    07/20/2018
    +1 From here also.
    Upvote
    Quote
  • Michiel van Erp
    Katalon Apprentice
    08/31/2018
    +1 from me as well, in our case it would be nice to be able to run the same test suite for multiple environments.
    Upvote
    Quote
  • Aaron Sua
    Katalon Apprentice
    10/16/2018
    +1  Our CI-CD system spins up dynamically named environments, and URLs based on branch names.  It isn't possible to know what is and isn't going to be built and preload all these options as profiles within the GUI.  It is absolutely necessary to be able to provide a minimum set of variables at CLI execution.
    Upvote
    Quote
  • kazurayam
    Katalon Evangelist
    10/17/2018
    dynamically named environments, and URLs based on branch names.

    Could you please provide an example of this?

    Upvote
    Quote
  • Aaron Sua
    Katalon Apprentice
    10/17/2018
    The developer commits a feature branch to the repository.
    Jenkins builds an EC2 instance, registers an ssl cert, and deploys the build.
    the url is https://{{ branch_name }}-devui.windsorcircle.com

    or

    locally we frequently spin up multiple stacks to compare version1 to version2.  As such the container names are generated dynamically

    app_test_latest_branch1
    app_test_latest_branch2

    where each is accessible from a unique port 
    branch1 on http://localhost:8000 ;
    branch2 on http://localhost:8001
    Upvote
    Quote
  • Aaron Sua
    Katalon Apprentice
    10/17/2018
    if I copy the entire source to tmp it functions as a workaround
    Upvote
    Quote
Sign In or Register to comment.