1. Overview of capability
- Capability is an extended command (configuration information) beyond the standard commands supported by webdriver
- Configure web driver properties, such as browser name and browser platform.
- Combined with selenium gird to complete distributed and compatibility testing
- Official website address: https://www.selenium.dev/zh-cn/documentation/webdriver/capabilities/shared/
2. Capability configuration
def test_capability():
# 切换成 windows 就会报错
capabilities = {"browserName": "chrome", "platformName": "windows"}
# 通过 desired_capabilities 添加配置信息
driver = webdriver.Chrome(desired_capabilities=capabilities)
driver.implicitly_wait(5)
driver.get("https://ceshiren.com/")
# 输入框输入搜索内容[霍格沃兹测试学院]
text = driver.find_element(By.CSS_SELECTOR, ".login-button").text
# 点击搜索按钮
print(text)
time.sleep(3)
driver.quit()
3. Introduction to Selenium Grid
- Selenium Grid allows us to run tests in parallel on multiple machines and manage different browser versions and browser configurations centrally (rather than in each individual test).
- Official website address: https://www.selenium.dev/documentation/grid/
4. Distributed operation
def test_ceshiren2():
hogwarts_grid_url = "https://selenium-node.hogwarts.ceshiren.com/wd/hub"
capabilities = {"browserName":"chrome","browserVersion":"101.0"}
# 配置信息
# 实例化Remote,获取可以远程控制的driver实例对象
# 通过 command_executor 配置selenium hub地址
# 通过 desired_capabilities 添加配置信息
driver = webdriver.Remote(
command_executor=hogwarts_grid_url,
desired_capabilities=capabilities)
driver.implicitly_wait(5)
driver.get("https://ceshiren.com/")
# 输入框输入搜索内容[霍格沃兹测试学院]
text = driver.find_element(By.CSS_SELECTOR, ".login-button").text
# 点击搜索按钮
print(text)
time.sleep(3)
driver.quit()
Finally, I would like to thank everyone who read my article carefully. Looking at the increase in fans and attention, there is always some courtesy. Although it is not a very valuable thing, if you can use it, you can take it directly!
Software Testing Interview Document
We must study to find a high-paying job. The following interview questions are from the latest interview materials from first-tier Internet companies such as Alibaba, Tencent, Byte, etc., and some Byte bosses have given authoritative answers. After finishing this set I believe everyone can find a satisfactory job based on the interview information.