有没有办法让测试咖啡馆使用sso登录?



对于端到端测试,我希望Testcafe使用SSO登录到我们的SaaS应用程序(就像用户一样)。为此,Testcafe需要通过我们的代理,然后使用当前登录的用户的凭据登录到应用程序。

每当我使用自己的浏览器执行此操作时,这都可以正常工作,但不知何故,Testcafe 在尝试访问该页面时陷入困境。

我试图使用 Testcafe 提供的授权选项使其工作,但是,它们似乎都不起作用。

import { Selector, ClientFunction } from 'testcafe';
const getLocation = ClientFunction(() => document.location.href);
fixture("Close ADFS")
.httpAuth({
username: 'username',
password: 'password'
});
test('My first test', async t => {
await t
.navigateTo("url of web application")
.expect(getLocation()).contains("url of web application")
.expect(Selector("css selector that is in the application").exists).ok("Application not reached")
});

每当我运行测试时,我都会收到以下错误:

× My first test
1) AssertionError: expected 'about:error' to include 'url of web application'
Browser: Chrome 77.0.3865 / Windows 10.0.0
9 |    });
10 |
11 |test('My first test', async t => {
12 |  await t
13 |    .navigateTo("url of web application")
> 14 |    .expect(getLocation()).contains("url of web application")
15 |    .expect(Selector("css selector that is in the application").exists).ok("Application not reached")
16 |});
at contains (C:UsersM63G736Projectstestcafe-adfstest.js:14:28)
at <anonymous> (C:UsersM63G736Projectstestcafe-adfstest.js:11:1)
at <anonymous> (C:UsersM63G736Projectstestcafe-adfsnode_modulestestcafesrcapiwrap-test-function.js:17:28)
at TestRun._executeTestFn (C:UsersM63G736Projectstestcafe-adfsnode_modulestestcafesrctest-runindex.js:289:19)
at TestRun.start (C:UsersM63G736Projectstestcafe-adfsnode_modulestestcafesrctest-runindex.js:338:24)

2) A request to "url of web application" has failed.
Use quarantine mode to perform additional attempts to execute this test.
You can find troubleshooting information for this issue at "https://go.devexpress.com/TestCafe_FAQ_ARequestHasFailed.aspx".
Error details:
Failed to find a DNS-record for the resource at "url of web application".
Browser: Chrome 77.0.3865 / Windows 10.0.0

有人能说这是否是Testcafe可以做的事情吗?如果是这样,你能告诉我使用什么配置/代码吗?

编辑: 我通过使用另一个代理修复了DNS错误。并稍微修改了测试:

import { Selector, ClientFunction } from 'testcafe';
const getLocation = ClientFunction(() => document.location.href);
fixture("Close ADFS").page('https://google.nl');
test('My first test', async t => {
await t
.navigateTo("url of web application")
.expect(Selector("element on homepage of web application").exists).ok("Close not reached")
.expect(getLocation()).contains("url of web application")
});

这仍然失败

Close ADFS
× My first test
1) AssertionError: Close not reached: expected false to be truthy
Browser: Chrome 77.0.3865 / Windows 10.0.0
9 |  });
10 |
11 |test('My first test', async t => {
12 |  await t
13 |    .navigateTo("url of web application")
> 14 |    .expect(Selector("body > app-component > app-shell > header > nav > div > div.navbar-header > div").exists).ok("Close not reached")
15 |    .expect(getLocation()).contains("url of web application")
16 |});
at ok (C:UsersM63G736Projectstestcafe-adfstest.js:14:113)
at <anonymous> (C:UsersM63G736Projectstestcafe-adfstest.js:11:1)
at <anonymous> (C:UsersM63G736Projectstestcafe-adfsnode_modulestestcafesrcapiwrap-test-function.js:17:28)
at TestRun._executeTestFn (C:UsersM63G736Projectstestcafe-adfsnode_modulestestcafesrctest-runindex.js:289:19)
at TestRun.start (C:UsersM63G736Projectstestcafe-adfsnode_modulestestcafesrctest-runindex.js:338:24)

1/1 failed (22s)
npm ERR! Test failed.  See above for more details.

每当我运行测试时,我都会看到它确实访问了 google.nl,但随后无法导航到应用程序 URL。

这意味着浏览器无法加载"Web 应用程序的网址"网址。确保可从执行测试的计算机访问 Web 应用程序。

最新更新