TestCafe-如何通过auth0登录使用角色

问题描述 投票:0回答:1

我有一个具有auth0登录名的应用。在这种情况下,我还无法弄清楚如何制作t.useRole

幸运的是,这很容易复制。 auth0(应用程序)使用相同的过程。它失败的方式与我的应用程序完全相同。

预期结果-用户登录-用户转到仪表板-用户保持登录状态-用户再次进入信息中心(第二项测试)

实际-用户登录-用户转到仪表板-用户不再通过身份验证-用户进入登录页面

import { Role, Selector, ClientFunction } from 'testcafe';

const getPageUrl = ClientFunction(() => window.location.href.toString());

const exampleRole: Role = Role('https://auth0.com/auth/login', async t => {
    const userNameInput = Selector('input').withAttribute('name', 'email');
    const passwordInput = Selector('input').withAttribute('name', 'password');
    const loginButton = Selector('button').withAttribute('name', 'submit');

    await t
        .wait(5000)
        .click(userNameInput)
        .typeText(userNameInput, userName)
        .click(passwordInput)
        .typeText(passwordInput, password)
        .click(loginButton);
})

fixture(`SAMPLE`)
    .page('https://manage.auth0.com/dashboard')
    .beforeEach(async t => {
        await t.useRole(exampleRole)
    })

test('My first test', async t => {
    await t
        .expect(getPageUrl()).contains('dashboard')
});

test('My next test', async t => {
    await t
        .expect(getPageUrl()).contains('dashboard')
})

输出

 SAMPLE
 √ My first test
 × My next test

   1) AssertionError: expected

   'https://auth0.auth0.com/login?state=***&client=***&protocol=oauth2&response_type=code&redirect_uri=https%3A%2F%2Fmanage.auth0.com%2Fcallback&scope=openid%20profile%20name%20email%20nickname%20created_at'
      to include 'dashboard'
    ```
testcafe
1个回答
0
投票
解决方法是在角色块的

。click(loginButton)之后添加等待。请查看这是否适合您的情况。

const exampleRole: Role = Role('https://auth0.com/auth/login', async t => { const userNameInput = Selector('input').withAttribute('name', 'email'); const passwordInput = Selector('input').withAttribute('name', 'password'); const loginButton = Selector('button').withAttribute('name', 'submit'); await t .wait(5000) .click(userNameInput) .typeText(userNameInput, userName) .click(passwordInput) .typeText(passwordInput, password) .click(loginButton); .wait(10000); })

© www.soinside.com 2019 - 2024. All rights reserved.