testcafe-CAS认证

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

TestCafe的新手。有一些简单的示例测试可以轻松地工作。但是,我找不到任何似乎可以允许我通过CAS身份验证页面登录到我的应用程序的功能示例。

此代码可在登录页面上找到登录按钮并单击它。

fixture`VRT`
    .page `http://myapp.com/login/`;

test('Find Login button', async t => {
    const input = Selector('input.btn');

    await t.click(input);
});

这可以在登录页面上输入用户名和密码:

test('Login using CAS', async t => {
     await t
     .expect("#username").exists
     .typeText('#username', 'myuser')
     .typeText('#password', '***')
     .click('#submit');
});

但是问题在于,似乎没有办法从一项测试继续进行到另一项测试。因此,我无法从打开登录页面的第一个测试进入输入凭据的下一个测试。对于TestCafe,似乎每个测试都必须指定自己的页面。

如果我尝试通过直接将其指定为夹具“页面”而直接进入CAS登录页面,则TestCafe无法打开该页面,因为URL非常长。

谢谢您的建议。


更新:

因此,使用角色使我更进一步(谢谢),但是在进入我要测试的页面之前,必须先通过输入按钮单击才能进入CAS页面。可以再次单击添加角色登录:

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

const finalLoginBtn = Selector('input.btn');

const myUserRole = Role('http://example.com/login', async t => {
    await t
        .click('input.btn')
        .typeText('#username', 'my-username')
        .typeText('#password', '*****')
        .click('#submit')
        .click(finalLoginBtn);
}, { preserveUrl: true });

fixture`VRT`

test("My User Page", async t => {
    await t.navigateTo(`http://example.com`)
    await t.useRole(myUserRole);
});
authentication testing automated-tests cas testcafe
1个回答
2
投票

TestCafe的“用户角色”功能应符合您的要求。请有关详细信息,请参阅TestCafe文档中的以下主题:https://devexpress.github.io/testcafe/documentation/test-api/authentication/user-roles.html

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