I'm working on Selenium and I currently have a hub connected to two vms running linux with all the browsers.
I was able to launch the browsers . However, event hough I have two vms all my tests run on a single browser on a single vm. Selenium does not launch more than one browser in a vm. I have set maximum instance to 5 and it reflects in my gris console. I have testsuite which needs to run on linux and windows vm and it has to run simultaneously . Im using the WebDriver to call my grid like this .
capabilities = new DesiredCapabilities();
capabilities.setBrowserName("firefox");
driver = new RemoteWebDriver(new URL("http://XXX.XXX.XXX.:4444/wd/hub"), capabilities);
And this is how I create my test Suite:
testNames.add(SupportPortalTestSuite.class.getName());
JUnitCore.main(testNames.toArray(new String[testNames.size()]));
Also when I register my nodes I get:
11:28:47.403 INFO - using the json request : {"class":"org.openqa.grid.common.RegistrationRequest","capabilities":[{"platform":"LINUX","seleniumProtocol":"Selenium","browserName":"*firefox","maxInstances":5},{"platform":"LINUX","seleniumProtocol":"Selenium","browserName":"*googlechrome","maxInstances":5},{"platform":"LINUX","seleniumProtocol":"Selenium","browserName":"*iexplore","maxInstances":1},{"platform":"LINUX","seleniumProtocol":"WebDriver","browserName":"firefox","maxInstances":5},{"platform":"LINUX","seleniumProtocol":"WebDriver","browserName":"chrome","maxInstances":5},{"platform":"WINDOWS","seleniumProtocol":"WebDriver","browserName":"internet explorer","maxInstances":1}],"configuration":{"port":5555,"register":true,"host":"10.235.132.161","proxy":"org.openqa.grid.selenium.proxy.DefaultRemoteProxy","maxSession":5,"hubHost":"10.235.1.50","role":"node","registerCycle":5000,"hub":"http://10.235.1.50:4444/grid/register","hubPort":4444,"url":"http://10.235.132.161:5555","remoteHost":"http://10.235.132.161:5555"}}
11:28:47.407 INFO - starting auto register thread. Will try to register every 5000 ms.
I need to run the tests on all available browsers on the vms simultaneously .
Selenium Grid give you the ability to run tests in parallel but doesn't handle it automatically. This is typically done with a test runner that handles it for you. Some frameworks like TestNG have this built-in but would likely need some customizing depending on your code.
Though it is preferred to use some frameworks such as testNG, you can run them with a plain java Threaded way too.
Related
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 :)
Could someone please help me understand the difference between the remote control server in Selenium Grid 1 and the remote control server in Selenium Grid 2. From what I've read, one of the main differences between the versions is that version 2 of Selenium Grid was merged with Selenium Remote Control. Is this the same remote control as Selenium 1, that was responsible for proxy injection? as I thought this had been deprecated.
This is as of Selenium 3.4.0
We now have two separate artifacts.
For example if you head down to the Selenium downloads URL you would notice the following two artifacts
selenium-server-standalone-3.4.0.jar - This is the Grid (or Grid2 as you call it) as we know. This standalone jar can work in 3 modes viz.,
Hub - It acts as the hub standing in between your test and the actual node that gets the work done. Kind of like a postman/mailman and a match maker.
Node - This is the actual place where all the action happens. When running in this mode, it is responsible for getting automation requests from the tests routed via the Hub and opens up browsers, performs UI actions etc.,
Standalone - This is pretty much the same as Node but just that it doesn't require a Hub to route the automation test traffic to it. Tests can directly point at the Standalone and then start running. I believe this is perhaps the kind of setup that third party execution environment providers such as SauceLabs maybe using. (This is just a hunch, I don't know for sure).
selenium-html-runner-3.4.0.jar - This is where all the legacy stuff (or Selenium RC as you call it) has moved into. So if you had a html test suite that you created by recording a UI flow using Selenium IDE and wanted to run them from a command line (Note that you can always execute a html test suite from within the Selenium IDE and don't need anything extra), you would use this.
There is nothing called as Selenium Grid1 anymore. There's only Selenium Grid2 (which is the re-engineered version of Grid1).
The Selenium RC support exists only as a stop gap solution with no maintenance as part of selenium-html-runner-3.4.0.jar. This has been officially deprecated and there's no support for issues that surface on this.
The expectation is that if one were to be using Selenium and building new tests, then one should be directly using only the WebDriver APIs (which is Selenium2) and not fall back to using DefaultSelenium APIs (which is Selenium1)
Hope that helps!
I'd like to setup a Selenium server so that clients can record tests locally, recorded tests can be replayed and tested on an Ubuntu server with Firefox + Chrome.
Unfortunately the Selenium site is so confusing and mentions so many different projects (Selenium 1, Selenium 2, Selenium RC, Selenium Grid) that I'm not sure where to start.
How do I go about setting up Selenium Server on an Ubuntu box?
Unfortunately the Selenium site is so
confusing and mentions so many
different projects (Selenium 1,
Selenium 2, Selenium RC, Selenium
Grid) that I'm not sure where to
start.
Selenium has multiple versions
IDE - mainly to record the test and play it back. It is mainly a Firefox Addon. This can be used for very basic testing. You can also export the recorded test to selenium RC. All these mentioned in seleniumhq.org->documentation section: http://docs.seleniumhq.org/docs/
RC - Like any other automation tool, you can write your own code to run the test rather than just recording and playing it back. This has far better capabilities than IDE including support for several languages (Java, Javascript, Ruby, PHP, Python, Perl and C#) and support for almost every browser out there in various platform.
Grid - This helps in running multiple tests in parallel.
To record and run the test in Firefox (NOT CHROME) its very easy. This doesn't require a selenium server running.
record the whole test
save it in a file
Copy the file to Ubuntu machine
Open the same test using IDE in Ubuntu machine and run it again in firefox
If you want to run on chrome, then you need to go to the next level of using selenium RC. And this requires the selenium server running.
How do I go about setting up Selenium
Server on an Ubuntu box
Download selenium-server jar from here. Copy this to any directory in your ubuntu server
Open a terminal and navigate to the folder which has the selenium server jar.
Enter java -jar selenium-server-jarfilename.jar
Selenium server will start on port 4444 by default and keep listening to the tests.
The site is confusing in terms of the versioning and names. Selenium is the name of the entire project which started off as Selenium RC (remote control). Selenium RC is the old version of the API which is also sometimes called Selenium 1. Selenium 2 is the newest version and the latest release was last week being Selenium RC2 (release candidate). This uses a different API to Selenium RC. The new API is known as WebDriver. The new API still allows you to access the older Selenium RC but only for backwards compatibility.
Since you're starting now, there is no reason for you to use the Selenium RC API. You should instead use the advanced user interactions which are part of WebDriver. Setting up WebDriver is pretty easy and there is a decent guide on it here. You should note that the API used there is the older standard (2.0 beta) which uses WebElements. The new API (advanced user interactions) decouples actions from the elements they are performed on a lot more. I would recommend you use the latest versions of the API which is being actively supported rather than older deprecated versions.
Since you want to do this all locally, the second link I gave you should be enough to get you up and running. Assuming you're going to be using the Java bindings it is as simple as:
public class Selenium2Example {
public static void main(String[] args) {
// Create a new instance of the Firefox driver
// Notice that the remainder of the code relies on the interface,
// not the implementation.
WebDriver driver = new FirefoxDriver();
// And now use this to visit Google
driver.get("http://www.google.com");
Actions builder = new Actions( driver );
builder.sendKeys( driver.findElement( By.name("q") ), "Cheese!" );
Action action = builder.build();
action.perform();
//Close the browser
driver.quit();
}
}
This is the example code edited to use advanced user interactions.
You must have two things to write and execute selenium tests.
1) Selenium Server is also known as Selenium RC (Remote Control). You can go to this link and download Selenium Server.
You can start selenium server with command java -jar ur_selenium_server.jar
2) Client Driver: Using client-driver you can code selenium tests. It consists of combination of selenium commands that perform certain actions on the UI. For e.g. click, select etc.
Selenium supports many different language bindings for client-driver. Download appropriate client-driver for your preferred language from above download page.
You can refer client driver apis and code your tests.
Hope this helps
Right now I am using Hudson CI to launch browser in xvnc and run my tests through Webdriver (pre 2.0)
Should I use Selenium remote webdriver instead? is that more efficient than hudson ci?
I want to run my tests on Amazon....are there any selenium remote webdriver server or Selenium Grid plugin that can already integrate with Amazon? Should I pursue Grid or remotedriver server?
My ultimate goal is to be able to launch multiple tests parallel on Selenium on Amazon and be able to quickly scale up and down.
Right now I pay $100/month for server that has hudson CI on it....but I never end up using the whole capacity....
Grid or the Remote Server does not replace a CI tool like Hudson. They will not schedule jobs, parallelize your tests, report results (with history) or send email/IM notifications when builds fail.
So you would still have Hudson (or similar) for all those things, possibly using Grid or the Remote Server to decouple the machine(s) running the browser(s) from the one running the tests.
Selenium Grid will allow you launch multiple tests in parallel. And with the right configuration you can even run the tests of different browsers in parallel.
Selenium grid is still using selenium 1.x remote control drivers. So if you already have your tests written in webdriver code, then you might not be able to use it with current Selenium grid. There is a new version of selenium grid - Grid 2.0 that will be out soon. That will be support webdriver as well.
I have selenium 2 web driver scripts up and running and I now want to tie those into my continuous integration process. I have 2 physical machines set aside for selenium to run on and a VM machine for our build machine that also runs Hudson.
How do I have Hudson start selenium scripts on a remote machine?
This is an answer for the c# bindings, I guess you're using the java bindings but it should almost be the same.
First you should start the selenium server on the remote selenium server using the selenium-server-standalone-2.0b3.jar found here: http://code.google.com/p/selenium/downloads/list
You start it using:
java -jar selenium-server-standalone-2.0b3.jar
In your test you use the RemoteWebDriver like this:
var desiredCapabilities = DesiredCapabilities.Firefox();
var selenium = new RemoteWebDriver(new Uri("http://seleniumserver1:4444/wd/hub"), desiredCapabilities);
That should make sure your testscripts send all webdriver commands to the remote server.
Grid 2.0 should be in selenium 2.0 beta 4 making it easier to use both selenium servers. ( I guess now you could switch server urls by yourself )