selenium grid (distributed)

foreword

Original text: https://blog.csdn.net/real_tino/article/details/53467406

Selenium grid is a tool for distributed execution of test case scripts. For example, testers often need to test the compatibility of multiple browsers, then grid can be used.

1. The files required to use the grid

1.Selenium server(即selenium-server-standalone-x.xx.x.jar)

Download the corresponding version http://selenium-release.storage.googleapis.com/index.html

My selenium corresponds to version 2.53.1

2.grid configuration file (this file is responsible for providing host and browser information)

1 def grid():
2     d={'http://127.0.0.1:4444/wd/hub':'firefox','http://127.0.0.1:5555/wd/hub':'chrome'}
3     return d 
4     

This file defines a method, which stores a dictionary, assigns 2 different ports to the machine and specifies different browsers (4444 is the default port of grid hub, 5555 is the port of a node)

3. Test script

 1 # encoding:utf-8
 2 
 3 from selenium import webdriver
 4 from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
 5 import time, os.path
 6 import grid_module
 7 
 8 for host, browser in grid_module.grid().items():
 9     driver = webdriver.Remote(
10         command_executor=host,
11         desired_capabilities={
12             'platform': 'ANY',
13             'browserName': browser,
14             'version': '',
15             'javascriptEnabled': True
16         }
17     )
18     driver.get("http://www.baidu.com")
19     driver.find_element_by_id("kw").send_keys(u"中国")
20     driver.find_element_by_id("su").click()
 21      time.sleep(3 )
 22      if driver.title == u " China_Baidu Search " :
 23          print ( " Title matches! " )
 24      else :
 25          print ( " Title does not match! " )
 26      driver.close()

This script is a script that writes a Baidu search keyword and makes a simple assertion. The imported grid_module is the grid configuration file in the first step. The loop body writes the host name and browser name from the dictionary and assigns it to the following parameters, so that the test script will successively call the two specified local browsers and run

2. Execute the script

1. Start selenium server

1) Open cmd and enter the command in the path where the selenium server is located (do not close)

java -jar selenium-server-standalone-2.53.1.jar -role hub

2) Open another command, enter the command (do not close)

Java -jar selenium-server-standalone-2.53.1.jar -role node -port 5555

This is to start the first node, specify port 5555, which is consistent with the port written in the grid configuration file

3) After the hub and node are started, we enter http://127.0.0.1:4444/grid/console in the browser , open the grid console, we can see that a node with port 5555 has been started, The IP here is the local IP

4) Run the script

3. Problems encountered

1.cannot find firefox binary in path

Solution: Add the Firefox browser path to the system variable without spaces in the path

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324980285&siteId=291194637