2017-09-27 29 views
0

我现在有在我的测试规格之一量角器下面的代码:量角器时序问题

.then(function() { 
    return button.click(); 
}) 
.then(function() { 
    return element(otherButton).isDisplayed(); 
}) 
.then(function(otherButtonIsPresent) { 
    if(otherButtonIsPresent) { 
     return browser.wait(EC.elementToBeClickable(element(otherButton)), getWaitTime()) 
      .then(function() { 
       element(otherButton).click(); 
       return element(continueButton).isPresent(); 
      }) 
    } 
}) 

当我使用Chrome使用--debug-brk--inspect标志调试,我能够通过这些检查和恢复像平常一样。当我在没有标志的情况下运行相同的测试时,测试失败并在尝试点击它之前查找otherButton期间停顿。

我想知道是否这是因为在调试过程中,我设置了断点并等待按钮显示在屏幕上,然后再尝试单击它们。

我需要确保这个元素在页面上可见之前试图点击它,并想知道是否有另一种方式,如果完成此?

谢谢

+0

尝试使用browser.wait()与ExpectedConditions沿着使的webdriver到直到某些特定条件。请参阅http://www.protractortest.org/#/api?view=ProtractorExpectedConditions。 –

回答

0

我使用的答案,因为我还不能评论。

你基本上是自己提到的:点击一个按钮后,你只是想等到下一个按钮可以点击。 因此,您的.then()函数应该从它所依赖的按钮开始。对我来说,似乎三个排队的.then()函数依赖于相同的条件,所以在你.click()第一个按钮之后,第二个.then()立即执行,而不是等待之前的.click()完成。

因此把.then()后面直接相关.click()和内前.then()功能全,这应该工作:

.then(function() { 
    element(button).click().then(function(){ 
     element(otherButton).click().then(function(){ 
      return element(continueButton).isPresent(); 
     }); 
    }); 
}); 

或者,如果你有ExpectedConitions去,你不应该需要.then() -functions。由于量角器应该管理ControlFlow,让你把它写不链接.then() -functions:

.then(function() { 
    browser.wait(EC.elementToBeClickable(element(button)), getWaitTime()); 
    element(button).click(); 
    browser.wait(EC.elementToBeClickable(element(otherButton)), getWaitTime()); 
    element(otherButton).click(); 
    browser.wait(EC.elementToBeClickable(element(continueButton)), getWaitTime()); 
    return element(continueButton).isPresent(); 
}); 

This nice post阐述了异步写了一点,但由于量角器同步执行。

作为替代的示例组合我的两个输入端,种双固定测试:

.then(function() { 
    browser.wait(EC.elementToBeClickable(element(button)), getWaitTime()); 
    element(button).click().then(function(){ 
     browser.wait(EC.elementToBeClickable(element(otherButton)), getWaitTime()); 
     element(otherButton).click().then(function(){ 
      browser.wait(EC.elementToBeClickable(element(continueButton)), getWaitTime()); 
      return element(continueButton).isPresent(); 
     }); 
    }); 
});