-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(authentication): add the ability to use http authentication
http basic authentication can be used by creating a js file that contains the necessary credentials (as seen in testcafe documentation) => featureFileName.credentials.js re #76
- Loading branch information
Showing
6 changed files
with
114 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module.exports.username = 'user'; | ||
module.exports.password = 'pass'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Feature: HTTP Basic Authentication | ||
|
||
I want to be able to import HTTP credentials in my tests by using TestCafe's httpAuth functionality | ||
|
||
Scenario: Authenticating on Jigsaw HTTP test site | ||
Given I created an HTTP authentication file for my feature | ||
And I opened the HTTP test site | ||
When I open the protected page | ||
Then I should reach the protected page |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { existsSync } from 'fs'; | ||
import { Given, When, Then } from '@cucumber/cucumber'; | ||
import { Selector } from 'testcafe'; | ||
|
||
const linkSelector = Selector( | ||
'div.row:nth-child(3) > div:nth-child(1) > div:nth-child(2) > div:nth-child(2) > a:nth-child(3)' | ||
); | ||
|
||
Given('I created an HTTP authentication file for my feature', async (t) => { | ||
// only works with js files at the moment | ||
const allowedExtentions = ['.js']; | ||
const foundCredentialFiles = allowedExtentions | ||
.map((extention) => __filename.slice(0, -3).concat('.credentials', extention)) | ||
.filter((filename) => existsSync(filename)); | ||
await t.expect(foundCredentialFiles.length).gt(0); | ||
}); | ||
|
||
Given('I opened the HTTP test site', async (t) => { | ||
await t.navigateTo('https://authenticationtest.com/').expect(linkSelector.exists).ok(); | ||
}); | ||
|
||
When('I open the protected page', async (t) => { | ||
await t.click(linkSelector); | ||
}); | ||
|
||
Then('I should reach the protected page', async (t) => { | ||
const titleSelector = Selector('div.container h1'); | ||
await t.expect(titleSelector.innerText).eql('Login Success'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters