测试咖啡 - CAS 身份验证



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);
});

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

最新更新