2016-07-20 4 views
1

ステータスが特定の「終了」ステータスに変わるまで待機するセレンでアクションを実行しようとしています。セレンの条件付き中間待機アクション

概念的には、このように擬似コードに配置することができる。

public boolean waitForActionToComplete(long maxTimeoutInSeconds, int repeatTimeInSeconds, Callable<T> action, Callable<T> condition) { 
    long startTime = 0; 
    while (startTime < maxTimeoutInSeconds) 
     perform <action>;     // e.g., click on a "Refresh" button to refresh the results 
     boolean done = verify <condition>; // e.g., check whether the job status is "Done" 
     if (done)   
      return true;     // if done, then exit with TRUE 
     else 
      Thread.sleep(repeatTimeInSeconds); 
    end while; 

    return false;       // status still not complete, timeout gracefully 
} 

この方法は、おそらくExpectedConditionとWebdriverWait/FluentWaitと幾分簡単な方法で実現することができます。しかし、フレームワークの特定の制約のため、私はそのような方法を正確に実装して使用することはできません。これは、(このメソッドのシグネチャを持つ枠組みの中でインタフェースを実装)として、上記の方法を実施しなければならないであろう。

public void execute(final WebDriver webDriver, String... parameters) { 
// implementation here 
} 

誰がどのように上記の指定された形式で変換方法を教えすることはできますか?

+0

ホープ://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/support/ui/WebDriverWait.html)および[FluentWait](https://seleniumhq.github.io/selenium/docs/ api/java/org/openqa/selenium/support/ui/FluentWait.html)。 – JeffC

+0

ありがとうJeffC。それは有り難いです。それは理にかなっている。私は上記の完全な問題文を持っていないと思った。私は今それを完了しました。 – naspras

+0

あなたはFluentWaitで説明したことを引き続き行うことができます。あなたは 'verify 'が何であれ、それを自分で実装しなければなりません。 – JeffC

答えて

1

ステータスが特定の「完了」ステータスに変わるまで待つことになるSeleniumでアクションを実行しようとしています。

これは、単に以下のように独自のカスタムメソッドwaitForActionToCompleteを作成insteadof ExpectedConditions.textToBePresentInElementLocatedWebDriverWaitを使用して達成することができます -

WebDriverWait wait = new WebDriverWait(driver, 30); 
wait.until(ExpectedConditions.textToBePresentInElementLocated(byObject, "Finished")); 

はそれができます...あなたは[WebDriverWait](HTTPSを調査する必要があります:)