Search code examples
cucumbere2e-testinghttp-authenticationtestcafe

How to implement httpAuth in cucumber step definition


There is a way to handle httpAuth in testCafe, http://devexpress.github.io/testcafe/documentation/test-api/authentication/http-authentication.html , I am trying to test a site which first I have to go through httpAuth. The mentioned function is for fixture. How I should handle httpAuth inside a cucumber step definition? An example much appreciated.

My stepdef is similar to

Given('The page is loaded', async function () { await testController.navigateTo('http://example.com').httpAuth({ username: 'logmein', password: 'test123' }) });

And I am getting

TypeError: testController.navigateTo(...).httpAuth is not a function


Solution

  • The test.httpAuth of fixture.httpAuth methods are intended to specify the credentials to be used by an individual test or a fixture, so these methods should be used in the context of test or fixture, but not in the context of testController. You cannot use httpAuth inside a test body. Please see the example from documentation (https://devexpress.github.io/testcafe/documentation/guides/advanced-guides/authentication.html#http-authentication):

    fixture `My fixture`
        .page `http://example.com`
        .httpAuth({
            username: 'username',
            password: 'Pa$$word',
    
            // Optional parameters, can be required for the NTLM authentication.
            domain:      'CORP-DOMAIN',
            workstation: 'machine-win10'
        });
    
    test('Test1', async t => {});          // Logs in as username
    
    test                                   // Logs in as differentUserName
        .httpAuth({
            username: 'differentUserName',
            password: 'differentPa$$word'
        })
        ('Test2', async t => {});