我有这样的代码:
it('should go to summary page without sending the order', async () => {
stepExecutor.startTimer();
// redirects, rather than checking logging
await stepExecutor.executeStep(loginWithCustomer, {
name: 'loginWithCustomer',
description: 'Page: login'
});
//
await stepExecutor.executeStep(selectFirstSubscription, {
name: 'selectFirstSubscription',
description: 'Page: abo first'
});
});
async function loginWithCustomer() {
const page = createLoginPage(browser.params.space);
await page.navigateTo(browser.params.login.url);
await page.enterLogin(browser.params.login.username, browser.params.login.password);
await page.redirect(`${browser.baseUrl}${ABO_FIRST_URI}`);
}
async function selectFirstSubscription() {
const page = new AboFirstPage();
await page.closeCookieNotification();
await page.selectFirstSubscription();
}
export class AboFirstPage {
async selectFirstSubscription() {
await element(by.css('.button--primary')).click();
}
}
它给我暴露了一个错误:
- Failed: No element found using locator: By(css selector, .button--primary)
Executed 1 of 1 spec (1 FAILED) in 5 secs.
[18:04:59] I/launcher - 0 instance(s) of WebDriver still running
[18:04:59] I/launcher - chrome #01 failed 1 test(s)
[18:04:59] I/launcher - overall: 1 failed spec(s)
[18:04:59] E/launcher - Process exited with error code 1
但是在它重定向到(函数loginWithCustomer)的页面上,会出现这样的选择器。 和element(by.css('。button--primary'))返回一个对象: 这段代码有什么问题?
答案 0 :(得分:1)
让我们检查等待的问题。将sleep
添加到此函数:
async function selectFirstSubscription() {
const page = new AboFirstPage();
await page.closeCookieNotification();
await browser.sleep(5000);
await page.selectFirstSubscription();
}
如果它可以工作,那么您有等待的问题,在单击元素之前,应添加显式的服务员。例如await ExpectedConditions.elementToBeClickable(element)