使用ChromeOptions opt.add_argument 添加参数方式,使用本地浏览器缓存执行用例报错

讨论 2 464
xiaojianwen
xiaojianwen LV1 2023年5月15日 20:46 编辑
<h3><span style="font-weight: bold;">操作步骤:&nbsp;</span></h3><p id="descriptionP"><span style="font-weight: bold;">1、修改引擎源码 testcase.py:</span></p><pre><code>if test.driver["browser_opt"] == "headless": <br> opt = webdriver.ChromeOptions() <br> opt.add_argument("--headless") <br> opt.add_argument("--no-sandbox") <br> # 添加保持登录的数据路径 <br> opt.add_argument("--user-data-dir=" + r"C:/Users/Administrator/AppData/Local/Google/Chrome/User Data") <br>elif test.driver["browser_opt"] == "remote": <br> caps = { 'browserName': 'chrome' } <br>else: opt = webdriver.ChromeOptions() # 添加保持登录的数据路径 <br> opt.add_argument("--user-data-dir=" + r"C:/Users/Administrator/AppData/Local/Google/Chrome/User Data") <br> opt.add_experimental_option('excludeSwitches', ['enable-logging'])</code></pre><p>&nbsp;<img src="http://www.liumatest.cn/community/editor-md-upload/03f0667a6fb54117a98dd6107c8f59ad.png" style="max-width: 100%;"></p><p><span style="font-weight: bold;">2、返回项目平台调试用例,能打开浏览器,但没有顺利执行用例,日志如下:</span>&nbsp;</p><pre><code>2022-11-22 15:02:48.318015 - Error - Message: unknown error: Chrome failed to start: exited normally. (unknown error: DevToolsActivePort file doesn't exist) (The process started from chrome location C:\Program Files\Google\Chrome\Application\chrome.exe is no longer running, so ChromeDriver is assuming that Chrome has crashed.) <br>2022-11-22 15:02:48.323998 - Error - 程序错误信息:<br>Traceback (most recent call last): File "D:\install\Python\Python3.9.11\lib\unittest\case.py", line 59, in testPartExecutor yield File "D:\install\Python\Python3.9.11\lib\unittest\case.py", line 592, in run self._callTestMethod(testMethod) File "D:\install\Python\Python3.9.11\lib\unittest\case.py", line 550, in _callTestMethod method() File "F:\project\Liuma-engine\lm\lm_case.py", line 26, in testEntrance WebTestCase(test=self).execute() File "F:\project\Liuma-engine\core\web\testcase.py", line 47, in __init__ self.driver = webdriver.Chrome(executable_path=test.driver["browser_path"], options=opt) File "C:\Users\Administrator\.virtualenvs\automation2-master-Cbq6gXD4\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 76, in __init__ RemoteWebDriver.__init__ File "C:\Users\Administrator\.virtualenvs\automation2-master-Cbq6gXD4\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 157, in __init__ self.start_session(capabilities, browser_profile) File "C:\Users\Administrator\.virtualenvs\automation2-master-Cbq6gXD4\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 252, in start_session response = self.execute(Command.NEW_SESSION, parameters) File "C:\Users\Administrator\.virtualenvs\automation2-master-Cbq6gXD4\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute self.error_handler.check_response(response) File "C:\Users\Administrator\.virtualenvs\automation2-master-Cbq6gXD4\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited normally. (unknown error: DevToolsActivePort file doesn't exist) (The process started from chrome location C:\Program Files\Google\Chrome\Application\chrome.exe is no longer running, so ChromeDriver is assuming that Chrome has crashed.)</code></pre><p><br></p><p><br></p>
收藏(0)  分享
相关标签: 讨论
注意:本文归作者所有,未经作者允许,不得转载
2个回复
  • Chras-fu
    2023年5月14日 12:01
    可能是你的浏览器没有安装在默认位置,在启动参数里添加binary_location参数指定chrome.exe的绝对路径,参考https://stackoverflow.com/questions/70465933/chromedriver-is-no-longer-running-so-chromedriver-is-assuming-that-chrome-has-c
    0 2
  • xiaojianwen
    2023年5月14日 12:01
    本人已解决,添加该参数,需要关闭本机的所有chrome浏览器窗口,否则会报错。 建议是使用其他浏览器打开流马平台,再执行用例
    0 0