buildstep shell 脚本中一开始配置如下;
pip install -r reqirements.txt
pytest
执行就提示“pip: command not found”
修改后
pip3install -r reqirements.txt
pytest
执行后提示:pytest: command not found
把pytest 改成全路径后修复
/opt/homebrew/anaconda3/envs/py38selenium/bin/pytest
新的问题是在本地case是通过的,但是到jenkins上case执行过程报错
_________________________________ test_case01 __________________________________service = options = @staticmethod def get_path(service: Service, options: BaseOptions) -> str: path = service.path try:> path = SeleniumManager().driver_location(options) if path is None else path/opt/homebrew/anaconda3/envs/py38selenium/lib/python3.8/site-packages/selenium/webdriver/common/driver_finder.py:38: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /opt/homebrew/anaconda3/envs/py38selenium/lib/python3.8/site-packages/selenium/webdriver/common/selenium_manager.py:106: in driver_location output = self.run(args)_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ args = ['/opt/homebrew/anaconda3/envs/py38selenium/lib/python3.8/site-packages/selenium/webdriver/common/macos/selenium-manager', '--browser', 'chrome', '--language-binding', 'python', '--output', ...] @staticmethod def run(args: List[str]) -> dict: """Executes the Selenium Manager Binary. :Args: - args: the components of the command being executed. :Returns: The log string containing the driver location. """ if logger.getEffectiveLevel() == logging.DEBUG: args.append("--debug") args.append("--language-binding") args.append("python") args.append("--output") args.append("json") command = " ".join(args) logger.debug("Executing process: %s", command) try: if sys.platform == "win32": completed_proc = subprocess.run(args, capture_output=True, creationflags=subprocess.CREATE_NO_WINDOW) else: completed_proc = subprocess.run(args, capture_output=True) stdout = completed_proc.stdout.decode("utf-8").rstrip("\n") stderr = completed_proc.stderr.decode("utf-8").rstrip("\n") output = json.loads(stdout) result = output["result"] except Exception as err: raise WebDriverException(f"Unsuccessful command executed: {command}") from err for item in output["logs"]: if item["level"] == "WARN": logger.warning(item["message"]) if item["level"] == "DEBUG" or item["level"] == "INFO": logger.debug(item["message"]) if completed_proc.returncode:> raise WebDriverException(f"Unsuccessful command executed: {command}.\n{result}{stderr}")E selenium.common.exceptions.WebDriverException: Message: Unsuccessful command executed: /opt/homebrew/anaconda3/envs/py38selenium/lib/python3.8/site-packages/selenium/webdriver/common/macos/selenium-manager --browser chrome --language-binding python --output json.E {'code': 65, 'message': 'error sending request for url (https://storage.googleapis.com/chrome-for-testing-public/124.0.6367.60/mac-arm64/chromedriver-mac-arm64.zip): error trying to connect: Connection reset by peer (os error 54)', 'driver_path': '', 'browser_path': ''}/opt/homebrew/anaconda3/envs/py38selenium/lib/python3.8/site-packages/selenium/webdriver/common/selenium_manager.py:154: WebDriverExceptionThe above exception was the direct cause of the following exception: def test_case01():> driver = webdriver.Chrome()testcase/test_login.py:8: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /opt/homebrew/anaconda3/envs/py38selenium/lib/python3.8/site-packages/selenium/webdriver/chrome/webdriver.py:45: in __init__ super().__init__(/opt/homebrew/anaconda3/envs/py38selenium/lib/python3.8/site-packages/selenium/webdriver/chromium/webdriver.py:49: in __init__ self.service.path = DriverFinder.get_path(self.service, options)_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ service = options = @staticmethod def get_path(service: Service, options: BaseOptions) -> str: path = service.path try: path = SeleniumManager().driver_location(options) if path is None else path except Exception as err: msg = f"Unable to obtain driver for {options.capabilities['browserName']} using Selenium Manager."> raise NoSuchDriverException(msg) from errE selenium.common.exceptions.NoSuchDriverException: Message: Unable to obtain driver for chrome using Selenium Manager.; For documentation on this error, please visit:https://www.selenium.dev/documentation/webdriver/troubleshooting/errors/driver_location/opt/homebrew/anaconda3/envs/py38selenium/lib/python3.8/site-packages/selenium/webdriver/common/driver_finder.py:41: NoSuchDriverException=========================== short test summary info ============================FAILED testcase/test_login.py::test_case01 - selenium.common.exceptions.NoSuchDriverException: Message: Unable to obtain driver for chrome using Selenium Manager.; For documentation on this error, please visit:https://www.selenium.dev/documentation/webdriver/troubleshooting/errors/driver_location============================== 1 failed in 22.05s ==============================Build step 'Execute shell' marked build as failure[selenimuAllure] $ /opt/homebrew/Cellar/allure/2.28.0/bin/allure generate /Users/cwc/.jenkins/workspace/selenimuAllure/report -c -o /Users/cwc/.jenkins/workspace/selenimuAllure/allure-reportReport successfully generated to /Users/cwc/.jenkins/workspace/selenimuAllure/allure-reportAllure report was successfully generated.Creating artifact for the build.Artifact was added to the build.Finished: FAILURE
网上搜罗一番看意思大概是说selenium找不到浏览器webdriver
https://blog.csdn.net/CcReborn/article/details/132656781找到这篇教程
参考着修改了代码:
chrome_driver_path ="/opt/homebrew/anaconda3/envs/py38selenium/bin/chromedriver"
service = Service(executable_path=chrome_driver_path)
driver = webdriver.Chrome(service=service)
driver.maximize_window()
通过!!
PS:另外还有一个奇怪的问题,本地环境修改为python3.9后也有这个报错,但是本地用python3.8不报错,奇怪的是在jenkins端看起来用的是3.8也会报错,在本地使用3.9复现问题后修改代码本地通过,然后使用新代码Jenkins上也通过了