Firefox 浏览器打开一秒后关闭,忽略场景

Firefox Browser Closes One Second After Opening, Ignoring Scenarios

我使用 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: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure. Build info: version: '3.4.0', revision: 'unknown', time: 'unknown' System info: host: 'WS00MU016', ip: '', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '9.0.1' Driver info: driver.version: FirefoxDriver

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

您可以在下方找到推荐的版本。我看到您的 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(及更高版本)

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