Python + Selenium notes (11): Configure selenium Grid and pythonselenium

Source: Internet
Author: User
Tags seleniumhq selenium grid

Python + Selenium notes (11): Configure selenium Grid and pythonselenium

(1)Preface

Selenium GridTests can be distributed on several physical or virtual machines to perform tests in a distributed or parallel manner.

This link is an official description.

Https://github.com/SeleniumHQ/selenium/wiki/Grid2

(2)Selenium Grid

This is probably the meaning (a central NODE (HUB), N subnodes (NODE, operating system + browser ))

 

 

(3)Environment Configuration

1. Prerequisites: The corresponding JDK environment has been configured (JDK environment is included in LINUX (1.8 is included in LINUX), and JDK environment must be configured in WINDOWS (1.9 Is Installed in LINUX ))

2. Download Selenium Standalone Server from https://docs.seleniumhq.org/download/

 

3. Start Selenium Grid server (hub)

Selenium Grid server (hub, the computer that stores the Code), switch to the directory where Selenium Standalone is located (directly in the folder where Selenium Standalone is located shift + right-click, select here to open the command window or CD path), and then execute the following command

java -jar selenium-server-standalone-<version>.jar -role hub
Example: java-jar selenium-server-standalone-3.9.1.jar-role hub
You can add-port to specify the port number. The default value is 4444.
Http: // localhost: 4444/grid/console

4. Configure node)

(1) Node (that is, other computer or virtual machine environments, you can also directly add the computer where the hub is located as a node ), add the corresponding driver file path to the system variable path. (For example, add the path where chromedriver is located to the path. We have already said the configuration of Firefox, IE, and Google browser environments)

(2) execute the following command

Java-jar selenium-server-standalone-3.9.1.jar-role node-browser "browserName = firefox, version = 62, maxSession = 3, platform = WINDOWS"-hub http: // 192.168.4.196: 4444/grid/register-port 5555

Note:

BrowserName: browser name

Version: browser Version

MaxSession: number of concurrent browser instances supported

Platform: Operating System

-Hub: http: // (Selenium Grid server (hub) IP address) + port number set at startup/grid/register

-Port: Specifies the port number.

(3) add other nodes to the same computer (or virtual machine), open a CMD window, and run the preceding command (remember to modify the browser information ), do not repeat the port number on the same computer.

(4)After the environment is configured, as shown in figure (I don't want to figure it out if I have a linux virtual machine on my computer and it is a waste of time, but it should not be too close to windows, if you have an environment, try to add the path variable and execute related commands on the terminal to add nodes)

 

(5)Example (run the script to directly run the test in the matching environment)

1 import sys 2 import unittest 3 from selenium import webdriver 4 from selenium. webdriver. common. action_chains import ActionChains 5 class SearchTest (unittest. testCase): 6 # define two global attributes. If no external parameters are available, use the default value 7 PLATFORM = "WINDOWS" 8 BROWSER = "firefox" 9 @ classmethod10 def setUpClass (cls ): 11 # Set the operating system and browser 12 desired_caps ={} 13 desired_caps ['platform'] = cls. PLATFORM14 desired_caps ['browsername'] = cls. BROWSER15 # the IP address here is the IP address of the computer on which the HUB is located. driver = webdriver. remote ('HTTP: // 192.168.3.2: 4444/wd/hub ', desired_caps) 17 cls. driver. implicitly_wait (10) 18 cls. driver. maximize_window () 19 cls. driver. get ("https://www.cnblogs.com/") 20 21 def test_search_by_look (self): 22 seach_class = self. driver. find_element_by_xpath ('// li/a [@ href = "/cate/2/"]') 23 # locate the small class Python24 seach_small = self in the programming language. driver. find_element_by_xpath ('// li/a [@ href = "/cate/python/"]') 25 ActionChains (self. driver ). move_to_element (seach_class ). perform () 26 seach_small.click () 27 # Check whether the webpage title is Python-website classification-blog 28 self. assertEqual (self. driver. title, "Python-website classification-blog Park") 29 30 @ classmethod31 def tearDownClass (cls): 32 cls. driver. quit () 33 34 if _ name _ = '_ main _': 35 # if a parameter is added when you run the script using the command line, PLATFORM and BROWSER use the External Parameter 36 if len (sys. argv)> 1: 37 SearchTest. PLATFORM = sys. argv. pop () 38 SearchTest. BROWSER = sys. argv. pop () 39 # Add the verbosity = 2 parameter to display the specific test method 40 unittest in the command line. main (verbosity = 2)

(6)Unsolved Problems (configuring the environment alone is not enough)

1,Run the same test script in parallel in multiple Environments

2,Implement Parallel Running of the same script in different environments

 

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.