【问题标题】:TestCafe Role does not return to specified fixture pageTestCafe 角色未返回指定的夹具页面
【发布时间】:2020-07-12 21:59:38
【问题描述】:

我正在尝试为 Testcafe 使用角色。当我使用角色时,它不会让我回到指定的夹具页面。文档说这是它应该如何工作,但我似乎无法让它工作。

目标:

  1. 使用角色登录
  2. 使用角色后返回 page.libraryScreen。

这是我的代码:

fixture`Library /all`.page(page.libraryScreen).beforeEach(async t => {
  await t.useRole(page.adminUser);
});

test('Search Bar', async t => {
  const searchIcon = Selector('div').withAttribute('class', 'CampaignsPage-fab1');
  const microAppNameInput = Selector('input').withAttribute('placeholder', 'Search');
  const microAppTitle = Selector('div').withAttribute('class', 'SetCard-title ').innerText;
  const searchIconElement = searchIcon.with({ visibilityCheck: true })();

  await t
    .click(searchIconElement)
    .typeText(microAppNameInput, testMicroAppTitle)
    .expect(microAppTitle)
    .eql(testMicroAppTitle);
});

【问题讨论】:

    标签: javascript testing automated-tests e2e-testing testcafe


    【解决方案1】:

    似乎我需要在角色中使用 { preserveUrl: true }。例如:

    this.adminUser = Role(
      this.loginScreen,
      async t => {
        const emailInput = Selector('input').withAttribute('placeholder', 'Email');
        const passwordInput = Selector('input').withAttribute('placeholder', 'Password');
    
        await t
          .typeText(emailInput, this.email)
          .typeText(passwordInput, this.password)
          .click(this.submit);
      },
      { preserveUrl: true }
    );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-07-01
      • 1970-01-01
      • 2021-08-04
      • 1970-01-01
      • 1970-01-01
      • 2020-07-23
      • 2016-03-11
      相关资源
      最近更新 更多