testing - 有没有办法让testcafe使用sso登录?

标签 testing single-sign-on adfs testcafe zscaler

对于端到端测试,我希望 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。

最佳答案

表示浏览器无法载入'url of web application' URL。确保可以从执行测试的计算机访问 Web 应用程序。

关于testing - 有没有办法让testcafe使用sso登录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58522445/

相关文章:

java - 如何使用 Java 或 vbscript 对具有 SSO 身份验证的 URL 执行 HTTP POST?

asp.net-mvc - 如何在 IIS 中使用带有 https 的域名而不是 localhost 来调试网站

iphone - 多个应用程序使用同一个 FaceBook 单点登录帐户,如何选择哪个打开登录屏幕?

Azure 应用程序网关 - 后端运行状况 404 错误

adfs - 使用 ADFS 重新进行身份验证?

java - 单元测试定义 - 范围和模拟外部依赖

ruby-on-rails - 如何在 Cucumber 中测试不同的环境(例如开发|测试|生产)?

python - Unittest 的 subTest 不能与 Pytest 一起使用,还是我疯了?

jenkins - 在 Jenkins 的常规脚本中,调用目标抛出了异常

c# - 如何在 ASP.NET Core Web API 中添加两个不同的 token