gpt4 book ai didi

java - Firefox 驱动程序失败并出现无法访问的错误

转载 作者:太空宇宙 更新时间:2023-11-04 12:12:09 25 4
gpt4 key购买 nike

正在使用我组装的 dart Web 应用程序进行一些测试。我按照标准使用 pub build 运行它,然后执行一个简单的 python -m SimpleHTTPServer 来启动服务器。惊人的。可以在两种浏览器上访问 localhost:8000

然后我进入我的 Java 应用程序来运行一些 Selenium 测试。简单如运行应用程序。它在 Chrome 上成功,但在 Firefox 上失败。我已经针对具有不同标题的其他页面进行了测试。它工作得很好并且通过了两项测试,但是与此相关的某些东西似乎不起作用。

当代码执行时,我看到它打开两个浏览器并进行相应的导航。

Java 代码:

@Test
public void testWithChrome(){
WebDriver driver = new ChromeDriver(DesiredCapabilities.chrome());
testSuite(driver);
}

@Test
public void testWithFirefox(){
WebDriver driver = new FirefoxDriver(DesiredCapabilities.firefox());
testSuite(driver);
}

public void testSuite(WebDriver driver){
driver.navigate().to("http://localhost:8000/web/");
Assert.assertTrue("title should start with Polymer Todo App",
driver.getTitle().startsWith("Polymer Todo App"));

System.out.printf("This is a Test: '%s'\n", driver.getTitle());
System.out.println(driver.getTitle().startsWith("Polymer Todo App"));

driver.close();
driver.quit();
}

你可以看到它非常简单。您还可以看到我有一些打印语句。这些打印语句显示在控制台输出中。我只是不确定为什么会出现中止和 UnreachableBrowserException

错误:

Sep 29, 2016 10:07:44 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Attempting bi-dialect session, assuming Postel's Law holds true on the remote end
1475158066440 Marionette INFO Listening on port 55006
Sep 29, 2016 10:07:51 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
JavaScript warning: https://normandy.cdn.mozilla.net/static/bundles/selfrepair-c889f52c56e4df3156a1.f5e450e97071.js, line 7: mutating the [[Prototype]] of an object will cause your code to run very slowly; instead create the object with the correct initial [[Prototype]] value using Object.create
JavaScript warning: http://localhost:8000/web/, line 308: mutating the [[Prototype]] of an object will cause your code to run very slowly; instead create the object with the correct initial [[Prototype]] value using Object.create
JavaScript warning: http://localhost:8000/web/index.bootstrap.initialize.dart.js, line 1: unreachable code after return statement
JavaScript warning: http://localhost:8000/web/index.bootstrap.initialize.dart.js line 3207 > Function, line 1: unreachable code after return statement
JavaScript warning: http://localhost:8000/web/index.bootstrap.initialize.dart.js, line 1: unreachable code after return statement
JavaScript warning: http://localhost:8000/web/index.bootstrap.initialize.dart.js line 3213 > Function, line 1: unreachable code after return statement
JavaScript warning: http://localhost:8000/web/index.bootstrap.initialize.dart.js, line 1: unreachable code after return statement
JavaScript warning: http://localhost:8000/web/index.bootstrap.initialize.dart.js line 3213 > Function, line 1: unreachable code after return statement
JavaScript warning: http://localhost:8000/web/index.bootstrap.initialize.dart.js, line 1: unreachable code after return statement
JavaScript warning: http://localhost:8000/web/index.bootstrap.initialize.dart.js line 3213 > Function, line 1: unreachable code after return statement
JavaScript warning: http://localhost:8000/web/index.bootstrap.initialize.dart.js, line 1: unreachable code after return statement
JavaScript warning: http://localhost:8000/web/index.bootstrap.initialize.dart.js, line 1: unreachable code after return statement
JavaScript warning: http://localhost:8000/web/index.bootstrap.initialize.dart.js, line 1: unreachable code after return statement
JavaScript warning: http://localhost:8000/web/index.bootstrap.initialize.dart.js line 3213 > Function, line 1: unreachable code after return statement
JavaScript warning: http://localhost:8000/web/index.bootstrap.initialize.dart.js, line 1: unreachable code after return statement
JavaScript warning: http://localhost:8000/web/index.bootstrap.initialize.dart.js line 3213 > Function, line 1: unreachable code after return statement
JavaScript warning: http://localhost:8000/web/index.bootstrap.initialize.dart.js, line 1: unreachable code after return statement
JavaScript warning: http://localhost:8000/web/index.bootstrap.initialize.dart.js line 3213 > Function, line 1: unreachable code after return statement
JavaScript warning: http://localhost:8000/web/index.bootstrap.initialize.dart.js, line 1: unreachable code after return statement
JavaScript warning: http://localhost:8000/web/index.bootstrap.initialize.dart.js line 3213 > Function, line 1: unreachable code after return statement
This is a Test: 'Polymer Todo App'
true
[Child 7828] ###!!! ABORT: Aborting on channel error.: file c:/builds/moz2_slave/m-rel-w32-00000000000000000000/build/src/ipc/glue/MessageChannel.cpp, line 2027

