我正在尝试创建一个简单的测试,只需打开页面并验证其标题。我认为这不能再简单了,但是...我的测试在当前打开的Chrome浏览器中打开了一个新标签,并且在driver.get(myUrl);
上失败,因为org.openqa.selenium.NoSuchSessionException
我试过升级和降级chromedriver和升级降级selenium,但到目前为止没有成功。目前我正在使用selenium-java 3.3.1,chromedriver 2.28和chrome 57.0.2987.98。任何帮助都很感谢。
额外的问题,上次我使用chromedriver它打开了一个新的浏览器窗口,有什么办法回到那个吗?我更喜欢我的测试在一个新的窗口,而不是一个新的标签。
public class MyExampleTest {
private String baseUrl;
private WebDriver driver;
@Before
public void openBrowser() {
baseUrl = "http://myurl/";
System.setProperty("webdriver.chrome.driver", "C:\\Projects\\chromedriver.exe");
driver = new ChromeDriver();
driver.get(baseUrl);
}
@Test
public void pageTitleAfterSearchShouldBeThere() throws IOException {
assertEquals("The page title should be this at the start of the test.", "my title", driver.getTitle());
}
}
堆栈跟踪:
org.openqa.selenium.NoSuchSessionException: no such session
(Driver info: chromedriver=2.28.455520 (cc17746adff54984afff480136733114c6b3704b),platform=Windows NT 6.1.7601 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 13 milliseconds
Build info: version: '3.3.1', revision: '5234b325d5', time: '2017-03-10 09:10:29 +0000'
System info: host: 'XXXXXXXXXXXXXXX', ip: 'xxx.xxx.xxx.xx', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_121'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{message=unknown error: Chrome failed to start: crashed
(Driver info: chromedriver=2.28.455520 (cc17746adff54984afff480136733114c6b3704b),platform=Windows NT 6.1.7601 SP1 x86_64), platform=ANY}]
Session ID: 359ce80c1b82e53fffae055451228404
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:216)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:168)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:638)
at org.openqa.selenium.remote.RemoteWebDriver.get(RemoteWebDriver.java:325)
at ec_selenium.CapExampleTest.openBrowser(CapExampleTest.java:58)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.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.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
3条答案
按热度按时间pxiryf3j1#
这是因为不匹配的chromedriver版本和兼容的webdriver版本。要么改变它的任何一个或采取两个最新的。这对我工作!
c3frrgcw2#
您需要检查chrome驱动程序下载页面https://chromedriver.chromium.org/downloads
上面写着兼容性......另外,看看这里有一个兼容的驱动程序n浏览器https://stackoverflow.com/a/55266105/6305768的列表
7fhtutme3#
你可能搞砸了
imports
。试试下面的代码,对我来说很好。这将打开一个
new window
每次不是一个新的标签在已经打开的chrome浏览器。