代码的最后一步因 Assertion 错误而失败,因为实际值仍然是LoginPage,我猜是因为该步骤在浏览器实际重定向到HomePage之前完成。
我尝试使用browser.sleep(10000)
and browser.wait()
,但它们对我不起作用。处理此类问题的正确方法是什么?
import {browser, by, protractor} from 'protractor';
import { ClientPage } from '../pages/offerScreenPage';
import {CallbackStepDefinition, defineSupportCode} from 'cucumber';
import {By} from "selenium-webdriver";
import {Events} from "../pages/Event";
let chai = require('chai').use(require('chai-as-promised'));
let expect = chai.expect;
defineSupportCode(function ({ Given, When, Then}) {
let client: ClientPage = new ClientPage();
Given(/^User is in Login Page $/, async () => {
await expect(browser.getTitle()).to.eventually.equal('LoginPage');
});
When(/^User enters credentials$/, async () => {
await client.userId.sendKeys("abc123");
await client.password.sendKeys("passwod");
});
When(/^User clicks the submit button$/, async () => {
await client.submit.click();
});
Then(/^User is redirected to a new page$/, async () => {
await expect(browser.getTitle()).to.eventually.equal('HomePage');
});
});