每次@Test运行两次硒测试

时间:2015-11-30 20:59:26

标签: java macos maven selenium

我在IntelliJ中设置了一个超级简单的maven项目来与Selenium一起工作。

的pom.xml

    <dependencies>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>2.48.2</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
            <type>jar</type>
        </dependency>
    </dependencies>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

测试文件:

import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class SeleniumHQTest {
    @Test
    public void testTabsExist() {
        WebDriver driver = new FirefoxDriver();
        driver.get(HomePage.googleURL);
        driver.quit();
    }
}

第一个浏览器打开google.com并关闭。然后第二个firefox打开,我收到以下错误:

org.openqa.selenium.WebDriverException: Session not found: 476bea76-a0cb-1e4f-9dcf-54dc6f16f674
Command duration or timeout: 2.98 seconds
Build info: version: '2.48.2', revision: '41bccdd10cf2c0560f637404c2d96164b67d9d67', time: '2015-10-09 13:08:06'
System info: host: 'upkarmac.usca.ibm.com', ip: '9.72.139.142', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.10.5', java.version: '1.8.0_66'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{applicationCacheEnabled=true, rotatable=false, handlesAlerts=true, databaseEnabled=true, version=38.4.0, platform=MAC, nativeEvents=false, acceptSslCerts=true, webStorageEnabled=true, locationContextEnabled=true, browserName=firefox, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: 476bea76-a0cb-1e4f-9dcf-54dc6f16f674

    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:647)
    at org.openqa.selenium.remote.RemoteWebDriver.get(RemoteWebDriver.java:311)
    at com.ibm.paq.testpaq.SeleniumHQTest.testTabsExist(SeleniumHQTest.java:13)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:117)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Caused by: org.openqa.selenium.WebDriverException: Session not found: 476bea76-a0cb-1e4f-9dcf-54dc6f16f674
Build info: version: '2.48.2', revision: '41bccdd10cf2c0560f637404c2d96164b67d9d67', time: '2015-10-09 13:08:06'
System info: host: 'upkarmac.usca.ibm.com', ip: '9.72.139.142', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.10.5', java.version: '1.8.0_66'
Driver info: driver.version: unknown
    at <anonymous class>.nsCommandProcessor.prototype.execute(file:///var/folders/ld/s22xdgzj16d2l9zs8r5x8vn80000gn/T/anonymous8756482500413886703webdriver-profile/extensions/fxdriver@googlecode.com/components/command-processor.js:12577)
    at <anonymous class>.Dispatcher.executeAs/<(file:///var/folders/ld/s22xdgzj16d2l9zs8r5x8vn80000gn/T/anonymous8756482500413886703webdriver-profile/extensions/fxdriver@googlecode.com/components/driver-component.js:9455)
    at <anonymous class>.Resource.prototype.handle(file:///var/folders/ld/s22xdgzj16d2l9zs8r5x8vn80000gn/T/anonymous8756482500413886703webdriver-profile/extensions/fxdriver@googlecode.com/components/driver-component.js:9602)
    at <anonymous class>.Dispatcher.prototype.dispatch(file:///var/folders/ld/s22xdgzj16d2l9zs8r5x8vn80000gn/T/anonymous8756482500413886703webdriver-profile/extensions/fxdriver@googlecode.com/components/driver-component.js:9549)
    at <anonymous class>.WebDriverServer/<.handle(file:///var/folders/ld/s22xdgzj16d2l9zs8r5x8vn80000gn/T/anonymous8756482500413886703webdriver-profile/extensions/fxdriver@googlecode.com/components/driver-component.js:12390)
    at <anonymous class>.createHandlerFunc/<(file:///var/folders/ld/s22xdgzj16d2l9zs8r5x8vn80000gn/T/anonymous8756482500413886703webdriver-profile/extensions/fxdriver@googlecode.com/components/httpd.js:2054)
    at <anonymous class>.ServerHandler.prototype.handleResponse(file:///var/folders/ld/s22xdgzj16d2l9zs8r5x8vn80000gn/T/anonymous8756482500413886703webdriver-profile/extensions/fxdriver@googlecode.com/components/httpd.js:2387)
    at <anonymous class>.Connection.prototype.process(file:///var/folders/ld/s22xdgzj16d2l9zs8r5x8vn80000gn/T/anonymous8756482500413886703webdriver-profile/extensions/fxdriver@googlecode.com/components/httpd.js:1223)
    at <anonymous class>.RequestReader.prototype._handleResponse(file:///var/folders/ld/s22xdgzj16d2l9zs8r5x8vn80000gn/T/anonymous8756482500413886703webdriver-profile/extensions/fxdriver@googlecode.com/components/httpd.js:1677)
    at <anonymous class>.RequestReader.prototype._processBody(file:///var/folders/ld/s22xdgzj16d2l9zs8r5x8vn80000gn/T/anonymous8756482500413886703webdriver-profile/extensions/fxdriver@googlecode.com/components/httpd.js:1525)
    at <anonymous class>.RequestReader.prototype.onInputStreamReady(file:///var/folders/ld/s22xdgzj16d2l9zs8r5x8vn80000gn/T/anonymous8756482500413886703webdriver-profile/extensions/fxdriver@googlecode.com/components/httpd.js:1393)

0 个答案:

没有答案