selenium RC and Flow control - selenium

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.

Related

Selenium IDE 2.9.1 - Can I run tests from a command line?

I would like to add a command line start for Selenium IDE test scripts to our build process so some of the tests are run immediately after the latest code is built for our products.
I have been looking and everything I find seems to relate to older versions. I can't find anything that looks up to date.
Can I run tests that I have recorded in Selenium IDE 2.9.1 from the command line - and by extension, a batch file to run multiple tests.
Is there documentation that I did not find? Can someone direct me to it?
Thanks.
You didnt specify an operating system but i think you mean windows, and yes, you can run selenium IDE test suites from powershell or CMD on windows.
You will need Java installed on your machine, and also the Selenium Server.jar file which should have come with your installation of Selenium, if not you can download from the Selenium Site.
Then, create a test suite in IDE and save it somewhere on your machine. (you can only run test suites, not testcases - i wont explain the difference between the two here)
Then in powershell or CMD you run this command, you will need to change it depending on your installation directories.
C:\Java\JDK1.8.0_66-X64\bin\java -jar C:\Selenium\Selenium-Server\selenium-server.jar -htmlSuite *firefox "baseurl" "C:\temp\testsuitename" "C:\TEMP\logs" -timeout 0060 -trustAllSSLCertificates
I will break this down for you -
C:\JDK1.8.0_66-X64\bin\java -jar - this is your Java installation directory (mine is Java JDK 1.8)
C:\Selenium\Selenium-Server\selenium-server.jar - This is the location of your Selenium .jar file.
-htmlSuite *firefox These are .jar file options to tell the jar file you are running it from a command line and to use firefox
"baseurl" In here, you should enter your base url which would normally be at the top of the IDE gui. eg, www.google.com
"C:\temp\testsuitename" The full path where you have saved your test suite
"C:\TEMP\logs" Running from command line produces a html log, advise where you want this placed
-timeout 0060 -trustAllSSLCertificates There are additional options, of which there are many. In this case the total time the command will run before it times out is 60 seconds, and it will ignore all those untrusted certificate errors that firefox often gets (where you need to keep adding exceptions etc).
Hope i could help!

Selenium Test Results are empty [duplicate]

I'm trying to run an HTML testSuite with Selenium RC. The browser starts, the first test runs, and it stops. It doesn't continue to the second test case. I named both the test cases with .html extension. I am using Firefox.
If I run them manually, individually from the selenium RC test runner window they run ok. What am I missing, this seems pretty simple but yet I'm not able to get this working.
I am using Selenium RC 1.0.3
java -jar selenium-server.jar
-firefoxProfileTemplate"C:\Users\sicky\AppData\Roaming\Mozilla\Firefox\Profiles\zvt0jj7c.default"
-htmlsuite "*firefox" "https://4.17.8.9/" "C:\Users\sicky\Documents\selenium scripts\suite.html"
"C:\Users\sicky\Documents\selenium scripts\results.html"
What am I missing?
ok I figured this out. What I was doing was , I was converting the existing scripts into HTML. Apparently it doesnt work that way. It looks like I have to name them with html extension when I make those test cases itself, then the whole suite will run –
Actually I had the same behaviour and my test scripts were in fact created in Selenium IDE and had the proper .html extension.
However! The test suite itself didn't have the .html extension. I just added it and it started working properly.

selenium RC doesnt run the whole test suite

I'm trying to run an HTML testSuite with Selenium RC. The browser starts, the first test runs, and it stops. It doesn't continue to the second test case. I named both the test cases with .html extension. I am using Firefox.
If I run them manually, individually from the selenium RC test runner window they run ok. What am I missing, this seems pretty simple but yet I'm not able to get this working.
I am using Selenium RC 1.0.3
java -jar selenium-server.jar
-firefoxProfileTemplate"C:\Users\sicky\AppData\Roaming\Mozilla\Firefox\Profiles\zvt0jj7c.default"
-htmlsuite "*firefox" "https://4.17.8.9/" "C:\Users\sicky\Documents\selenium scripts\suite.html"
"C:\Users\sicky\Documents\selenium scripts\results.html"
What am I missing?
ok I figured this out. What I was doing was , I was converting the existing scripts into HTML. Apparently it doesnt work that way. It looks like I have to name them with html extension when I make those test cases itself, then the whole suite will run –
Actually I had the same behaviour and my test scripts were in fact created in Selenium IDE and had the proper .html extension.
However! The test suite itself didn't have the .html extension. I just added it and it started working properly.

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