(i) Preface
Selenium Grid you can distribute your tests on several physical or virtual machines to enable distribution or parallel execution of tests.
This link is official and relevant.
Https://github.com/SeleniumHQ/selenium/wiki/Grid2
(ii) Selenium Grid
That's probably what it means (a hub), n Subnodes (node, OS + browser)
(iii) Environment Configuration
1. Premise: The appropriate JDK environment has been configured (Linux comes with a JDK environment (my Linux comes with 1.8), Windows will configure the JDK environment (I am 1.9))
2. https://docs.seleniumhq.org/download/Download Selenium Standalone Server
3. Start Selenium Grid server (hub)
Selenium Grid Server (hub, which is the central node of the computer), switch to the directory where Selenium standalone is located (right-click in the folder standalone the Selenium shift+, choose to open the command window here , or the 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, default 4444
Http://localhost:4444/grid/console this address to access after startup
4. Configure node (nodes)
(1) node (that is, another computer or virtual machine environment, you can also directly add the hub of the computer as Node), in the system variable path is added to the path of the corresponding driver file. (Example: Add the path of Chromedriver to path, previously said Firefox, IE, Google browser environment configuration)
(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
Description
Browsername: Browser name
Version: Browser versions
Maxsession: Number of concurrent browser instances supported
Platform: Operating system
-hub:http://(Selenium Grid Server (Hub) IP) + port number set at startup/Grid/register
-port: Specify port number
(3) to the same computer (or virtual machine) to add another node, and then open a CMD window, run the above command (remember to modify the browser information), remember the same computer top number do not repeat.
(iv) the environment is configured as shown (My computer is driving a Linux virtual machine too card, a bit of a waste of time feeling, do not want to, but should and windows on the gap will not be too big, there is the environment can try to add the path variable, the terminal to execute related commands to add nodes)
(v) Example (run the script to see that the test runs directly in the matching environment)
1 ImportSYS2 ImportUnitTest3 fromSeleniumImportWebdriver4 fromSelenium.webdriver.common.action_chainsImportActionchains5 classsearchtest (unittest. TestCase):6 #define 2 Global properties, use default values when no external parameters are available7PLATFORM ="WINDOWS"8BROWSER ="Firefox"9 @classmethodTen defSetupClass (CLS): One #setting up the operating system and browser ADesired_caps = {} -desired_caps['Platform'] =CLS. PLATFORM -desired_caps['Browsername'] =CLS. BROWSER the #The IP here is the IP of the hub's computer. -Cls.driver = Webdriver. Remote ('Http://192.168.3.2:4444/wd/hub', Desired_caps) -Cls.driver.implicitly_wait (10) - Cls.driver.maximize_window () +Cls.driver.get ("https://www.cnblogs.com/") - + defTest_search_by_look (self): ASeach_class = Self.driver.find_element_by_xpath ('//li/a[@href = "/cate/2/"]') at #Small class Python in the Location programming language -Seach_small =self.driver.find_element_by_xpath ('//li/a[@href = "/cate/python/"]') - actionchains (self.driver). Move_to_element (Seach_class). Perform () - Seach_small.click () - #Check open page title is not Python-site category-Blog Park -Self.assertequal (Self.driver.title,"Python-Site Categories-Blog Park" ) in - @classmethod to defTeardownclass (CLS): + cls.driver.quit () - the if __name__=='__main__': * #when you run a script using the command line, if you add parameters, platform and browser use external parameters $ ifLen (SYS.ARGV) >1:Panax NotoginsengSearchtest.platform =Sys.argv.pop () -Searchtest.browser =Sys.argv.pop () the #Add verbosity=2 parameter to display the specific test method on the command line +Unittest.main (verbosity=2)
(vi) unresolved issues (configuring the environment alone is not enough)
1. implementing multiple environments to run the same test script in parallel
2. implementing multiple test scripts to run in parallel (for example, if hundreds of test scripts run one by one, it takes a long time)
Python+selenium Note (11): Configuring the Selenium Grid