Code to Run Multiple Selenium Webdriver JUnit Class In a Batch File - selenium

I have multiple selenium test classes. They are independent of each other.
Can anyone please tell me the code to put in a batch file to run multiple test class by simply clicking on the batch file?
Consider my java test classes are located in my local folder: "C:\WebDriver Effort\inspection\src\test\java\com".

Writing batch file is not big deal. First try to execute your testcases from command prompt.
If your test cases have main class you can execute like this.
cd C:\WebDriver_Effort\inspection\src\test\java\com\
javac Test1.java //compile testcase
java Test1 //running testcase
Make sure that selenium.jar is in your classpath otherwise mention the that while compiling.
javac -cp "Selenium-standaloneserver.jar" Test1.java //compile testcase
java -cp "Selenium-standaloneserver.jar" Test1 //running testcase
If you've written test cases in JUnit format follow the steps mentioned in this link

Related

How to run parallel test suites in TestNG

I am try to run parallel test suites using below command.
java -cp testng-6.3.1.jar;test.jar;selenium-server-standalone-2.18.0.jar org.testng.TestNG -suitethreadpoolsize 2 testng-vm1.xml testng-vm2.xml
When i execute above command, the last testng xml file only (i.e testng-vm2.xml) is running. But i want to run both xml files parallel .
As i know that the above command is getting from http://testng.org/doc/documentation-main.html#parallel-tests
Please let me know is it possible to run parallel suites through TestNG?
I think it's a better solution by creating a Maven Project and configuring it to run your tests in parallel.
More details:
Starting with Maven
http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html
TestNG (and its parallel config)
http://maven.apache.org/plugins/maven-surefire-plugin/examples/testng.html

selenium RC and Flow control

Currently I am working on selenium IDE, now I need to switch to selenium RC. I have downloaded selenium server.But I really don't know how to proceed further. Even I am not able to start server from command prompt. I have used C:\Selenium RC\selenium-server\jave -jar selenium-server.jar, but it struck in between and not proceeding further..
I am looking for language java or PHP.
Let me know how should I move further for successful execution of scripts by using selenium RC
First of all: save a test suite in Selenium IDE (File > Save Test Suite). You should generate test suite - it will contain information about test cases (which, of course, should also be saved (File > Save Test Case)).
Then you are ready for testing with Selenium RC.
Try it with below command:
java -jar path/to/selenium-server-standalone.jar -htmlsuite "*firefox" "http://google.com" "path/to/your/testsuite1" "path/to/result.html"
result.html - this file will be generated during/after execution.
Be sure that name of browser, URL and paths to test suite and result file are in the quotation marks.
I am using Selenium with PHPUnit. I have got class called, lets say, somethingTest (test classes must have 'Test' at the end of their names) and extended PHPUnit_Extensions_SeleniumTestCase. This class contains several test cases as methods (e.g. function testSomeMethod1() - 'test' at the beginning).
And I run it by command:
phpunit somethingTest.php
As to the second thing:
Unknown command: gotoIf
You should load gotoif extension by adding to the execution command something like: -userExtensions path/to/extension-file
This indicates a JavaScript file that will be loaded into Selenium.
If you choose Java to write code, a better approach would be using an IDE like Eclipse. Once you link the JARs and import them in your Java classes you can write your code quickly and efficiently. On top of that, Ecplise has lot of plugins for testing software like Junit, TestNG's to help you create better test suites. Not to mention a Java IDE is always helpful in debugging test code. Here is a tutorial on how to setup Eclipse with Selenium: http://selftechy.com/2011/05/31/setting-up-selenium-with-eclipse
Hope it helps.

Selenium 2 web driver from the command line

I have done this before but seem to be having a brain freeze and google is not helping
I have selenium 2 web driver in Java with eclipse and I simply want to run a script (class, java) from the command line.
Set the classpath, compile the code and then run the code. Something along the lines,
set classpath=c:\path\to\my\project\bin\.;c:\path\where\all\required\jars\*;
javac mywebdriver.java
java mywebdriver
I would suggest you to look at Ant for building your code than something like above..

Way to invoke the Selenium IDE From a unix command line

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.

I want to run Selenium test case file from command line

I made then saved a test case with the Firefox extension "Selenium IDE".
Now I want to use command line to run this exported html file.
I try to follow this how-do-i-launch-the-selenium-ide-from-the-command-line-with-a-specific-test-case but it doesn't work.
Please help me.
You will need the Selenium RC which you can get from:
http://seleniumhq.org/download/
And Java 1.5 or higher (Download Java here)
1) Install Java
2) Unpack Selenium RC.
3) Open a cmd.exe window and go to the directory containing the Selenium Server (selenium-remote-control-1.0.1\selenium-server-1.0.1)
4) Run the command below:
java -jar selenium-server.jar -htmlSuite "*firefox" "http://10.8.100.106" "C:\mytestsuite\mytestsuite.html" "C:\mytestsuite\results.html"
This should run your test suite in Firefox and write the results to the html file. Obviously you will need to change the "http://10.8.100.106" argument to your own server (this might just be localhost / 127.0.0.1)
It is possible to run individual test cases using Selenese Runner. You can specify a single test case file or a test suite as the unit to run.
We should execute the SeleniumRC in using following command;
java -jar filename.jar
ex:
java -jar program1.jar
the program1 consist of the followings are:
program1.class file
Resource library file such as SeleniumRC Server.jar and Selenium Java client.jar file
This method is applicable for SeleniumRC execution. We can directly create the program1.jar file from eclipse using
File->Export.
Here is an article that explains you step-by-step process of how to run Selenium RC application in Java.
Create a Java Selenium RC test script and executing the script
I have needed to do this before, and used the following:
An Ant Build (complex)
Creating a test runner class(a part of junit framework)class.
Most commonly we would run into build path errors while trying to run from cmd.
If you want to run it from command prompt you may consider writing your selenium test in python.
Make sure you have python installed if you are on windows. Mac will have python by default.
Running test from CMD is quite easy.
Follow below steps
1- Go to home directory and Set class path
Home Directory > set classpath=Home Directory\bin; and press enter
Home Directory > set classpath=Home Directory\lib*; and press enter
2-Home-directory > java org,testng.TestNG testng.xml testng2.xml testng2.xml and hit enter
I have documented all steps here. Hope it will help. Cheers
1) Running from CMD
java -cp "C:\ProjectX\Mortgage\bin;C:\Selenium_latest\selenium2.49.1\*;C:\Selenium_latest\selenium-2.49.1\libs\*" org.testng.TestNG C:\ProjectX\Mortgage\testng.xml
Run above command in C:\ProjectX\Mortgage
2) Create batch file name runner.bat
SET projectLocation=C:\ProjectX\Mortgage
CD %projectLocation%
SET classpath=%projectLocation%\bin;C:\Selenium_latest\selenium-2.49.1\*;C:\Selenium_latest\selenium-2.49.1\libs\*
java org.testng.TestNG %projectLocation%\testng.xml
PAUSE
3) Run the batch file by double clicking on it.
To be able to run in Chrome browser, you can use *chrome option instead of *firefox like below
java -jar selenium-server.jar -htmlSuite "*chrome" "http://localhost" "C:\testsuite\testsuite.html" "C:\testsuite\results.html"
Other browsers list include:
*firefox
*mock
*firefoxproxy
*pifirefox
*chrome
*iexploreproxy
*iexplore
*firefox3
*safariproxy
*googlechrome
*konqueror
*firefox2
*safari
*piiexplore
*firefoxchrome
*opera
*iehta
*custom
on session null