【问题标题】:Firefox Browser Closes One Second After Opening, Ignoring Scenarios火狐浏览器打开后一秒关闭,忽略场景
【发布时间】:2018-06-09 04:35:57
【问题描述】:

我使用 Firefox 版本 54.0.1(64 位)、Geckodriver v0.17.0-win64 和 Selenium 3.4.0,但是当我运行我的场景时,Firefox 会打开并在一秒钟后关闭。所以,我的场景被忽略了。我使用了不同版本的 Firefox、Geckodriver 和 Selenium。但没有帮助 这是我的代码:

private static WebDriver createConfiguredDriver() {

        final String driverName = TestData.getBrowser();   //BrowserType.FIREFOX
        final boolean remote = TestData.isRemoteMode();    //"webdriver.isremote";
        DesiredCapabilities desiredCapabilites = new DesiredCapabilities(driverName, "", Platform.ANY);
        desiredCapabilites.setCapability("marionette", false);
        if (remote) {
            final String host = TestData.getBrowserHost();
            final int port = TestData.getBrowserPort();
            logger.info("Remote browser host: " + host);
            logger.info("Remote browser port: " + port);
            try {
                URL remoteAddress = new URL("http", host, port, "/wd/hub");
                return new RemoteWebDriver(remoteAddress, desiredCapabilites);
            } catch (MalformedURLException mue) {
                throw new IllegalArgumentException("Failed to create remote URL using host: " + host, mue);
            }
        }
        else if (BrowserType.FIREFOX.equalsIgnoreCase(driverName)) {
            System.setProperty("webdriver.gecko.driver",
                    "src\\main\\resources\\geckodriver\\geckodriver.exe");
            logger.info("Using local FireFox WebDriver.");
//            desiredCapabilites.setCapability("firefox_binary", "C:\\Program Files\\Mozilla Firefox\\firefox.exe");
            return new FirefoxDriver(desiredCapabilites);

这是我的 pom.xml:

<dependencies>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.0</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.4.0</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium.fluent</groupId>
            <artifactId>fluent-selenium</artifactId>
            <version>1.14.5</version>
            <exclusions>
                <exclusion>
                    <groupId>org.seleniumhq.selenium</groupId>
                    <artifactId>selenium-java</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-java</artifactId>
            <scope>test</scope>
            <version>1.2.5</version>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-jvm</artifactId>
            <version>1.0.11</version>
            <type>pom</type>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-picocontainer</artifactId>
            <version>1.1.5</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>1.2.5</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest-all</artifactId>
            <version>1.3</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>gherkin</artifactId>
            <version>2.12.2</version>
            <scope>provided</scope>
        </dependency>
         </dependencies>
         <profile>
            <id>firefox</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <webdriver.driver>firefox</webdriver.driver>
            </properties>
        </profile>
         <profile>
            <id>remote</id>
            <properties>
                <webdriver.isremote>true</webdriver.isremote>
                <webdriver.host>vwbnode01</webdriver.host>
                <webdriver.port>4444</webdriver.port>
            </properties>
        </profile>
    </profiles>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.20.1</version>
                <configuration>
                    <skip>false</skip>
                    <forkCount>1</forkCount>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>2.15</version>
                <configuration>
                    <includes>
                        <include>**/*Test.java</include>
                        <include>**/Test*.java</include>
                        <include>**/*Steps.java</include>
                        <include>**/*TestRunner.java</include>
                    </includes>
                    <executions>
                    <execution>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.7.0</version>
                <configuration>
                    <source>9</source>
                    <target>9</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>2.9</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-site-plugin</artifactId>
                <version>3.2</version>
            </plugin>
        </plugins>
    </build>

我的控制台:

rg.openqa.selenium.remote.UnreachableBrowserException:无法启动新会话。可能的原因是远程服务器地址无效或浏览器启动失败。 构建信息:版本:'3.4.0',修订:'未知',时间:'未知' 系统信息:主机:'WS00MU016',ip:'',os.name:'Windows 10',os.arch:'amd64',os.version:'10.0',java.version:'9.0.1' 驱动信息:driver.version:FirefoxDriver

在 org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:658) 在 org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:250) 在 org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:236) 在 org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:137) 在 org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:191) 在 org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:108) 在 org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:137) 在 com.dods.ui.mpp.tests.runner.CucumberTestRunner.createConfiguredDriver(CucumberTestRunner.java:60) 在 com.dods.ui.mpp.tests.runner.CucumberTestRunner.init(CucumberTestRunner.java:84) 在 java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 在 java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 在 java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在 java.base/java.lang.reflect.Method.invoke(Method.java:564) 在 org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) 在 org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) 在 org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) 在 org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24) 在 org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27) 在 org.junit.runners.ParentRunner.run(ParentRunner.java:363) 在 cucumber.api.junit.Cucumber.run(Cucumber.java:100) 在 org.junit.runner.JUnitCore.run(JUnitCore.java:137) 在 com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68) 在 com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47) 在 com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242) 在 com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70) 引起:java.lang.NullPointerException 在 org.openqa.selenium.remote.service.DriverService.waitUntilAvailable(DriverService.java:192) 在 org.openqa.selenium.firefox.XpiDriverService.start(XpiDriverService.java:94) 在 org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:78) 在 org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:637) ... 24 更多

【问题讨论】:

  • 尝试将 selenium 升级到最新版本,看看它是否有效。我相信壁虎至少应该是 0.18
  • 我还想看看你在哪里打电话给createConfiguredDriver 以及你是如何处理驱动程序的。您是否已通过代码查看浏览器关闭的确切时间?有没有可能您在使用前不小心丢弃了它?
  • 我升级到 Selenium 3.8.1 和 Gecko 0.19 但仍然无法运行。浏览器正在打开,但无法在浏览器中获取 URL。我在控制台“org.openqa.selenium.WebDriverException: Timed out waiting 45 seconds for Firefox to start.”中有一个错误。

标签: java selenium firefox cucumber geckodriver


【解决方案1】:

您可以在下面找到推荐的版本。我看到您的 Selenium 和 Gecko 驱动程序已经升级,但是您还应该检查属性“marionette”是否设置为 true。

GeckoDriver v0.19.0:Firefox 55.0(及更高版本)和 Selenium 3.5(及更高版本)

GeckoDriver v0.18.0:Firefox 53.0(及更高版本)

GeckoDriver v0.16.0:Selenium 3.4(及更高版本)

【讨论】:

  • 没有帮助,即使属性“marionette”设置为 true。尝试了不同版本的 GeckoDriver、Firefox 和 Selenium,但浏览器打开并在一秒钟后关闭
【解决方案2】:

通过匹配解决了这个问题: GeckoDriver v0.19.0:Firefox 57.0.4(64 位)和 Selenium 3.4.0 属性“marionette”应设置为 true

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-20
    相关资源
    最近更新 更多