Using grids in the Selenium test framework

Source: Internet
Author: User
Tags selenium grid

Previous Test framework: http://www.cnblogs.com/tobecrazy/p/4553444.html

With Jenkins sustainable integration: http://www.cnblogs.com/tobecrazy/p/4529399.html

Use log4j 2:http://www.cnblogs.com/tobecrazy/p/4557592.html in the test framework

To start with the grid, selenium grid is a framework for executing test cases with different platforms (Windows, Linux, Android), and

These platforms are controlled by a central point, called the Hub, and the different platforms are called node

The structure is as follows:

Why Use Selenium grid:

If your program needs to be tested on a different operating system without a browser, and if more of the case needs to be done remotely, a better solution is to use Grid.selenium-grid is a tool designed to help us with distributed testing, and its entire structure consists of a hub node and several broker nodes. The hub is used to manage registration and status information for each agent node, and to accept request calls from remote client code and then forward the requested command to the broker node for execution.

How to use:

First Enable hub:

In a machine download: Selenium standalone 4.6:HTTP://PAN.BAIDU.COM/S/1QWE7SD2

Then create the Hub.bat

The contents are:

1 Java-jar selenium-server-standalone-2.46.  

Its default listener port 4444, default IP localhost if you want to modify, only need to add-port parameters and-hubhost

Java-jar selenium-server-standalone-2.46.  0.jar-role hub  1235-hubhost 192.168.2.45  

Next, add node to machine B and create Node.bat, which uses the default Hubhost Ip and port

1 Java-jar selenium-server-standalone-2.46.  0.jar-role Node-hub http://localhost:4444/grid/register   

In order to use chrome and IE driver, we need to set this

1 java-dwebdriver.ie.driver="C:\Users\workspace\Demo\webDriver\IEDriverServer.exe"- dwebdriver.chrome.driver="C:\Users\workspace\Demo\webDriver\chromedriver.exe"-jar selenium-server-standalone-2.46.  0.jar-role Node-hub http://localhost:4444/grid/register         

Start each of these two bat

If you are using remote Driver, you need to set such parameters

Desiredcapabilities capability = Desiredcapabilities.firefox ();        New Remotewebdriver (new URL ("Http://localhost:4444/wd/hub"), capability);        Capability.setbrowsername ("Firefox" ); Capability.setversion ("3.6");    

So we simply create a bean

1/**2*3*/4PackageCom.dbyl.libarary.utils;56/**7* For remote browser bean8*@authorYoung9*10*/11PublicClassRemotebrowserbean {12PrivateString Browsername;13PrivateString version;14PrivateString[] platform;15PrivateString Huburl;16PublicString Getbrowsername () {17ReturnBrowsername;18}1920PublicRemotebrowserbean ()21st{22This.browsername= "Firefox";23This.version= "38";24this.platform=New string[]{"VISTA", "Windows 7"};25This.huburl= "Http://localhost:4444/wd/hub";2627}2829PublicRemotebrowserbean (String browser)30{31This.browsername=Browser32this.version= "42";33this.platform=New string[]{"VISTA", "Windows 7"};34This.huburl= "Http://localhost:4444/wd/hub";3536}3738PublicvoidSetbrowsername (String browsername) {39This.browsername =Browsername;40}41PublicString GetVersion () {42ReturnVersion43}44PublicvoidSetversion (String version) {45This.version =Version46}474849PublicString[] GetPlatform () {50ReturnPlatform51}5253PublicvoidSetplatform (string[] platform) {54This.platform =Platform55 }56 57 public String Gethuburl () { 58 return Huburl;59 }60 public void Sethuburl (String huburl) {61 this.huburl = Huburl; }63 64 65}                 

and create Getremotedriver in Driverfactory.

1/**2* This method would create Remotewebdriver3*@authorYoung4*@paramRemotebrowserbean5*@returnWebdriver6*/7PublicStaticWebdriver Getremotedriver (Remotebrowserbean remotebrowserbean) {8 Desiredcapabilities capability =Null;9if (Remotebrowserbean.getbrowsername (). Contains ("Firefox")) {Ten capability =Desiredcapabilities.firefox ();11}Elseif (Remotebrowserbean.getbrowsername (). Contains ("Chrome")) {Capability =Desiredcapabilities.chrome ();13}14Webdriver Driver =Null;16Try{Driver =NewRemotewebdriver (18NewURL (Remotebrowserbean.gethuburl ()), capability);19}Catch(Malformedurlexception e) {20  E.printstacktrace ();  }22 23  Capability.setversion ( Remotebrowserbean.getversion ()); 24 capability.setcapability (Remotebrowserbean.getplatform () [0 ],25 remotebrowserbean.getplatform () [1]); 26  Driver.manage (). window (). Maximize (); 27 return Driver;                 

Then you can use it in case

1 @BeforeClass (alwaysrun=true)2     void beforetest () {4 driver = Driverfactory.getremotedriver (new Remotebrowserbean ("Chrome"));  5}         

Using grids in the Selenium test framework

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.