[Selenium] Grid

Source: Internet
Author: User
Tags selenium grid

Selenium Grid supports distributed testing, allowing testers to test in a distributed environment

In general, consider using the selenium Grid when you are facing:

1. Test multiple versions of multiple browsers or individual browsers, or test various browsers on different operating systems

2. Reduce test suite run time

The Selenium Grid contains a hub and at least one Node, both of which can be started by the Selenium-server-standalone.jar file

Deployment of the Selenium Grid

1. Install selenium Grid: Download Selenium-server-standalone.jar file from Selenium official website. The path to the Java executable must be correct so that you can run the file from the command line, and if you run an error, check the system's path variable to see if it is based on the path that includes the Java executable file

2. Start Selenium grid: In general, running the selenium grid requires the hub to be started, because Node calls depend on the hub

1. Grid Hub

1) Default boot Hub

Use the following command to start the hub with the default settings

$java-jar Selenium-server-standalone-2.37.0.jar-role Hub

This command can be called by all supported operating systems. Note that depending on the Selenium-server-standalone version, the version number in the jar file name needs to be changed accordingly. The default port number for Hub startup is 4444, and the user can define its boot port via the-port parameter

The Hub can be checked for success by entering the following address in the browser:

Http://localhost:4444/grid/console

Click View Config to view the configuration information for the selenium Grid, by default, the maximum number of sessions supported by a single hub is 5

2) Configure the Hub port

The Hub default port is 4444, and when the automated test case is connected to the Selenium Grid Hub, the listening port is the TCP/IP port, if another program is already using the port on the machine, or Selenium-server-standalone has been started, The log will indicate that the port is already occupied and cannot start the selenium Grid Hub.

One solution is to close a program that is using port 4444, and solution two is to have the Selenium Grid Hub use a different port. Replace the port used by the Hub with-port at the command line:

$java-jar selenium-server-standalone-2.37.0.jar-role hub-port 8888

This method works even when the existing hub is running on the machine, as long as the ports used by the two hubs are different.

If you want to know which ports are used by all running programs on the machine, you can use the following command:

$netstat-A

3) JASON configuration file

In addition to specifying parameters in the startup command to customize the hub configuration, you can also start the hub with a predefined configuration file. These configuration information can be written in a JASON-formatted configuration file, for example:

{

"Host": null,

"Port": 4444,

"Timeout": 300000,

"Maxsession": 5,

...

}

Then load the JASON configuration file by adding the-hubconfig parameter to the start command

$java-jar Selenium-server-standalone-2.37.0.jar-role Hub-hubconfig

Hub-json-cfg.json

2.Grid Node

1) Start Node by default

by the following command;

$java-jar Selenium-server-standalone-2.37.0.jar-role Node-hub

Htttp://localhost:4444/grid/register

This assumes that the default set of hubs has been started. The default port used by the hub to listen for new requests is 4444, so the URL for locating the hub uses 4444 of this port. Using localhost is assumed that Node and Hub are running on the same machine.

If you are running Node and hub on a different machine, you need to replace the local hostname with the hostname of the machine running the hub. In this case, Node will register all browser information that the native operating system can support to the Hub.

If you replace the parameter-roal node with-role Webdriver, that node is only compatible with Webdriver execution mode. Correspondingly, if replaced with-role RC, it means that node is only compatible with the execution mode of Remote Control

2) Register Mac OS X&opera

2 Ways to register node with the hub, the first one to be added by command line, just add the corresponding parameters:

$java-jar selenium-server-standalone-2.37.0.jar-role node-browser "Seleniumprotocol=webdriver, BrowserName=opera, Version=15,maxinstances=1,platform=mac "-hubhost localhost

You can check if the Hub is registered successfully by entering the following address in your browser:

Http://localhost:4444/grid/console

The second way is to create a JASON-formatted profile and load the JSON configuration file when you start Node

{

"Class": "Org.openqa.grid.common.RegistrationRequest",

"Capabilities": [

{

"Seleniumprotocol": "Webdriver",

"Browsername": "Opera",

...

}

],

"Configuration": {

"Maxsession": 5,

...

}

}

Then load the JASON configuration file by adding the-nodeconfig parameter to the start command

$java-jar Selenium-server-standalone-2.37.0.jar-role Node-nodeconfig

Hub-json-mac-opera.cfg.json

3) Register Linux & Firefox

If there are multiple browser versions in the system, you need to specify the browser's executable path. This example sets the following configuration items:

Execution mode is Webdriver, with the latest version of Firefox's path firefox_binary as an example, Maxinstances is set to 2, indicating the maximum support for execution of 2 browser instances

$java-jar selenium-server-standalone-2.37.0.jar-role node-browser "Seleniumprotocol=webdriver, BrowserName=firefox , Version=25,firefox_binary=/home/selenium2/firefox25/firefox maxinstances=2,platform=linux "-hubHost 192.168.0.104

4) Register WinDOS & Internet Explorer

c:\selenium2> Java-jar selenium-server-standalone-2.37.0.jar-role node-browser "SeleniumProtocol=Selenium, Browsername=iexplore,version=10,maxinstances=4,platform=windows "-hubhost 192.168.0.104

5)

[Selenium] Grid

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.