在测试规范中,我需要单击主页上的按钮,然后等待完全加载的页面。该按钮只被点击一次,当我重新运行规范它失败,因为量角器无法到达element(by.tagName('app-banner')
上的嵌套元素的末尾
it('should click a button', async () => {
const EC = protractor.ExpectedConditions;
page.login().then(() => {
browser.wait(element(by.id('Body')).element(by.tagName('app-root')).isDisplayed, 5000).
then(async () => {
browser.wait(await element(by.tagName('app-root')).element(by.tagName('app-banner')).isDisplayed, 5000).
then(async () => {
await element(by.tagName('app-root')).element(by.tagName('app-banner')).
element(by.id('topbar')).element(by.id('user-display')).click();
});
});
});
});
- HTML层次结构
<app-home>
<div _ngcontent-c1 class=”layout-wrapper”>
<app-banner>
<div _ngcontent-c3 id=”topbar”>
<a id=”user-display”>
<bar-switchuser>
<span>
<p-dropdown>
</p-dropdown>
</span>
</bar-switchuser>
</a>
</div>
<app-banner>
</div>
您已定义ExpectedConditions
但不使用它。为什么?用它代替isDisplayed
:
await browser.wait(ExpectedConditions.visibilityOf(element(by.id('Body')).element(by.tagName('app-root')), 5000, "Element is not visible in 5 sec")