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 more of the case requires a multi-threaded remote execution, A good solution is to use Grid.selenium-grid as a tool for designing distributed testing, which 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. 0

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  */4  Packagecom.dbyl.libarary.utils;5 6 /**7 * For remote browser bean8  * @author Young9  *Ten  */ One  Public classRemotebrowserbean { A     PrivateString Browsername; -     PrivateString version; -     Privatestring[] platform; the     PrivateString Huburl; -      PublicString Getbrowsername () { -         returnBrowsername; -     } +      -      PublicRemotebrowserbean () +     { A          This. browsername= "Firefox"; at          This. version= "38"; -          This. platform=Newstring[]{"VISTA", "Windows 7"}; -          This. huburl= "Http://localhost:4444/wd/hub"; -          -     } -      in      PublicRemotebrowserbean (String browser) -     { to          This. browsername=Browser; +          This. version= "42"; -          This. platform=Newstring[]{"VISTA", "Windows 7"}; the          This. huburl= "Http://localhost:4444/wd/hub"; *          $     }Panax Notoginseng      -      Public voidsetbrowsername (String browsername) { the          This. Browsername =Browsername; +     } A      PublicString getversion () { the         returnversion; +     } -      Public voidsetversion (String version) { $          This. Version =version; $     } -   -      the      Publicstring[] GetPlatform () { -         returnplatform;Wuyi     } the  -      Public voidSetplatform (string[] platform) { Wu          This. Platform =platform; -     } About  $      PublicString Gethuburl () { -         returnHuburl; -     } -      Public voidSethuburl (String huburl) { A          This. Huburl =Huburl; +     } the      -  $}

and create Getremotedriver in Driverfactory.

1 /**2 * This method would create Remotewebdriver3      * @author Young4      * @paramRemotebrowserbean5      * @returnWebdriver6      */7      Public Staticwebdriver getremotedriver (Remotebrowserbean remotebrowserbean) {8Desiredcapabilities capability =NULL;9         if(Remotebrowserbean.getbrowsername (). Contains ("Firefox"))) {TenCapability =Desiredcapabilities.firefox (); One}Else if(Remotebrowserbean.getbrowsername (). Contains ("Chrome")) { ACapability =desiredcapabilities.chrome (); -         } -  theWebdriver Driver =NULL; -         Try { -Driver =NewRemotewebdriver ( -                     NewURL (Remotebrowserbean.gethuburl ()), capability); +}Catch(malformedurlexception e) { - e.printstacktrace (); +         } A Capability.setbrowsername (Remotebrowserbean.getbrowsername ()); at capability.setversion (Remotebrowserbean.getversion ()); -Capability.setcapability (Remotebrowserbean.getplatform () [0], -Remotebrowserbean.getplatform () [1]); - driver.manage (). window (). Maximize (); -         returndriver; -}

Then you can use it in case

1 @BeforeClass (alwaysrun=true)2public     void  Beforetest ()3    {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.