org.openqa.selenium.WebDriverException:未知错误:Chrome无法启动:Github action runner ubuntu-latest异常退出错误

k7fdbhmy  于 2023-06-19  发布在  Go
关注(0)|答案(1)|浏览(120)

对于我在Github Actions中的selenium自动化测试,在我的测试设置中,我试图打开FireFox驱动程序。代码如下所示。

System.setProperty("webdriver.gecko.driver","Drivers/geckodriver");          
                
FirefoxOptions options = new FirefoxOptions();
options.setHeadless(true);
          
driver = new FirefoxDriver(options);             
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

上面的代码运行良好。问题是我有两个Github账户。代码在其中一个Github帐户中工作没有任何问题,但在另一个Github帐户中相同的代码失败。
下面是我得到的例外:

java.lang.IllegalStateException: Can't start Web Driver
        at src.test.java.tests.LoginTest.setup(LoginTest.java:86)

        Caused by:
        org.openqa.selenium.WebDriverException: Cannot find firefox binary in PATH. Make sure firefox is installed. OS appears to be: LINUX
        Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
        System info: host: 'f559711d91c1', ip: '172.18.0.2', os.name: 'Linux', os.arch: 'amd64', os.version: '5.11.0-1025-azure', java.version: '1.8.0_282'
        Driver info: driver.version: FirefoxDriver
            at org.openqa.selenium.firefox.FirefoxBinary.<init>(FirefoxBinary.java:100)
            at java.util.Optional.orElseGet(Optional.java:267)
            at org.openqa.selenium.firefox.FirefoxOptions.getBinary(FirefoxOptions.java:216)
            at org.openqa.selenium.firefox.FirefoxDriver.toExecutor(FirefoxDriver.java:187)
            at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:147)
            at src.test.java.tests.LoginTest.setup(LoginTest.java:80)

我尝试了Firefox和Chrome驱动程序,但两个选项都失败了。
对于chrome驱动程序,我尝试添加以下参数,但没有一个选项适用于chrome。

options.setBinary("Drivers/chromedriver");
options.addArguments("--no-sandbox");
options.addArguments("--headless");
options.addArguments("--whitelisted-ips");
options.setExperimentalOption("useAutomationExtension", false);
options.addArguments("--disable-infobars");
options.addArguments("--disable-dev-shm-usage");

以下异常不断发生

setup FAILED
    java.lang.IllegalStateException: Can't start Web Driver
        at src.test.java.tests.LoginTest.setup(LoginTest.java:86)

        Caused by:
        org.openqa.selenium.WebDriverException: unknown error: Chrome failed to start: exited abnormally.
          (unknown error: DevToolsActivePort file doesn't exist)
          (The process started from chrome location Drivers/chromedriver is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
        Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
        System info: host: '27c5f10fefbb', ip: '172.18.0.2', os.name: 'Linux', os.arch: 'amd64', os.version: '5.11.0-1025-azure', java.version: '1.8.0_282'
        Driver info: driver.version: ChromeDriver
3gtaxfhh

3gtaxfhh1#

此错误消息...

setup FAILED
    java.lang.IllegalStateException: Can't start Web Driver
    at src.test.java.tests.LoginTest.setup(LoginTest.java:86)

    Caused by:
    org.openqa.selenium.WebDriverException: unknown error: Chrome failed to start: exited abnormally.
      (unknown error: DevToolsActivePort file doesn't exist)
      (The process started from chrome location Drivers/chromedriver is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

...意味着ChromeDriver无法启动/产生新的 * 浏览上下文 *,即google-chrome会话。
你的主要问题似乎是setBinary()方法:

options.setBinary(new File("/path/to/chrome"));

而不是ChromeDriver,您需要传递 Google Chrome 可执行文件的绝对位置。

解决方案

实际上,您的代码行将是:

options.setBinary("/path/to/chrome");

相关问题