2017-01-10 113 views
1

這是我的塊,其中包含element.element(by.model("$ctrl.benchmark.name")); Dom不存在。它給了我錯誤,元素不在頁面上,但仍然執行所有代碼行。如果以上通過則我只要按順序處理然後去下一個。我如何處理量角器中的這些類型的問題。如何處理量角器測試,以按順序運行

it("Test BenchMark",function(){ 
    browser.getTitle().then(function (name) { 
     console.log(name); 

     browser.sleep(2000); 
     element(by.linkText("Manage Benchmarks")).click(); 
     browser.sleep(4000) 


     //element(by.xpath("//main[@class='ng-scope']//a[text()='Create Benchmark']")).click(); 
     console.log("megha"); 
     element(by.model("$ctrl.benchmark.name")).sendKeys("bench"); 
     element(by.buttonText("Save")).click(); 
     console.log(megha); 
     element(by.xpath("//button[@class='dropdown-toggle']")).click(); 
     console.log("dropdown clicked") 

    }); 
+0

一個辦法是切換到打字稿和使用異步/等待您的每個測試 – FCin

回答

0

您期待的行爲不會被量角器處理,它會通過測試框架(例如:Jasmine)。但是

"Jasmine doesn't support failing early, in a single spec. The idea is to give  
    you all of the failures in case that helps figure out what is really wrong 
    in your spec" 
0

您可以使用browser.wait()結合Expected Conditions

browser.wait()阻止控制流程執行,直到承諾解決,並且預期條件都評估爲承諾。

因此,您可以使用presenceOf()和/或visibilityOf()

var EC = protractor.ExpectedConditions; 
var el = element(by.model("$ctrl.benchmark.name")); 
var present = EC.presenceOf(el); // wait for it to be added to DOM 
var visible = EC.visibilityOf(el); // wait for it to be visible on page 
browser.wait(EC.and(present, visible), 10000); // wait maximum of 10 seconds 
// rest of code 
+0

'browser.wait()'返回一個承諾,所以爲了以後寫代碼,你需要使用'。然後()'。隨着許多等待,它變得非常嵌套。 – FCin

+0

@FCin你不需要'.then()',承諾是滿足預期條件 – Gunderson

+0

但是你必須使用'.then()'來解決它以便繼續測試。我正在談論的情況是,你有'browser.wait(EC.and(present,visible),10000);'和下一行是'console.log('abc');'。 Console.log將在'browser.wait'完成之前執行,除非您使用'.then()' – FCin

相關問題