1

私がまとめたダーツWebアプリケーションでいくつかのテストを行っていました。私は標準でpub buildとそれを実行して、サーバーを得るために単純なpython -m SimpleHTTPServerをしました。驚くばかり。両方のブラウザでlocalhost:8000にアクセスできます。Firefoxのドライバが失敗し、到達不能なエラーが発生する

私は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(); 
} 

あなたはそれが非常に簡単です見ることができます。また、私はいくつかの印刷ステートメントがあることがわかります。これらの印刷ステートメントは、コンソール出力に表示されます。

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")); 

//ドライバを:

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 
+0

実際にはインラインで実行できないコードには、コードスニップ機能を使用しないでください。 –

+0

私はそれを使っていましたが、 'driver.navigate()。to(...)'や 'driver.getTitle()' asyncのようなメソッドではありません。この場合、 'async' /' await'を使用して、次のコマンドが送信される前に呼び出しが完了するのを待つことができます。 –

+0

私は実際にJavaコードが非同期/待望のキーワードのペアを持っていたことを知りませんでした。しかし、コード自体はJavaでした。私はキーワードを確認するために探しています – Fallenreaper

答えて

0

これを解決するには、私は次のことをやった:私はちょうど私が中止と

がエラーUnreachableBrowserExceptionを得ている理由はわからないんだけど。閉じる(); // driver.quit(); }

最初は、@AfterClassのtry-catchなしで実行し、すべてのタスクを正しく実行しましたが、終了時に失敗しました。私は終了をテストしていないので、今度はMozillaが必要に応じて発砲しているように見えるので、私はそれを抑えるためにtry-catchを置いています。

私がテストするクラスを実行すると、テストケースドライバが最初に配置されます。私はテストする機能が必要なので、テストを自動化したくありませんでした。私は後でこれを更新することができます。

Afterクラスでは、私はクリーンアップを実行し、開いていたすべてのドライバを閉じます。 1つの欠点があります。テストがすべて完了するまで、すべてのドライバは開いたままです。私はこれをやりたいとは思っていませんでしたが、私は実際の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")); 
} 

私は、ドライバを閉じて終了したいので、同じ範囲。そうすれば、ブラウザをシャットダウンするテストケースはなく、スイート全体を実行し、その機能で完了したときに閉じることもできます。

+0

あなたのバージョンのFirefoxと互換性のあるセレンのバージョンを使用していることを確認してください。それらの重要な詳細を質問から外しました。回避策では何も修正されません。 –

+0

右、申し訳ありません。 SeleniumとFirefoxのバージョンはそれぞれ3.0.0-beta3と47.0.1です。 – Fallenreaper

関連する問題