Webdriver Multithreading concurrency

Source: Internet
Author: User

To run Webdriver with multiple threads concurrently, you must satisfy 2 conditions at the same time, first of all, your test program is multi-threaded, and then you need to use selenium Server. Download locations such as:

After downloading it is a jar package that needs to be run on the command line. There are 2 things inside: Hub and node. It can be understood that the hub is a thread pool running on a server that collects requests for test case submissions, assigns requests to the matching node, and node is the working thread that works specifically. Node can have multiple, running on different systems. Hub and node can also not be on a machine.

Multi-threaded concurrency running Webdriver: 1. Run hub 2. Run node 3. Run the test case. The following is the specific implementation method.

1. Run the hub. On the command line, enter: Java-jar selenium-server-standalone-2.37.0.jar-role hub-maxsession 40-port 4444

Parameter must indicate that the-role hub is the running hub. The default port is 4444, and you need to specify the other if the port is occupied. -maxsession is the maximum processing session request, which I set here to 40. If not specified, the default is 1 (that is, single-threaded mode).

2. Run node. (The next command is to run a node condition) on the command line (the following is a line to knock out):

Java-dwebdriver.ie.driver=d:\iedriverserver.exe-jar selenium-server-standalone-2.37.0.jar-role Node-hub/http 127.0.0.1:4444/grid/register-maxsession 20-browser "Browsername=internet explorer,version=9,platform=windows, Maxinstances=20 "-port 5555

Because node can be run on a system that is not accessible, the specified drive location is-dwebdriver.ie.driver=d:\iedriverserver.exe. The parameter must indicate that-role node is running node. The parameter-hub is followed by the IP and port of the hub in the first step: Http://hub IP: Port/grid/register. Node default Maxsession value is 5 (up to 5 browsers), that is, start a node will default to 5 Firefox, 1 chrome, 1 IE instances. If you use IE browser, even if your test case is multi-threaded, it will eventually be a one-off execution. However, if you specify maxinstances=5 in the parameters of the following-browser, you will run 5 browsers at the same time. The-browser parameter is the browser information that indicates what node can use. Note that if there is a problem with node's maxsession and maxinstances settings, a warning is given in the command window of the hub. This is the place to know if your node is set up successfully. After you run node, the node information is also displayed in the window. -port is the port number, the default port is 5555, if the port is occupied you need to specify the other. If you start a second node, the port must be specified, not 5555.

I set the node to run only IE, and the number of concurrent is 20, and up to 20 IE browsers are running. The value of the maxsession in node cannot exceed that in the hub. If you want multi-threaded concurrency, specify the maxsession value in both the hub and node parameters. If you use IE in node, you also need to indicate the maxinstances value of the same size after maxsession. My example will eventually run 20 ie browsers at the same time. Maxsession is that node can have several browsers running at the same time, while Maxinstances is saying that a browser can have several simultaneous runs. Since my computer is running 20 ie has some cards, then you can run another computer on a 20Session-size node. Personal test results: Running a 20Session size node is no different than running a 2 10Session size node. Running more than one node is primarily for distributed testing and does not allow a single computer to open too many browsers.

3. Run the test case. First comment out the 44 and 47 lines in the code above and open the 48-line comment. We need to submit the request to the hub in a remote way (the/wd/hub behind it is fixed).

Webdriver Driver = new Remotewebdriver (The new URL ("Http://hub IP: Port/wd/hub"), capability);

Because it is a remote way, the 44-row setup is useless. Below you can run your program, you will find that starting 20 threads at the same time, there will be 20 Internet Explorer running at the same time.

Webdriver Multithreading concurrency

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.