使用ChromeOptions opt.add_argument 添加参数方式,使用本地浏览器缓存执行用例报错
<h3><span style="font-weight: bold;">操作步骤: </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> <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> </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)
分享
相关标签:
注意:本文归作者所有,未经作者允许,不得转载