Is there a way to let testcafe login using sso?

1.2k Views Asked by At

For an End-to-End test, I want Testcafe to login to our SaaS application using SSO (just as a user would do). For this to work Testcafe needs to get through our proxy and then log in to the application using the credentials of the user that is currently logged in.

Whenever I do this using my own browser this works just fine, but somehow Testcafe gets stuck trying to visit the page.

I have tried to get this to work using the authorization options that Testcafe provides, however, none of them seem to work.

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

Whenever I run the test, I get the following error:

× 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

Can someone tell if this is something that can be done with Testcafe? And if so, can you tell me what config/code to use?

Edit: I fixed the DNS error by using another proxy. And modified the test somewhat:

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

This still fails at

 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.

Whenever I run the test, I see that it does visit google.nl, but then fails to navigate to the application URL.

1

There are 1 best solutions below

3
On

It means that the browser cannot load the 'url of web application' URL. Make sure the web application is reachable from computer on which the tests are executed.