Introduction and use of selenium Grid
Author: torrent
Introduction
Selenium grid is an automated testing tool. using existing computer infrastructure, grid can accelerate functional testing of web-app. Using grid, you can run multiple test cases in parallel on multiple machines and heterogeneous environments at the same time.
Selenium grid is based on the Web-app test tool selenium, which allows you to run multiple selenium remote control simultaneously. One better thing is that it displays all these selenium remote control as one so that you do not have to operate on a specific computer during the test.
Because selenium grid is based on selenium RC, it also supports all other RC languages, such as Ruby, Java, Python, C #, PHP ,...
Last, selenium grid is easy to use.
Schematic diagram
Use
Next, we will introduce how to use selenium grid.
Preparation:
1. Download and install ant
Http://apache.mirrormax.net/ant/binaries/apache-ant-1.7.0-bin.zip
Decompress the package to any directory you choose, and then extract the package to the PATH variable added by/Apache-ant-1.7.0/bin.
Finally, verify the installation:
$ Ant-version
Apache ant version 1.7.0 compiled on December 13 2006
2. download and install the JDK 1.6.
Http://www.java.com/en/download/index.jsp
After installation, add the bin directory of Java to the PATH variable, and then verify:
$ Java-version
Java version "1.6.0"
Java (TM) se Runtime Environment (build 1.6.0-b105)
Java hotspot (TM) server VM (build 1.6.0-b105, mixed mode)
3. Download selenium Grid
Http://selenium-grid.seleniumhq.org/download.html
Among them, zipping is a Windows platform, and tar.bz2 is used on other platforms. Decompress the package, and then verify that:
$ CD <your grid directory>
$ Ant sanity-Check
Run:
1. Run selenium Grid
$ Ant launch-Hub
Access the selenium grid console in a browser to verify that selenium grid is successfully started:
Http: // localhost: 4444/console
2. Run selenium remote control
If you specify a different port number on the same machine as the grid, you can run multiple RC nodes on the same machine:
$ Ant-dport = 5556 launch-remote-control
$ Ant-dport = 5557 launch-remote-control
$ Ant-dport = 5558 launch-remote-control
After running, access the grid console to verify that the RC registration is successful:
Localhost |
5555 |
* Firefox |
|
|
|
Localhost |
5556 |
* Firefox |
Localhost |
5557 |
* Firefox |
Localhost |
5558 |
* Firefox |
It is not on the same machine as gird. Assume that the environment is as follows:
We have three machines, one of which is hub.thoughtworks.com, and the other two RC1 and RC2 run two RC respectively. Then we need to use the following command to specify the corresponding parameters when starting RC:
$ Ant-dport = <port>-dhost = -Dport specifies the RC port number and-dhost specifies the Host Name of the RC machine. -Dhuburl specifies the URL of the grid machine.-denvironment indicates the RC browser and operating platform. For details, refer to the grid console description.
The URL can be either host name or TCP/IP.
After running according to the following parameters, the result of successful verification on the grid console is as follows:
Host |
Port |
Environment |
Rc1.seleniumhq.org |
5555 |
Firefox on Windows |
Rc1.seleniumhq.org |
5556 |
Firefox on Windows |
Rc2.seleniumhq.org |
5555 |
Firefox on Mac |
Rc2.seleniumhq.org |
5556 |
Firefox on Mac |
3. Call
The following code is called. To run the code, you need to write the main function or combine it with testng.
// Seleniumhost grid address, seleniumport grid port number, browser, and website tested object. </P> <p> Import static COM. thoughtworks. selenium. grid. tools. threadsafeseleniumsessionstorage. session; <br/> Import static COM. thoughtworks. selenium. grid. tools. threadsafeseleniumsessionstorage. startseleniumsession; <br/> Import static Org. testng. assertjunit. assertequals; <br/> Import static Org. testng. assertjunit. asserttrue; <br/> Import Org. testng. annotations. aftermethod; <br/> Import Org. testng. annotations. beforemethod; <br/> Import Org. testng. annotations. parameters; </P> <p>/** <br/> * base class for all tests in selenium grid Java examples. <br/> */<br/> public class flickrtestbase {</P> <p> Public static final string timeout = "30000 "; </P> <p> protected void startsession () throws exception {<br/> startseleniumsession ("localhost", 4444, "* istme", "http://www.google.cn "); <br/> SESSION (). setTimeout (timeout); <br/>}</P> <p> protected void closesession () throws exception {<br/> closeseleniumsession (); <br/>}</P> <p> protected void runflickrscenario (string searchstring) {<br/> SESSION (). open ("/"); <br/> asserttrue (Session (). getlocation (), Session (). getlocation (). startswith ("http://www.google.cn"); <br/> SESSION (). type ("Q", searchstring); <br/> SESSION (). click ("btng"); <br/> SESSION (). waitforpagetoload (timeout); <br/> asserttrue (Session (). istextpresent (searchstring. split ("") [0]); <br/>}</P> <p> Public static void main (string [] ARGs) throws exception {</P> <p> flickrtestbase GT = new flickrtestbase (); <br/> GT. startsession (); <br/> GT. runflickrscenario ("Selenium"); </P> <p >}</P> <p>
Selenium grid FAQ:
Http://selenium-grid.seleniumhq.org/faq.html