1

我是 WebdriverIO 和 Mocha 的新手,我写了 2 个测试来检查我们的网络应用程序。

在运行第一个测试后,我想关闭浏览器并再次登录。当我使用时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');
  });
});
4

1 回答 1

1

尝试使用browser.reloadSession()

after(() => {
    // Start a new session for every 'locale' (wipe browser cache):
    browser.reloadSession();
});

在您的特定示例中,您需要在afterEach()钩子中使用它,并describes分别将it语句(取决于您的测试套件要求)包装在父describe块中:

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();
  });
});
于 2020-06-16T10:09:11.070 回答