org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died.
Build info: version: 'unknown', revision: 'c7b525d', time: '2016-09-01 14:57:44 -0700'
System info: host: 'CHI-CS-55DXX52', ip: '10.60.68.15', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_77'
Driver info: driver.version: RemoteWebDriver
Capabilities [{rotatable=false, raisesAccessibilityExceptions=false, appBuildId=20160623154057, version=, platform=XP, proxy={}, command_id=1, specificationLevel=0, acceptSslCerts=false, browserVersion=47.0.1, platformVersion=6.1, XULappId={ec8030f7-c20a-464f-9b0e-13a3a9e97384}, browserName=Firefox, takesScreenshot=true, takesElementScreenshot=true, platformName=Windows_NT, device=desktop}]
Session ID: 7431bbcb-b619-48dc-b4ca-ccc14eef1ce8

at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:618)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:654)
at org.openqa.selenium.remote.RemoteWebDriver.quit(RemoteWebDriver.java:493)
at com.polymerdart.webdriver.MyFirstTest.testSuite(MyFirstTest.java:36)
at com.polymerdart.webdriver.MyFirstTest.testWithFirefox(MyFirstTest.java:24)
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:498)
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.InvokeMethod.evaluate(InvokeMethod.java:17)
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.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:117)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:262)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:84)
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:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Caused by: java.lang.IllegalStateException: UnixUtils may not be used on Windows
at org.openqa.selenium.os.ProcessUtils.getProcessId(ProcessUtils.java:188)
at org.openqa.selenium.os.UnixProcess$SeleniumWatchDog.getPID(UnixProcess.java:222)
at org.openqa.selenium.os.UnixProcess$SeleniumWatchDog.access$300(UnixProcess.java:201)
at org.openqa.selenium.os.UnixProcess.destroy(UnixProcess.java:132)
at org.openqa.selenium.os.CommandLine.destroy(CommandLine.java:155)
at org.openqa.selenium.remote.service.DriverService.stop(DriverService.java:196)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:94)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:597)
... 31 more

最佳答案

为了解决这个问题,我执行了以下操作:

static Map<String, WebDriver> driverMap = new HashMap<String,WebDriver>();

@BeforeClass
public static void initDriverMap(){
driverMap.put("chrome", new ChromeDriver(DesiredCapabilities.chrome()));
driverMap.put("firefox", new FirefoxDriver(DesiredCapabilities.firefox()));
}

@AfterClass
public static void cleanUp(){

Iterator it = driverMap.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String,WebDriver> pair = (Map.Entry)it.next();
pair.getValue().close();
try {
pair.getValue().quit();
}catch(Exception e){}
}
}

@Test
public void testWithChrome(){
WebDriver driver = driverMap.get("chrome");
testSuite(driver);
}

@Test
public void testWithFirefox(){
WebDriver driver = driverMap.get("firefox");
testSuite(driver);
}

public void testSuite(WebDriver driver){
driver.navigate().to("http://localhost:8000/web/");
Assert.assertTrue("title should start with Polymer Todo App",
driver.getTitle().startsWith("Polymer Todo App"));

System.out.printf("This is a Test: '%s'\n", driver.getTitle());
System.out.println(driver.getTitle().startsWith("Polymer Todo App"));

//driver.close();//驱动程序.quit(); }

起初,我在 @AfterClass 中没有使用 try-catch 的情况下运行它,并且它正确执行了所有任务,但随后退出失败。由于我没有测试退出,所以我在它周围放置了一个 try-catch 来抑制它,因为现在 Mozilla 似乎正在根据需要触发。

本质上,当我运行该类进行测试时,它会首先放入测试用例驱动程序。我不想自动化测试,因为我需要测试功能。我可以稍后更新。

在课后,我会运行清理并关闭所有打开的驱动程序。有一个缺点,那就是所有驱动程序都保持开放状态,直到测试全部完成。虽然我不想这样做,但我不想在我的实际 testSuite 中放置 try-catch。

在研究了一些变体之后,我发现最好的结果是在给定时间点打开更少的浏览器,如下所示:

public void testWithChrome(){
WebDriver driver = new ChromeDriver(DesiredCapabilities.chrome());
testSuite(driver);
driver.close();
try {
driver.quit();
}catch(Exception e){
System.out.println("Driver error preventing from Quitting.");
}
}

@Test
public void testWithFirefox(){
WebDriver driver = new FirefoxDriver(DesiredCapabilities.firefox());
testSuite(driver);
driver.close();
try {
driver.quit();
}catch(Exception e){
System.out.println("Driver error preventing from Quitting.");
}
}

public void testSuite(WebDriver driver){
driver.navigate().to("http://localhost:8000/web/");
Assert.assertTrue("title should start with Polymer Todo App",
driver.getTitle().startsWith("Polymer Todo App"));

System.out.printf("This is a Test: '%s'\n", driver.getTitle());
System.out.println(driver.getTitle().startsWith("Polymer Todo App"));
}

因为我想在同一范围内关闭并退出驱动程序。这样就没有测试用例关闭浏览器,就像它运行整个套件,然后在完成该功能后关闭一样。

关于java - Firefox 驱动程序失败并出现无法访问的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39772902/

25 4 0
文章推荐: linux - 没有ssh的没有密码文件的rsync
文章推荐: javascript - 如何在鼠标进入/离开链接时显示/隐藏非子
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com