2017-10-02 17 views
0

私は、次のコードを持っています。上記が成功しない場合は、browser.wait(do some things);継続の約束チェーン()タイムアウト

私はこれを達成するためにいくつかの異なる方法を試してきましたが、thisに似たようなことをしていますが、まだ実際には得られていません私が探している結果

私はこれをどのように達成することができますか?

おかげ

答えて

0

EDIT:Protractor FAQによると、エラーの場合における第2の機能を実行することができます。

.then(function() { 
    return buttonClick(); 
}) 
//wrap your BEGIN-END-part into a new function like this: 
// then(function(){BEGIN-END}, function(err){failcase-execution}) 
.then(function(){ 
    // BEGIN 
    .then(function() { 
     return browser.wait(EC.elementToBeClickable(anotherButton), timeOut) 
      .then(function() { 
       anotherButton.click(); 
      }) 
    }) 
    .then(function() { 
     return browser.wait(EC.elementToBeClickable(yetAnotherButton), timeout) 
      .then(function() { 
       yetAnotherButton.click(); 
      }) 
    }) 
}, function(err){ 
    //Here is your execution in error-case. 
    browser.wait(do some things); 
}) 
.then(function() { 
    browser.wait(do some things); 
}) 

しかし私には、2つの異なるスコープをテストしようとしているように聞こえます。 これらの2つのテストは同じテストケース(it-block)内で実行する必要がありますか?以下のような

何か:

describe ("test", function(){ 
    it("executes the first part incl. Begin-End", function(){ 
     //eventually some steps to come here first. 
     .then(function() { 
      return buttonClick(); 
     }) 
     // BEGIN 
     .then(function() { 
      return browser.wait(EC.elementToBeClickable(anotherButton), timeOut) 
       .then(function() { 
        anotherButton.click(); 
       }) 
     }) 
     .then(function() { 
      return browser.wait(EC.elementToBeClickable(yetAnotherButton), timeOut) 
       .then(function() { 
        yetAnotherButton.click(); 
       }) 
     }) 
    }); 
    it("executes the second part, which resumes anyway", function(){ 
     //if necessary, repeat some of the steps from before test 
     .then(function() { 
      return buttonClick(); 
     }) 
     .then(function() { 
      browser.wait(do some things); 
     }) 
    }); 
}); 

それともあなただけ把握しようとした場合、あなたはボタンをクリックすることができれば、あなただけのtrueまたはfalseを返す別の関数にBEGIN/ENDの間のクリックを実行することができます(へのリンクされたものと同様):

側の発言として
//existing part 
.then(function() { 
    return buttonClick(); 
}) 
.then(
    bool clicksWorked = this.optionalExecution(); 
) 
.then(function() { 
    browser.wait(do some things); 
    if(!clicksWorked){console.log("Some Buttons couldn't be clicked")} 
}) 

//as separate function, which just returns either true or false 
this.optionalExecution = function() { 
    try { 
     // BEGIN 
     browser.wait(EC.elementToBeClickable(anotherButton), timeOut) 
      .then(function() { 
       anotherButton.click(); 
      }) 
     browser.wait(EC.elementToBeClickable(yetAnotherButton), timeOut) 
      .then(function() { 
       yetAnotherButton.click(); 
      }) 
     return true 
    } 
    catch (Exception e) { 
     return false 
    } 
} 

:それは私にははっきりしていないとしてあなた.then()のすべてはを参照している場合 あなたは、あなたの.then() -listにもう少しコンテキストを追加できます入力条件それらがテストケースにどのように埋め込まれているかを示します。 現在の例では、あなたの行動を.then() -blocksの範囲内に入れる必要はないようです。分度器は、.then()がなくても、同期して行ごとに実行されます。参考文献here

+0

分度器のFAQをもう一度読んで、より良い方法を考えました。編集して私の回答に追加しました: https://github.com/angular/protractor/blob/master/docs/faq.md#how-can-i-catch-errors-such-as-elementnotfound –

関連する問題