lundi 4 mars 2019

Async/await t test codes are not working in in beforeEach of TestCafe

When I tried to use beforeEach in TestCafe, a function with some test codes inside of it seems not working properly. I am using doLogin in all different fixtures and tests.

Not working

const doLogin = async (t) => {
  const login = new Login();

  await t
    .maximizeWindow()
    .typeText(login.emailInput, accounts.EMAIL_SUCCESS, { replace: true, paste: true })
    .expect(login.emailInput.value).eql(accounts.EMAIL_SUCCESS, 'check an email')
    .typeText(login.passwordInput, accounts.PASSWORD, { paste: true })
    .click(login.loginButton);
};

fixture`App > ${menuName}`
  .page`${HOST}`
  .beforeEach(async (t) => {
    // This function is called
    // but tests inside the function were not run
    doLogin(t)
  });

Working Case with a fixture

fixture`App > ${menuName}`
  .page`${HOST}`
  .beforeEach(async (t) => {
    const login = new Login();

    // But this case is working.
    await t
      .maximizeWindow()
      .typeText(login.emailInput, accounts.EMAIL_SUCCESS, { replace: true, paste: true })
      .expect(login.emailInput.value).eql(accounts.EMAIL_SUCCESS, 'check an email')
      .typeText(login.passwordInput, accounts.PASSWORD, { paste: true })
      .click(login.loginButton);
  });

Working Case with calling from a test

test(`show all ${menuName} menu's components`, async (t) => {
  // When I added a function directly into a test function then it worked.
  doLogin(t);
  // some codes

Could anyone tell me the problem in this code?

In the official document, it said At the moment test hooks run, the tested webpage is already loaded, so that you can use test actions and other test run API inside test hooks.

Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire