How to pass runtime parameter (params) in Selenium Side runner?
I want to execute the Side file from command prompt and also pass various urls and user names as parameters to run. i tried selenium-side-runner --params "a='example-value'", it didn't work.
Related
Currently, I have a .ini file called testcase.ini which looks something like this:
[TEST]
DRIVER_PATH = C:\Python\
BROWSER = CHROME
; BROWSER = EDGE
; BROWSER = FIREFOX
CHROME_PATH = C:\Program Files\Google\Chrome\Application\chrome.exe
; EDGE_PATH = C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe
; FIREFOX_PATH = C:\Program Files\Mozilla Firefox\firefox.exe
To run my automated tests, I open a command prompt in my Test Plan folder and enter a command like this:
python TestPlan_LoginTest.py
Instead of going in to the testcase config file and commenting out which browsers I don't wish to use when running my automated tests, I'd like to be able to choose the browser when I invoke the test in the command prompt, i.e. something like this:
python TestPlan_LoginTest.py Firefox
or
python TestPlan_LoginTest.py Edge
If I don't include a browser in the invocation, it defaults to Chrome.
Is this possible with unittest? What changes would I need to make and where?
If you're using a pytest plugin called SeleniumBase, you can set the browser from the command-line. (It defaults to "chrome" if not specified.) Example:
pytest test_demo_site.py --edge
pytest my_first_test.py --firefox
Or if you prefer to use your own framework, you can find the necessary code for setting pytest command-line options here in SeleniumBase: pytest_plugin.py
That link shows you about using pytest_addoption(parser): as well as code such as:
parser.addoption(
"--edge",
action="store_true",
dest="use_edge",
default=False""",
)
which lets you customize command-line options for use in tests.
I am running my tests using - .testcaferc.json file and command that I am using to run is : node node_modules/testcafe/bin/testcafe
I want to pass an additional parameter for running my different tests on different environments. When I tried to add that parameter in command: node node_modules/testcafe/bin/testcafe production then I am not able to it as it consider them as tests.
Please let me know how can I handle this.
You can use the environment variables for this case.
Set the environment variable
// Enviroment variable set is platform specific
// See https://devexpress.github.io/testcafe/documentation/recipes/configuration/access-environment-variables-in-tests.html#set-environment-variables
export production=true
testcafe chrome test.js
and use it in a test
fixture ('Fixture');
test('test', async t => {
console.log(process.env.production);
});
Is there a way to execute TestNG.xml in dry run mode so that I can figure out what methods gets qualified for the test run. I am using Eclipse and intend to run the tests via testng.xml. How to configure Run Configurations for this.
Newbie to Selenium-TestNG and Eclipse
I tried to provide -Dtestng.mode.dryrun=true in Run Configurations -> Arguments tab under both Program argument and VM arguments
The run configurations had no effect on the execution. The tests were executed in normal fashion. I expected the configurations would just list test methods in the console
You are going to see all tests with no failures. That what you expect when you run testNg with the argument.
To check the dryrun argument works, make your test to fail. Then run your test with "-Dtestng.mode.dryrun=true". Add the argument in "VM arguments"
Also, check your version of testNG is 6.14 or higher
I'm using jenkins and selenium.
I need to send the testing url to selenium server from jenkins.
Under General Tab
Jenkins String parameter: Name = APP, Default Value = http://localhost/basecode/
Under Post-build Actions
Trigger parameterized build on other projects -> Predefined parameters -> Parameters -> SEL_APP=$APP
Above mentioned SEL_APP value needs to be written in the selenium bat file.
Suggestions are most welcome :-)
If you are using maven then you can pass the parameters through maven command.
mvn clean test -Duser=value1 -Dpass=value2
If you are building the Jenkins job with parameters then you can use jenkins parameters in maven command as
clean test -Duser=$jenkinsparam1 -Dpass=$jenkinsparam1
jenkinsparam1 - Jenkins parameter while building a job.
In the code you can use them as
String s1 = System.getProperty("user");
String s2 = System.getProperty("pass");
Use File Operations Plugin to create a bat file.
Add File Operations build step and with in it add File Create Operation. It creates the bat file with the contents provided in text area.
Use %parameter_name% in your bat file, it would directly pick it from Jenkins.
Is there a way to invoke the Selenium IDE From the Linux command line. I would really like to have a command that when run would cause the Selenium IDE to run the current test. (This way I can hook it into gvim's save hook and never take my hands off the keyboard)
EDIT:
I know how to get PHP unit or the like to run selenium. That works great for running tests, the problem is that right now what I am trying to do is use the selenium IDE as a macro. IE to load my app and navigate me to the part I am working on. That does not work well from phpunit because it reloads the page as soon as the test ends.
You cannot run IDE directly from the command line, however you can use Selenium RC to run scripts recorded in Selenese (i.e. recorded by Selenium IDE) without converting them to a different language.
Run Selenese Directly Within the
Server Using -htmlSuite
You can run Selenese html files
directly within the Selenium Server by
passing the html file to the server’s
command line. For instance:
java -jar selenium-server.jar
-htmlSuite "*firefox" "http://www.google.com"
"c:\absolute\path\to\my\HTMLSuite.html"
"c:\absolute\path\to\my\results.html"
This will automatically launch your
HTML suite, run all the tests and save
a nice HTML report with the results.
Note
When using this option, the server
will start the tests and wait for a
specified number of seconds for the
test to complete; if the test doesn’t
complete within that amount of time,
the command will exit with a non-zero
exit code and no results file will be
generated.
This command line is very long so be
careful when you type it. Note this
requires you to pass in an HTML
Selenese suite, not a single test.
Also be aware the -htmlSuite option is
incompatible with -interactive You
cannot run both at the same time.
The above is taken from http://seleniumhq.org/docs/05_selenium_rc.html
What I found you can do is use the unix command line tool "xdotool" to generate the click event on the button, which will run the script. Exactly what I wanted to do. This is the command line I run. (Its in a shell script)
xdotool search --name "Selenium IDE" mousemove --window %1 153 65 click 1
For the Selenium IDE I don't know a solution. Selenium IDE is the user frontend for the Selenium Core.
But to run a set of working test scripts, you can use Selenium Remote Control (RC). This is an API for the Selenium Core. It is available for Java, Ruby, Python, .Net/C#, Perl, PHP.
You can record a macro with Selenium IDE. Then you can export the macro to each of the supported programming languages. I used it successfully for Java:
Exported the script to Java
Wrapped the Java code with a JUnit test case
Used a simple main method in a Java class to parse some command line arguments and to call the JUnit runner
Started the Selenium Server from the command line
Called the Java class from the command line
It should work in an analogous way for other programming languages. Compile Java or C# to an executable or directly call the Python/Ruby/Perl script.
The wrapping as a JUnit test case is optional. The advantage is that you can execute the Selenium macro also with any other JUnit runner, e.g. in Eclipse or with the JUnit Ant task.