Running Selenium IDE tests via Selenium Grid - selenium

I should start off by saying that I am regretfully and painfully a noob. But I'm trying to change that!! I do not know any programming languages, but have managed to "make things happen" by doing enough research to get whatever job I've ever needed done done.
Anyway, I have been creating Selenium tests using the Selenium IDE and I am having a bit of trouble getting these test to run via Selenium Grid.
I have been exporting the tests as JUnit 4 (Webdriver) files. I am running the grid on a Ubuntu headless server, and my remote controls on one Windows 7 machine running IE9 and Firefox, and a Windows Vista machine running IE8 and Chrome.
My goal is to take the tests that I've exported from Selenium IDE as JUnit 4 (Webdriver) files and run them from the grid in parallel on my two Windows machines. I have edited my hosts files on my Windows machines to recognize the Ubuntu server by the name of "seleniumgrid". For example:
On the Ubuntu server terminal 1:
ant launch-hub
Win7 terminal1:
ant -Dport=5555 -Denvironment="IE9 on Windows" -Dhost=Win7 -DhubURL=http://seleniumgrid:4444 launch-remote-control
Win7 terminal2:
ant -Dport=5555 -Denvironment="Firefox on Windows" -Dhost=Win7 -DhubURL=http://seleniumgrid:4444 launch-remote-control
Vista termina1:
ant -Dport=5555 -Denvironment="IE8 on Windows" -Dhost=WinVista -DhubURL=http://seleniumgrid:4444 launch-remote-control
Vista terminal2:
ant -Dport=5555 -Denvironment="Chrome on Windows" -Dhost=WinVista -DhubURL=http://seleniumgrid:4444 launch-remote-control
Now, from here, I'm trying to launch the JUnit4 (webdriver) file that I have exported from Selenium IDE to run this configuration. The name of the file is titled : Registration.java.
What do I have to do now to run the Registration.jar file? I can't seem to find any documentation that answers this question, which leads me to believe that I have a fundamental misunderstanding of how this all works...
Pardon if this question has been answered before. I have poor terminology when it comes to this stuff.
HUGE thanks for taking the time to read this, and even more for an answer if there is one.
-brandon

There is no need to launch hub and nodes via ant. You can run them from cmd:
java -jar selenium-server-standalone-2.21.0.jar -role hub -- will run hub
java -jar selenium-server-standalone-2.21.0.jar -role node -hub http://seleniumgrid:4444/grid/register -- will run node
Default port for node is 5555, so for the second terminal you should specify port that differs from default one, e.g. 5556:
java -jar selenium-server-standalone-2.21.0.jar -role node -port 5556 -hub http://seleniumgrid:4444/grid/register
Also you should specify browser parameters for each node, e.g.:
-browser browserName=firefox,maxInstances=5,platform=WINDOWS
In your JUnit tests you should use RemoteWebDriver with DesiredCapabilities:
DesiredCapabilities capability = DesiredCapabilities.firefox();
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capability);
For parallel execution you should edit your tests additionally (sorry, don't work with jUnit, so can't help here much except of link that you can find below.)
Include JUnit class files, your class files, including your JUnit test classes, libraries your class files depend on in your classpath on Linux machine:
export CLASSPATH=$JUNIT_HOME/junit.jar:/myproject/classes:/myproject/lib/something.jar
Invoke the Junit command on Linux machine:
java org.junit.runner.JUnitCore [test class name]
Or you can use ant instead.
I will recommend to start with hub on Linux and one node with one browser on Windows without any parallelization, so you will be sure that this part works correctly. As a next step run tests for two nodes sequentially and then try to run them in parallel.
For complete tutorials read these materials: How do I run JUnit using Ant, Activating Junit tests from Command Line, Grid2 tutorial, Parallel JUnit 4 and Selenium (three parts)

Related

What is the difference between Selenium Grid and pytest-xdist plugin?

