当前位置:网站首页>UI automation test farewell to manual download of browser driver
UI automation test farewell to manual download of browser driver
2022-07-05 03:49:00 【Little brother said test】
Thank you for your time


“Everyone is doing UI When automating , What is the most annoying , Is it element positioning or browser and driver compatible debugging ? Let's move on
”

One .SeleniumWebDriver
SeleniumWebDriver Is a program that allows control Web Browser Library . It provides a cross browser API, Can be used to drive using different programming languages ( Such as Java、JavaScript、Python、C# or Ruby) Browser ( Such as Chrome、Edge or Firefox etc. ).Selenium WebDriver The main purpose of is to realize Web Automated testing of applications .
SeleniumWebDriver Use the native support of each browser to automate . For this reason , We need to use Selenium WebDriver API A browser named Driver Binary file . Now the drivers of mainstream web browsers are ChromeDriver (Chrome) ,geckoDriver (Firefox) , perhaps msededriver (Edge).WebDriver API The communication with the driver binary file is called W3C WebDriver( Formerly known as JSON Wire Protocol) The standard agreement of . then , Use the native function of each browser to complete the communication between the driver and the browser .
We manually download the corresponding version of the corresponding browser according to different browsers and browser versions driver, Set system properties .
System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");
System.setProperty("webdriver.gecko.driver", "/path/to/geckodriver");
System.setProperty("webdriver.edge.driver", "/path/to/msedgedriver");
System.setProperty("webdriver.opera.driver", "/path/to/operadriver");
System.setProperty("webdriver.ie.driver", "C:/path/to/IEDriverServer.exe");
We're doing it UI When automating, we often encounter browser upgrades that lead to driver Version mismatch problem , The solution is to manually download the corresponding version driver, For starters , It's not a simple job , Is there any way to automatically download the corresponding version according to different browsers driver Well ? The answer is yes , This is what we are talking about this time WebDriverManager. Yes Java and Python They all support it .
Two .WebDriverManager brief introduction
WebDriverManager It's an open source Java library , Of course, there are Python edition , It is executed in a fully automated way Selenium WebDriver Management of required drivers ( For example, download 、 Setup and maintenance ). in addition , In version 5 in ,WebDriverManager Other related functions are also provided , For example, find the browser installed in the local system , structure WebDriver object ( Such as ChromeDriver、FirefoxDriver、 EdgeDriver etc. ) , stay Docker The browser runs seamlessly in the container , And monitoring function .
3、 ... and .WebDriverManager actual combat (Java edition )
1.pom.xml Add WebDriverManager rely on
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>5.0.3</version>
<exclusions>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
</exclusions>
</dependency>
2. Create a new test script , To test the
import io.github.bonigarcia.wdm.WebDriverManager;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
/**
* @author author : The way test engineers grow up
* @version Creation time :2022/7/3
* Class description : Automatic download Chrome Browser driven
*/
public class OperateBrowserDriver {
public static void main(String[] args) throws InterruptedException {
WebDriverManager.chromedriver().setup();
WebDriver driver = new ChromeDriver();
driver.get("http://www.cnblogs.com/mrjade/");
Thread.sleep(1000);
driver.quit();
}
}
3. Execution results

4.driver Storage path ( With Macos For example )

Four .WebDriverManager actual combat (Python edition )
1. install
pip install webdriver-manager
2. Use
# coding=utf-8
'''
@Author : The way test engineers grow up
@Time : 2022/7/3 12:13
@Desc : Methods described
@Software: PyCharm
'''
import time
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(ChromeDriverManager().install())
driver.get("https://www.baidu.com/")
time.sleep(5)
driver.quit()
3. Execution results

4.driver Storage path ( With Macos For example )

Four . Official documents
For more browser operations, please refer to the official website documentation
https://bonigarcia.dev/webdrivermanager/
Learning resource sharing
Finally, thank everyone who reads my article carefully , Watching the rise and attention of fans all the way , Reciprocity is always necessary , Although it's not very valuable , If you can use it, you can take it

These materials , For thinking 【 Advanced test development 】 For our friends, it should be the most comprehensive and complete war preparation warehouse , This warehouse also accompanied me through the most difficult journey , I hope it can help you ! Everything should be done as soon as possible , Especially in the technology industry , We must improve our technical skills . I hope that's helpful …….

边栏推荐
- ICSI213/IECE213 Data Structures
- Excuse me, my request is a condition update, but it is blocked in the buffer. In this case, can I only flush the cache every time?
- [web Audit - source code disclosure] obtain source code methods and use tools
- An elegant program for Euclid‘s algorithm
- ABP vNext microservice architecture detailed tutorial - distributed permission framework (Part 1)
- How rem is used
- Monitoring web performance with performance
- 线上故障突突突?如何紧急诊断、排查与恢复
- Ubantu disk expansion (VMware)
- Google Chrome CSS will not update unless the cache is cleared - Google Chrome CSS doesn't update unless clear cache
猜你喜欢

How to learn to get the embedding matrix e # yyds dry goods inventory #
![Yuancosmic ecological panorama [2022 latest]](/img/55/0901109e4c865b77137610b4fe0624.jpg)
Yuancosmic ecological panorama [2022 latest]

NEW:Devart dotConnect ADO.NET

【web源码-代码审计方法】审计技巧及审计工具

Pdf things
![[vérification sur le Web - divulgation du code source] obtenir la méthode du code source et utiliser des outils](/img/ea/84e67a1fca0e12cc4452c744c242b4.png)
[vérification sur le Web - divulgation du code source] obtenir la méthode du code source et utiliser des outils

DMX parameter exploration of grandma2 onpc 3.1.2.5

postman和postman interceptor的安装

一文带你了解BI的前世今身与企业数字化转型的关系

面试汇总:这是一份全面&详细的Android面试指南
随机推荐
PlasticSCM 企业版Crack
[move pictures up, down, left and right through the keyboard in JS]
[105] Baidu brain map - Online mind mapping tool
v-if VS v-show 2.0
The architect started to write a HelloWorld
Pdf things
[安洵杯 2019]不是文件上传
请问一下我的请求是条件更新,但在buffer中就被拦截了,这种情况我只能每次去flush缓存么?
Class inheritance in C #
MySQL winter vacation self-study 2022 11 (9)
De debugging (set the main thread as hidden debugging to destroy the debugging Channel & debugger detection)
Why is there a reincarnation of 60 years instead of 120 years in the tiangan dizhi chronology
Accuracy problem and solution of BigDecimal
C file in keil cannot be compiled
【做题打卡】集成每日5题分享(第三期)
程序员的视力怎么样? | 每日趣闻
Clickhouse synchronization MySQL (based on materialization engine)
Kubernetes - identity and authority authentication
Flex flexible layout
VM in-depth learning (XXV) -class file overview