JAVA といくつかの Selenium スクリプトを使用して、Eclipse IDE でテスト ケースを作成します。
私の問題は、テストケースの継続的な実行が、selenium.waitForPageToLoad("30000") メソッドでエラー/失敗したテストを生成することがあることです。特定の条件が満たされるまでメソッドがループするという解決策を作成したので、このコードにたどり着きました。しかし、これは機能しません。
Junit Test を実行 > @Test1,2,3..n > ページがロードされない @ Test n > 次の行のコードを実行 > @Test n でテストに失敗 > ページがロードされないため、次のスクリプトを実行できないため(ページが読み込まれないため、ページに必要な要素がありません)。
これは想定されていることです: Junit テストを実行 > @Test1,2,3..n > ページが読み込まれない @ テスト n > 特定の条件が満たされるまでページが読み込まれるのを待つ (例: 要素 X がページに既に存在する) > 次の行のコードを実行 > @Test n でテストに合格
スクリプトの次の行に必要な要素が存在するまで、ページの読み込みを待機するソリューションが必要です。
このコードは機能しません。あなたの助けが必要です。ありがとう
//Wait for Page to Load until Expected Element is not Present
public void waitForPageToLoadElement(final String isElementPresent){
boolean elementBoolean;
do{
selenium.waitForPageToLoad("30000");
elementBoolean = selenium.isElementPresent(isElementPresent);
if (elementBoolean==false){
try{Thread.sleep(3000);}
catch (Exception e) {
//catch
}}
}
while(elementBoolean==false);
}
//Wait for Page to Load until Expected Text is not Present
public void waitForPageToLoadText(String isTextPresent){
boolean elementBoolean;
do{
selenium.waitForPageToLoad("30000");
elementBoolean = selenium.isTextPresent(isTextPresent);
if (elementBoolean==false){
try{Thread.sleep(3000);}
catch (Exception e) {
//catch
}}
}
while(elementBoolean==false);
}
//Opens url until Expected Element is not Present
public void openUrl(String url){
boolean userNameBoolean, passwordBoolean;
do {
selenium.open(url);
userNameBoolean = selenium.isElementPresent("id=loginForm:username");
passwordBoolean = selenium.isElementPresent("id=loginForm:password");
if (userNameBoolean==false && passwordBoolean==false){
try{Thread.sleep(3000);}
catch (Exception e) {
//catch
}}
}while (userNameBoolean==false && passwordBoolean==false);
}