对于端到端测试,我希望 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:\Users\M63G736\Projects\testcafe-adfs\test.js:14:28)
at <anonymous> (C:\Users\M63G736\Projects\testcafe-adfs\test.js:11:1)
at <anonymous> (C:\Users\M63G736\Projects\testcafe-adfs\node_modules\testcafe\src\api\wrap-test-function.js:17:28)
at TestRun._executeTestFn (C:\Users\M63G736\Projects\testcafe-adfs\node_modules\testcafe\src\test-run\index.js:289:19)
at TestRun.start (C:\Users\M63G736\Projects\testcafe-adfs\node_modules\testcafe\src\test-run\index.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:\Users\M63G736\Projects\testcafe-adfs\test.js:14:113)
at <anonymous> (C:\Users\M63G736\Projects\testcafe-adfs\test.js:11:1)
at <anonymous> (C:\Users\M63G736\Projects\testcafe-adfs\node_modules\testcafe\src\api\wrap-test-function.js:17:28)
at TestRun._executeTestFn (C:\Users\M63G736\Projects\testcafe-adfs\node_modules\testcafe\src\test-run\index.js:289:19)
at TestRun.start (C:\Users\M63G736\Projects\testcafe-adfs\node_modules\testcafe\src\test-run\index.js:338:24)
1/1 failed (22s)
npm ERR! Test failed. See above for more details.
每当我运行测试时,我看到它确实访问了 google.nl,但随后无法导航到应用程序 URL。