2016-07-04 5 views
1

分度器は、エラーメッセージがページに存在するかどうかを確認する必要があります。したがって、エラーメッセージは "alert-message"クラスまたは "fail-heading"クラスのいずれかになります。ページの表示後に要素の1つが存在するかどうかを調べる方法

私が以下のようにすると、alert-message classNameが表示されている場合にのみ成功します。しかし、時々私はclassNameを "失敗"と見なします。

var waitforele_confirmation = by.className('alert-message'); 
browser.wait(function(){return browser.driver.isElementPresent(waitforele_confirmation)}, 60000); 
expect(browser.driver.isElementPresent(waitforele_confirmation)).toBeTruthy(); 

だから私は動的にページがロードされた後に存在している要素をチェックしたいです。また、私は各要素を待っているときにbrowser.wait関数を使いたいと思います。私はちょうど理解するために以下の擬似コードを行った。

while (i<120 and !found) 
{ 
    int i=0; 
    if (element(by.className('alert-message')).isPresent()) 
    { 
    found = true; 
    } 
    else if (element(by.className('fail-heading')).isPresent()) 
    { 
    found = true; 
    } 
    else 
    { 
    browser.sleep(500); 
    } 
    i++; 
} 

分度器のplsで誰かが擬似コードを変換できますか?コードの下

答えて

1
let EC = protractor.ExpectedConditions; 
let alertMessageVisibility = EC.visibilityOf($('.alert-message')); 
let failHeadingVisibility = EC.visibilityOf($('.fail-heading')); 

browser.wait(EC.or(alertMessageVisibility, failHeadingVisibility), 60000, "Alert message or fail heading should become visible in 60 seconds, but it wasn't") 
+0

を完璧に取り組んでいます。ありがとう。 –

0

あなたが期待どおりに動作します:

var EC = protractor.ExpectedConditions; 
var alertMessageElement = element(by.className('alert-message')) 
var failHeadingElement = element(by.className('fail-heading')) 

/*browser.wait() will be keep on checking for error messages until either 
any one of the error message found or specified timeout limit reached*/ 

browser.wait(function(){ 
EC.visibilityOf(alertMessageElement).call().then(function(isAlertMessagePres 
ent){ 
    if(isAlertMessagePresnt){ 
    return true; 
    } 
}) 

EC.visibilityOf(failHeadingElement).call().then(function(isFailedHeadingPresent) { 
if(isFailedHeadingPresent){ 
    return true; 
} 
}) 
    },10000,'No error message found within specified timeout of 10 seconds  
     '); 
+0

共有いただきありがとうございます。このコードで構文エラーが発生しています。私は分度器に新しいので、構文の問題を解決できませんでした。しかし、以下の回答(xotabu4)はうまくいきます。 E /ランチャー - エラー:C:\分度器\ POC \ testcases_n_spec.js:(isPresent()){trueを返す;}場合97 リターン ^^にSyntaxError:予期しないトークンif文 –

+0

削除復帰横場合。あなたの問題のための他のオプションが必要な場合は今すぐお試しください。ありがとう –

+0

私はもう一度試してみました。以下のエラーを取得します。失敗:isPresentが定義されていません。私はisPresent()を与えようとしましたが、それでも同じエラーです。とにかく問題は解決されます。私たちはこの問題を解決することができます。 –

関連する問題