2012-01-13 5 views
1

webdriverを使用し、gwtを使用して構築されたアプリケーションをテストします。まず要素が存在すると主張したい。この要素は動的に読み込まれ、テストするのは簡単ではありません。しかし、私は要素がもはや存在しなくなると主張する必要があります。それはdomの中にもう存在しません。これに対する私の最初のアプローチは、ExpectedConditionを作成し、その要素がDOMから正常に削除されたことを確認するために、つまり アサート要素が存在しなくなった

 ExpectedCondition<Boolean> e = new ExpectedCondition<Boolean>() { 
     public Boolean apply(WebDriver d) { 
      return d.findElements(By.cssSelector(someCSSpath)).size() == 0; 
    }}; 

    WebDriverWait wait = new WebDriverWait(driver, 15); 
    wait.until(e); 

I would have expected that would have waited for 15 seconds for the element to disappear from the dom, I would expected that it would poll every 500 milis. I would expect that at every poll the bool would be false as the element would be found until such time as it disappears and at which point the condition becomes true. What I find in my output is that indeed it polls every 500 milis however once the condition becomes true I actually wait for an entire minute before moving onto the next step. This seems incorrect behavior, am I missing something? Any suggestions?

+0

[WebDriverWaitのJavaDoc] 1つは長いと秒です。 – Kilthorn

+0

Implicit waitが指定されていますか? yesの場合、findElements()は要素が少なくとも1回は(暗黙的に待機している間)待機するため、この条件をオフにする必要があります。 –

答えて

0

Try to use : ExpectedConditions.stalenessOf(..)という条件を待つことです。私のために働く。

0

"implicitlyWait"を60秒に設定しましたか?

driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS); 

オブジェクトが消えると、「findElements」メソッドが返されるまでに60秒待つことになります。

"wait.until(e);を実行する前に" implicitlyWait "を0に設定することをお勧めします。メソッドを呼び出し、60秒に戻します。

0

WebElementにハンドルがある場合は、これを使用できます。 (http://selenium.googlecode.com/svn/trunk/docs/api/java/index.html)この特定のコンストラクタは、2つのパラメータを有し、第二DOC当たり

new WebDriverWait(driver, 2).until(ExpectedConditions.stalenessOf(webElement));

関連する問題