我是WebdriverIO和Mocha的新手,我写了2个测试来检查我们的Web应用程序。
我想在运行第一个测试后关闭浏览器并再次登录。 当我使用browser.close()
时,我得到一个错误,browser.close()
不是一个函数,基本上第二个测试在浏览器打开的第一个测试之后立即运行。
有没有办法在摩卡测试后关闭浏览器?
describe('Verify that a signed-in user can get to the page', () => {
it('Title assertion ', () => {
const viUrl = 'https://buyermanage.com/bmgt/lock?useMock=pre.json';
signInPage.signIn('rich221', 'password', viUrl);
assert.equal(preApp.getTitle(), 'Pre-App', 'Title Mismatch');
});
});
describe("Verify that a not signed-in user can't get to the page and is redirected to login page", () => {
it('Title assertion ', () => {
const viUrl = 'https://buyermanage.com/bmgt/lock?useMock=pre.json';
assert.equal(preApp.getTitle(), 'Pre-App', 'Title Mismatch');
});
});
尝试使用browser.reloadSession()
:
after(() => {
// Start a new session for every 'locale' (wipe browser cache):
browser.reloadSession();
});
在您的特定示例中,您需要在afterEach()
钩子中使用它,并将describes
分别包装在父describe
块中的it
语句(取决于您的测试套件要求(:
describe('The world is your oister', () => {
describe('Verify that a signed-in user can get to the page', () => {
it('Title assertion ', () => {
// bla bla bla
});
});
describe("Verify that a not signed-in user can't get to the page and is redirected to login page", () => {
it('Title assertion ', () => {
// bla bla bla
});
});
afterEach(() => {
browser.reloadSession();
});
});