如何使用 WebDriverManager 在没有 setup() 方法的情况下查找 Web 浏览器版本

发布于 2025-01-11 00:43:04 字数 607 浏览 0 评论 0原文

我有兴趣获取浏览器版本

我有两个问题

- 问题 1:- 有没有一种方法可以在不设置浏览器的情况下找出浏览器版本? 或者我们可以首先强制停止驱动程序的下载。 可以使用以下代码,但在这种情况下将下载驱动程序。

WebDriverManager.chromedriver().setup();  //without doing this step
WebDriverManager.chromedriver().getDownloadedDriverVersion();

问题 2:- 目前我使用 wmic 命令进行浏览器检测,该命令在 WebDriverManager 中使用,但在某些系统上失败。 WebDriverManager 中还使用哪些替代方法来获取浏览器版本。我很想知道这一点,因为我在系统上禁用了 wmic,但 webDriverManager 仍然照常工作(我猜想使用 WebDriverManager 中的替代方法)。我在理解代码方面面临困难。请帮助我了解 WebDriverManager 的流程,例如使用哪些方法/方式来检测浏览器版本以及按什么顺序。

任何帮助将不胜感激!

I am interested in getting the browser Version

I've two questions-

Question 1:- is there is a way to find out the browser version without setting up the browser?
or can we force stop the downloading of the Driver in the first place.
It is possible with the below code but the driver will be downloaded in this case.

WebDriverManager.chromedriver().setup();  //without doing this step
WebDriverManager.chromedriver().getDownloadedDriverVersion();

Question 2:-
Currently I am using wmic commands for browser detection which is used in WebDriverManager but it is failing on some systems.
what more alternatives ways are used in the WebDriverManager to fetch the browser version. I am curious to know about this as I've disabled wmic on my system still webDriverManager is working as usual(I guess with alternative methods within WebDriverManager).I am facing difficulties in understand the code. Please help me to understand the flow of the WebDriverManager like which methods/ways are used to detect the browser version and in what order.

Any help would be appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

月亮邮递员 2025-01-18 00:43:04

WebDriverManager

WebDriverManager 是开源 Java 库,用于维护 Selenium WebDriver(例如,chromedriver、geckodriver、 msedgedriver 等)以完全自动化的方式。

此外,WebDriverManager 还提供其他相关功能,例如发现本地系统中安装的浏览器、构建 WebDriver 对象(例如如 ChromeDriver、FirefoxDriver、EdgeDriver 等),并在 Docker 容器中无缝运行浏览器。

WebDriverManager 的主要用途是驱动程序管理的自动化(即下载安装 维护测试自动化套件中涉及的驱动程序。因此,使用 WebDriverManager 您不太可能首先强制停止驱动程序的下载。

但是,当您一段时间以来第一次使用特定的浏览器版本时,会下载匹配的驱动程序版本并将其保存在缓存中,这从生成的日志中非常明显。

====== WebDriver manager ======
Current google-chrome version is 98.0.4758
Get LATEST chromedriver version for 98.0.4758 google-chrome
There is no [win32] chromedriver for browser  in cache
Trying to download new driver from https://chromedriver.storage.googleapis.com/98.0.4758.102/chromedriver_win32.zip
Driver has been saved in cache [C:\Users\Sadanand.Kolhe\.wdm\drivers\chromedriver\win32\98.0.4758.102]

展望未来,如果浏览器版本和匹配的驱动程序版本保持不变,并且同时缓存中存在已下载版本的驱动程序的先前版本,则可以避免重新下载,这从两个生成的日志中可以明显看出背靠背测试执行。

====== WebDriver manager ======
Current google-chrome version is 98.0.4758
Get LATEST chromedriver version for 98.0.4758 google-chrome
Driver [C:\Users\Sadanand.Kolhe\.wdm\drivers\chromedriver\win32\98.0.4758.102\chromedriver.exe] found in cache

WebDriverManager

WebDriverManager is the open-source Java library that maintains the configuration management of the drivers required by Selenium WebDriver (e.g., chromedriver, geckodriver, msedgedriver, etc.) in a fully automated fashion.

Additionally, WebDriverManager provides other relevant features, such as the capability to discover browsers installed in the local system, building WebDriver objects (such as ChromeDriver, FirefoxDriver, EdgeDriver, etc.), and running browsers in Docker containers seamlessly.

The primary use of WebDriverManager is the automation of driver management (i.e., download, setup, and maintenance) of the drivers involved in your Test Automation Suite. Hence using WebDriverManager it's highly unlikely you can force stop the downloading of the Driver in the first place.

However, when you use a specific browser version for the first time in a while the matched driver version is downloaded and saved within the cache which is pretty much evident from the generated logs.

====== WebDriver manager ======
Current google-chrome version is 98.0.4758
Get LATEST chromedriver version for 98.0.4758 google-chrome
There is no [win32] chromedriver for browser  in cache
Trying to download new driver from https://chromedriver.storage.googleapis.com/98.0.4758.102/chromedriver_win32.zip
Driver has been saved in cache [C:\Users\Sadanand.Kolhe\.wdm\drivers\chromedriver\win32\98.0.4758.102]

Moving forward, if the browser version and the matched driver version remains unchanged and at the same time the previous version of the downloaded version of the driver is available within the cache, the fresh downloading is avoided, which is evident from the logs generated from two back to back test execution.

====== WebDriver manager ======
Current google-chrome version is 98.0.4758
Get LATEST chromedriver version for 98.0.4758 google-chrome
Driver [C:\Users\Sadanand.Kolhe\.wdm\drivers\chromedriver\win32\98.0.4758.102\chromedriver.exe] found in cache
GRAY°灰色天空 2025-01-18 00:43:04

关于第一个问题,从版本 5 开始,WebDriverManager 允许检测本地系统中是否安装了给定的浏览器。为此,每个管理器都提供了方法getBrowserPath()。此方法返回一个 Optional,如果系统中未安装给定浏览器或检测到的浏览器路径(在可选对象内),则该值为空。请参阅文档

关于 Q2,WebDriverManager 在内部使用一个名为 命令数据库的知识数据库。该数据库是 shell 命令的集合,用于发现不同操作系统中给定浏览器的版本(例如,Linux 中的 Chrome 的 google-chrome --version)。该数据库包含适用于 Windows 的 WMIC 命令,还包含对注册表的查询。再次参阅 doc

Regarding Q1, as of version 5, WebDriverManager allows detecting if a given browser is installed or not in the local system. To this aim, each manager provides the method getBrowserPath(). This method returns an Optional<Path>, which is empty if a given browser is not installed in the system or the browser path (within the optional object) when detected. See doc.

Regarding Q2, WebDriverManager uses internally a knowledge database called commands database. This database is a collection of shell commands used to discover the version of a given browser in the different operating systems (e.g., google-chrome --version for Chrome in Linux). This database contains WMIC commands for Windows but also queries to the registry. See doc again.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文