SELENIUM-GRID2 Configuration Remotewebdriver

Source: Internet
Author: User
Tags selenium grid

Why use Selenium Grid?
    • Distributed run-scale test
    • can easily run different browser on different OS through a central point
    • Minimize maintenance time on the grid and take full advantage of virtual appliances
Selenium Grid Deployment and startup

Hub: The master node, connecting to invoke node.
Node: Responsible for executing tests, invoking the browser.

The following is an example of the Selenium-server-standalone-2.27.0.jar version:
Use such 3 machines:

    • 10.81.14.170
    • 10.81.14.180
    • 10.81.14.190

Launch Hub (10.81.14.180):

java  -jar  

Open in Browser: Http://10.81.14.180:4444/grid/console can view the hub status. That is, the grid default startup port is 4444, if you want to switch to a different port, add -port parameters. For example, to switch to 8888:

java  -jar  selenium-server-standalone-2.27.0.jar -role hub  -port 8888

Start Node (10.81.14.170):

java -jar selenium-server-standalone-2.27.0.jar -role node -hub http://10.81.14.180:8888/grid/register

Similarly, you can use the -port switch node port, which is the default port of 5555.
Node nodes here can also exist as a standalone remote node and support Rc,webdriver at the same time. Browser input Http://10.81.14.180:8877/wd/hub can see the session information.

Then, the same starts the node nodes on the 10.81.14.180, 10.81.14.190.

Open the browser http://10.81.14.180:8888/grid/console, you can see the following interface:

At this point, Selenium Grid2 has been configured successfully.

Running tests using a grid

The Selenium Grid2 is backwards compatible and supports Rc,webdriver. If you use RC, which is SELENIUM1, use the following method:

Selenium selenium = new DefaultSelenium(“10.81.14.180”, 8888, “*firefox”, “http://www.baidu.com”);

Using Webdriver, use the following methods:

DesiredCapabilities capability = DesiredCapabilities.firefox();WebDriver driver = new RemoteWebDriver(new URL("http://10.81.14.180:8888/wd/hub"), capability);

It can be seen that all requests are sent to the hub and then executed by the hub assigned to the matching nodes.
So, how is the hub allocated? Look down.

Node configuration

By default, node launches 11 instances of the browser: 5 firefox,5 Chrome, 1 Internet Explorer. From the grid console interface, why are there 22 instances of each machine? This is the case, node in order to support both RC and webdriver two kinds of protocol, so it is 2*11. Put the mouse on each browser icon, you can see the configuration of the difference.
Similar content:

{      "browserName": "*firefox",      "maxInstances": 5,      "seleniumProtocol": "Selenium"    }

Or

 {      "browserName": "firefox",      "maxInstances": 5,      "seleniumProtocol": "WebDriver"    }

Among them, Seleniumprotocol is the different protocol of the definition.

How do I modify the driver configuration? Can be manipulated from the startup parameters.

-browser browserName=firefox,version=3.6,maxInstances=5,platform=LINUX

What is node's default boot configuration?
Because if you configure this many things from the startup parameters, it is hard to write. Therefore, the official is very humanized to provide a JSON file to configure. This means that the default startup configuration is as follows:
Http://code.google.com/p/selenium/source/browse/trunk/java/server/src/org/openqa/grid/common/defaults/DefaultNode.json

Http://code.google.com/p/selenium/source/browse/trunk/java/server/src/org/openqa/grid/common/defaults/DefaultHub.json

If you want to customize the configuration, directly to the JSON file modification, start, specify the configuration file.

Just like that, all right? From the blog http://www.shenyanchao.cn/blog/2012/10/12/selenium-multiple-browser-support/know that the browser start is to develop some driver location, Otherwise, node does not know how to launch the browser instance. It is therefore necessary to specify:

java -jar selenium-server-standalone-2.27.0.jar -port 8877 -role node -hub http://10.81.14.180:8888/grid/register  -nodeConfig nodeconfig.json -Dwebdriver.chrome.driver="E:/selenium/chromedriver.exe" -Dwebdriver.ie.driver="E:/selenium/IEDriverServer.exe"

Reference Documentation:
Http://code.google.com/p/selenium/wiki/Grid2

Client Writing test Cases
Package Seleniumdemo; Import Java. Net. Malformedurlexception; Import Java. Net. Url; Import org. Openqa. Selenium. Javascriptexecutor; Import org. Openqa. Selenium. Webdriver; Import org. Openqa. Selenium. remote. Desiredcapabilities; Import org. Openqa. Selenium. remote. Remotewebdriver;p Ublic class EDemo2 {public static void main (string[] args) throws Malformedurlexception, interruptedexception {//Remo Basic use of tewebdriver//First parameter: Represents the address of the server. The second argument: represents the expected execution object, and so can other browsers webdriver driver = new Remotewebdriver (The new URL ("http://127.0.0.1:4444/wd/hub/"), desiredcapabilities .chrome ()) .manage () .maximize ()  driver .get ( "http://www.baidu.com") .sleep (2000)  "alert (' I'm now on the server ')" ; Thread.sleep (2000)  driver .quit () ;}        

Execute Script

In fact, the script is executed on the server side, and the client is used to send commands. During execution, you can see the server-side chrome call, and cmd print out the relevant run information, as follows

SELENIUM-GRID2 Configuration Remotewebdriver

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.