2016-08-16 34 views
0

Appium 1.4.16.1を使用してAndroidの実デバイスでChromeブラウザでテストを実行すると、スイートでスローされた次の例外を処理する必要があります。私は例外がセッションが削除された後に、(10に設定された)タイムアウトのために投げられると思う。ただし、Selenium Webdriver(行wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(UILoc))))によって例外がスローされると、catchブロックを使用してキャッチされず、その後の実行がハングします。appiumセッションタイムアウトのためwebdriverがSessionNotFoundExceptionをスローする方法

デスクトップクロームブラウザで実行した場合と同じテストケースが例外をキャッチできることに注意してください。

これ以上の処理をする必要があるため、これをキャッチする方法があるかどうか教えてください。 Appiumセッションのタイムアウトを増やすことで、この状況を回避できます。しかし、私はまだ最大限を扱いたい。

Appiumタイムアウトログ

> info: --> POST /wd/hub/session/5ff4eaccea1df145b80f6df4af4c3d7b/url {"url":"http://test.com"} 
> info: JSONWP Proxy: Proxying [POST /wd/hub/session/5ff4eaccea1df145b80f6df4af4c3d7b/url] to [POST hubsession] with body: {"url":"http://test.com"} 
> info: [debug] Didn't get a new command in 10 secs, shutting down... 
> info: Shutting down appium session 
> info: Chromedriver: Changed state to 'stopping' 
> info: JSONWP Proxy: Proxying [DELETE /] to [DELETE hubsession] with no body 
> info: JSONWP Proxy: Got response with status 200: {"sessionId":"5ff4eaccea1df145b80f6df4af4c3d7b","status":0,"value":null} 
> info: JSONWP Proxy: Replacing sessionId 5ff4eaccea1df145b80f6df4af4c3d7b with 5ff4eaccea1df145b80f6df4af4c3d7b 
> info: <-- POST /wd/hub/session/5ff4eaccea1df145b80f6df4af4c3d7b/url 200 110858.244 ms - 72 
> info: --> POST /wd/hub/session/5ff4eaccea1df145b80f6df4af4c3d7b/element {"using":"xpath","value":"//div[@id='form-1010']"} 
> info: JSONWP Proxy: Proxying [POST /wd/hub/session/5ff4eaccea1df145b80f6df4af4c3d7b/element] to [POST hubsession] with body: {"using":"xpath","value":"//div[@id='form-1010']"} 
> info: JSONWP Proxy: Got response with status 200: "{\"sessionId\":\"5ff4eaccea1df145b80f6df4af4c3d7b\",\"status\":0,\"value\":null}" 
> info: JSONWP Proxy: Got response with status 200: {"sessionId":"","status":6,"value":{"message":"no such session\n (Driver info: chromedriver=2.23.409699 (49b0fa931cda1caad0ae15b7d1b68004acd05129),platform=Windows NT 10.0.10586 x86_64)"}} 
> info: <-- POST /wd/hub/session/5ff4eaccea1df145b80f6df4af4c3d7b/element 200 743.048 ms - 189 
> info: Chromedriver: Changed state to 'stopped' 
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"shutdown"} 
> info: [debug] [BOOTSTRAP] [debug] Got command of type SHUTDOWN 
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":"OK, shutting down","status":0} 
> info: [debug] [BOOTSTRAP] [debug] Closed client connection 

webdriverを例外ログ

Aug 17, 2016 12:49:44 AM org.openqa.selenium.support.ui.ExpectedConditions findElement 
WARNING: WebDriverException thrown by findElement(By.xpath: //div[@id='form-1010']) 
org.openqa.selenium.remote.SessionNotFoundException: no such session 
    (Driver info: chromedriver=2.23.409699 (49b0fa931cda1caad0ae15b7d1b68004acd05129),platform=Windows NT 10.0.10586 x86_64) (WARNING: The server did not provide any stacktrace information) 
Command duration or timeout: 753 milliseconds 
Build info: version: '2.53.0', revision: '35ae25b', time: '2016-03-15 17:00:58' 
System info: host: 'Pune832', ip: '10.10.148.44', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_60' 
Driver info: org.openqa.selenium.remote.RemoteWebDriver 
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, chrome={chromedriverVersion=2.23.409699 (49b0fa931cda1caad0ae15b7d1b68004acd05129)}, takesHeapSnapshot=true, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=true, version=52.0.2743.98, platform=ANDROID, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}] 
Session ID: 5ff4eaccea1df145b80f6df4af4c3d7b 
    *** Element info: {Using=xpath, value=//div[@id='form-1010']} 
    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:206) 
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158) 
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678) 
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:363) 
    at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:500) 
    at org.openqa.selenium.By$ByXPath.findElement(By.java:361) 
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:355) 
    at org.openqa.selenium.support.ui.ExpectedConditions.findElement(ExpectedConditions.java:899) 
    at org.openqa.selenium.support.ui.ExpectedConditions.access$0(ExpectedConditions.java:897) 
    at org.openqa.selenium.support.ui.ExpectedConditions$6.apply(ExpectedConditions.java:181) 
    at org.openqa.selenium.support.ui.ExpectedConditions$6.apply(ExpectedConditions.java:1) 
    at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:238) 

答えて

0

与えられたXPathを使用して要素を見つけることができません。 ***要素情報:あなたはロケータとしてIDを使用しているので、私は以下のコードを使用することをお勧め

{=のxpath、値= // divの[ID = 'フォーム-1010' @]を使用} -

driver.findElements(By.id("form-1010")); 

以下のコードを使用して、要素が存在するかどうかを確認します。要素が存在しない場合は、エラーログを取得します。

protected boolean isElementPresent(By by) throws IOException { 
    boolean isElement = false; 
    try 
    { 
     if (driver.findElement(by) != null) 
     { 
      isElement = true; 
      return isElement; 
     } 
    } 
    catch(Exception e) 
    { 
     System.out.println(e); 
     System.out.println("Element not found"); 
     isElement = false; 
     return isElement; 
    } 
    return isElement; 
} 
+0

私が探しているのは、上記のSessionNotFoundException(appiumがセッションを削除するとき)によって引き起こされるこの例外をキャッチする方法です。このためにtry/catchブロックを使用してもキャプチャされません。 – Monty

+0

ドライバーを静的ドライバーとして定義し、ヌルかどうかを確認します。ドライバがnullの場合、appiumセッションが実行されていないことを意味します。 – Suman

0

appiumサーバーの起動時に60秒を長くしてください。 Timeoutはappiumサーバーに引数として渡すことができます。

--command-timeout 60

すべてのセッションに使用するサーバーのデフォルトのコマンドタイムアウト。まだnewCommandTimeoutキャップでオーバーライドされるでしょう。

関連する問題