![](/img/trans.png)
[英]Selenium-Python - How to reduce time for NoSuchElementException
[英]How to setup chromedriver in jenkins for selenium-python script?
我正在使用以下代码在本地机器上运行我的脚本
from seleniumwire import webdriver
import pytest
from selenium.webdriver.chrome.options import Options
import time
import allure
class Test_main():
@pytest.fixture()
def test_setup(self):
# instantiate browser
chrome_options = Options()
chrome_options.add_argument('--start-maximized')
chrome_options.add_argument('--headless')
self.driver = webdriver.Chrome(executable_path=r"D:/Python/Sel_python/drivers/chromedriverv86/chromedriver.exe", chrome_options=chrome_options)
# terminate script
yield
self.driver.close()
self.driver.quit()
print("Test completed")
##Remaining functions/test cases followed. Not adding the entire script here
我将此代码推送到 git 上,然后尝试使用以下构建命令在 jenkins 中运行相同的代码:
cd "D:\Python\Sel_python\Pytest"
pip install -r requirements.txt
pytest Test_Tracking_code_scripts.py -s -v
但是随后jenkins抛出了chromedriver无法定位的错误。 我的问题是:
chromedriver.exe
上传到我的 git 存储库中我是 jenkins 的新手,请在这里帮帮我
self.driver = webdriver.Chrome(executable_path=r"D:/Python/Sel_python/drivers/chromedriverv86/chromedriver.exe", chrome_options=chrome_options)
作为
self.driver = webdriver.Chrome(executable_path=r"C:/drivers/chromedriver.exe", chrome_options=chrome_options)
如果您遇到任何问题,请告诉我。
注意:
我找到了解决方案。 我的代码缺少 chrome 二进制路径。 添加与Options()
参数相同的参数解决了该错误。
分享更新的代码补丁:
from seleniumwire import webdriver
import pytest
from selenium.webdriver.chrome.options import Options
import time
import allure
class Test_main():
@pytest.fixture()
def test_setup(self):
# initiating browser
chrome_options = Options()
chrome_options.binary_location=r"C:\Users\libin.thomas\AppData\Local\Google\Chrome\Application\chrome.exe"
chrome_options.add_argument('--start-maximized')
chrome_options.add_argument('--headless')
self.driver = webdriver.Chrome(executable_path=r"D:/Python/Sel_python/drivers/chromedriver v86/chromedriver.exe",options=chrome_options)
# terminate script
yield
self.driver.close()
self.driver.quit()
print("Test completed")
#test cases followed below
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.