I'm new to parallel testing and I was wondering what the difference is between them.
Apparently, pytest-xdist does not need Selenium Grid to run. It can be used with Selenium alone.
Does anybody have any clue or resource where I can learn the difference?
Thanks and kind regards.
Just in case this is useful for anybody I will write down what I learnt:
pytest-xdist: It is used for running parallel tests in the browsers that are installed in the local machine where tests will be run. This means that each test has a browser configured (e.g.: Firefox, Chrome) such as:
driver = webdriver.Firefox()
or
driver = webdriver.Chrome()
And so each test will run with the driver that was specified in the code. Obviously, the local machine needs the browser drivers to be available in any PATH location, so that tests can be run with them.
Selenium Grid: It allows the execution of tests in different browsers, browser versions and operating systems configurations.
Selenium Grid combined with pytest-xdist allows the execution of parallel tests in different browser-OS environments (configured with capabilities, I think).
An execution command example would be:
pytest -n5 -v -s -m "test or ready" --capability browserName firefox
-n5: (pytest parameter) means that 5 instances of the browser will be launched simultaneously.
test or ready: these are the markers that can be combined to execute tests that have these markers.
browserName firefox: It is a capability that indicates that tests must be run in the specified browser, in this case, Firefox. Some possible values are: chrome, firefox, internet explorer, safari.
Some other capabilities are:
version: The browser version to use.
platform: The platform in which the browser will be executed. Some possible values are: WINDOWS, XP, VISTA, MAC, LINUX, UNIX, ANDROID.
To set up the Selenium Grid environment go along the following steps:
Download selenium-server-standalone-[version].jar from
https://www.selenium.dev/downloads/.
Initiate the HUB:
java -jar selenium-server-standalone-[version].jar -role hub
Initiate as many NODES as you want with:
java -jar selenium-server-standalone-[version].jar -role node -hub http://[URL_HUB]/wd/hub
Configure a RemoteDriver in the tests, for example: driver = webdriver.Remote( desired_capabilities = DesiredCapabilities.CHROME, command_executor = 'http://[URL_HUB]:4444/wd/hub')
I still need to learn how to pass the capabilities args as parameters for the RemoteDriver. In conftest.pyfile I can get the capabilities as a list with config.getoption('--capability')). I still need to figure out how to pass the capabilities I want to the setUp method of all my tests.
If someone knows, I will really appreciate a hint on this.
I hope this helps someone who is as lost as I was at the beginning :)

Safari does not support execution of automation scripts on multiple thread,

Safari does not support execution of automation scripts on multiple threads, Please let me know if there are any alternatives to run selenium tests in parallel. I am running tests in parallel on other browsers like chrome and firefox. The Framework is developed in python using pytest and I am using pytest-xdist to run the scripts in parallel. I also tried pytest-parallel but even this did not help.
Have you searched other related threads?
Example thread from about 8 months ago: here
Paraphrased quote from there:
My expectation is that you're hitting default maxSession limit of
5 browser instances.
You can double check it by opening your Selenium Grid console and
looking into node configuration:
The value can be ramped up by providing the relevant maxSession
parameter to your Selenium Grid Node startup command line like:
java -jar selenium-server-standalone-3.141.59.jar -role node -maxSession 10 -hub http://localhost:4444/grid/register
^^^^^^^^^^^^^^
References

Selenium Grid Support - launch multiple browser windows from same machine

We know that Selenium Grid is supporting parallel testing from different machines.
My Objective is to launch multiple browser windows from same machine and launch tests from same machine parallel. Is it possible with Selenium grid? Could you guide me here, please?
Regards,
-kranti
Yes, you can do it and you can even specify how many windows you want to run at once on given computer. All is done through -browser parameter:
java -jar selenium-server-standalone-2.42.0.jar -role node -browser browserName=firefox,maxInstances=3 -hub http://localhost:4444/grid/register
The above parameter allows the node to run up to 3 instances of firefox browser at once.
Later on, the computer will open 3 different instances of Firefox and run the tests. It worked well in my setup.

Selenium Tests on company Jenkins CI

