如何使用 Webdriver-Manager 在 Protractor 中下载适当的 Chromedriver [英] How can I download Appropriate Chromedriver in Protractor using Webdriver-Manager
问题描述
我设计了一个基于黄瓜量角器的自动化框架,除了 Webdriver-manager 之外,一切正常.每次 IT 部门更新谷歌浏览器版本时,我都需要手动更新二进制文件.
I have designed a cucumber-protractor based automation framework where everything is working fine except for the Webdriver-manager. I need to update the binaries manually each time the IT Department updates google chrome version.
当我使用命令 "webdriver-manager update --proxy=http://someproxy.com:PORT#"
时,webdriver-manager 总是下载最新的 chromdriver 二进制文件而不是兼容的版本与当前 Chrome 版本一致.
When i use command "webdriver-manager update --proxy=http://someproxy.com:PORT#"
, webdriver-manager always downloads the latest chromdriver binaries instead of a compatible version as per the current Chrome Version.
如果有办法自动确定 Chrome 版本并下载相应的 Chrome 二进制文件,请帮助我.
Please help me if there is a way to determine the chrome version automatically and download the corresponding Chrome binaries.
我曾尝试在其他地方搜索类似的行为和论坛,但没有一个命令有效.相反,它总是下载最新版本的 chromedriver 二进制文件,而不是兼容的二进制文件.
I have tried to search for similar behavior and forums elsewhere but none of the commands work. Instead it always downloads the latest version of chromedriver binaries instead of a compatible one.
如果您找到了解决方案,请帮助提供一些示例代码.
Please help with some sample code in-case you come through a solution to this.
推荐答案
您可以在开始测试之前运行 sh
,以确定 chromedriver
是否需要更新:
You could run a sh
prior to starting your tests that will determine wether the chromedriver
needs to be updated:
#!/bin/bash
# get existing chromedriver version
EXISTING_CD_VERSION=$(node_modules/.bin/chromedriver -version | egrep -o '(\d+)\.(\d+)\.(\d+)')
# get installed Google Chrome version
CHROME_VERSION=$(/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --version | egrep -o '(\d+)\.(\d+)\.(\d+)')
if [ "$EXISTING_CD_VERSION" = "$CHROME_VERSION" ]; then
echo "ChromeDriver version matches the Google Chrome version"
else
NEW_CD_VERSION=$(curl https://chromedriver.storage.googleapis.com/LATEST_RELEASE_$CHROME_VERSION)
node_modules/.bin/webdriver-manager update --versions.chrome $NEW_CD_VERSION
fi
注意:上面的脚本是从 MacOS 系统获取 Google Chrome 版本.如果您使用的是 Linux,则需要将其更改为 google-chrome --version
NOTE: The script above is getting the Google Chrome version from a MacOS system. If you're on Linux, you need to change that to google-chrome --version
这篇关于如何使用 Webdriver-Manager 在 Protractor 中下载适当的 Chromedriver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!