I have been running Selenium test cases successfully on my local Jenkins. When I run test cases on my local jenkins it opens up chrome/safari or any specified browser on my machine to run.
Now I would like to run the same job on my company Jenkins. But Jenkins is not set up on real machine. So it does not have browser.
How do I run my suite on company Jenkins. I do not want to run headless.
Thanks
You need to run selenium grid on your server machine, where jenkins is installed. After that you need to run a register script to your grid in the machine where you will run browsers.
Before run the browser, get some files ready in a folder. Selenium-server and the browser driver (chromedriver, iedriver whichever you want to use. You don't need firefox)
Script should be like this
cd /path/path/selenium
java -jar selenium-server-standalone-2.46.0.jar -role node -hub http://your.ip.address:4444/grid/register -browser "browserName=firefox,maxInstances=10,platform=MAC" -browser "browserName=chrome,maxInstances=10,platform=MAC" -maxSession 20 -Dwebdriver.chrome.driver=/path/path/selenium/chromedriver
You can edit the script according to your system (MAC/Windows, file paths. file names)
Install the required browsers on Company Jenkins:
It may be the good and effective option, but in case it can't be done refer other options.
Use Headless Browsers Like PhantomJS, etc:
These browsers are good for testing simple features but not meant for advanced feature testing. Headless browsers are not equivalent to real browsers.
Setup a Selenium Grid on Company Jenkins:
You can distribute your tests over different nodes and run tests parallel as well using the Grid. Make your Jenkins machine the Hub and add different Nodes to run your tests, Refer this.
Create Virtual Machines to run your tests:
Virtual machine can help you save the Hardware cost by creating virtual servers for running your tests. This can also be done in conjunction with Selenium Grid. Refer this.
Run your tests on cloud services platform like Saucelabs, BrowserStack, etc:
Best is to use cloud for running your tests. You need not worry about the testing environment like browsers and platforms as they have almost every possible browser + platform combination to run your test.

Selenium testing machine

--- TL;DR
At this point I suggest everyone to tied their Continuous Integration server/service to https://ghostinspector.com/
OLD QUESTION
after three days googling and testing I gave up, and I need help.
My objective is allow my co-workers to record one or more tests with Selenium IDE. Export them, upload them into a server, and get this server running these tests using the webdriver with htmlunit. As we build or fix the app, we will upload the tests to make out test library.
Record a test with Selenium IDE is okay. But getting it running is the problem. The machine we intend to let the tests is an linux amazon server. No front-end stuff, no kde, gtk, so no firefox, chrome, etc... This is why I've specified the htmlunit driver.
So far I wasn't able to get this task running even into my machine - Ubuntu 12.04 x86_64.
I downloaded the selenium-server tarball, and tried running:
java -jar selenium-server.jar -htmlSuite "*webdriver" "our.site.org" "/path/to/testsuite1.html" "/path/to/report1.html"
No success. Even changing the "*webdriver" (using other pops-up a browser screen).
I've tried running the server and the standalone server and connecting via browser.
I've tried PHP bindings by facebook.
I've tried PHPUnit and Testing Selenium classes - along with their respectives exported scripts from Selenium Formatters.
I really do not know where I'm slipping. Can anyone give me a safe direction, tutorial, etc, to follow with?
--- EDIT
Okay, my question may be resumed to:
What si the command line that would allow me to run selenese scripts with selenium-server, using the HtmlUnit driver?
Are you using Continuous Integration?
If so, you should consider getting a plugin to have your CI software run the Selenium tests. Works like a charm for me with Jenkins.
Considering your particular setup, you could both have the amazon linux server run the tests with HTMLUnitDriver, and declare other machines (with a GUI and proper browser) as "nodes" to run your test on other browsers.
Link to a tutorial
Have you read this blog post by David Burns (Automated Tester):
http://www.theautomatedtester.co.uk/tutorials/selenium/selenium_rc_setup.htm
He describes the way to run selenese tests using HTMLSuite.
We are going to use the HTMLSuite commands of the Selenium Remote
Control. This allows you run your Selenese Test Suites as is. The
command should look like java -jar selenium-servre.jar -htmlsuite
. Browser
could be : -*firefox
-*chrome
-*iexplore
-*iehta
-*safari
-*custom /path/to/browser
The path to the test suite and the results file should be a full path.
Here is an example command; java -jar selenium-server.jar -htmlsuite
*iexplore http://www.theautomatedtester.co.uk c:\testsuite\testsuite.html c:\testsuite\results.html
I would point out that htmlunit does not seem to be a supported option so I would expect to use -*custom and provide a path to htmlunit.
This is legacy functionality so there is a chance it doesn't work as expected any more. HTMLSuite expects the tests to be in Selenese (HTML table) format, you mention trying with the PHP binding, I would not expect this to work. If you do want to use some PHP bindings I would suggest using Adam Saunter's fork of the facebook bindings, they are the most up to date and best supported.
https://github.com/Element-34/saunter.php
With Selenium WebDriver you can point to start a HtmlUnit in a already started node
In Java you'll do something like this:
IWebDriver driver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), DesiredCapabilities.HtmlUnit());
To start the node just make sure to set browserName to 'htmlunit'.