Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: cucumber. again. #398

Merged
merged 19 commits into from
Jan 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions .github/workflows/wdi5-tests_core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,6 @@ jobs:
node-version: [14, 16, 18, 19]

steps:
- name: update chrome
run: |
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
sudo sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
sudo apt-get update
sudo apt-get --only-upgrade install google-chrome-stable
# check chrome version
google-chrome --version

- name: check out repo
uses: actions/checkout@v3

Expand Down
2 changes: 1 addition & 1 deletion docs/authentication.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Generally speaking, the authentication behavior mimicks that of a regular user s
BTP-, Office365- and custom IdP all supply credentials as a user would, meaning they're literally typed into the respective input fields on each login screen.
Basic Authentication prepends username and password in encoded form to the URL, resulting in an `HTTP` `GET` in the form of `https://username:[email protected]`.

!> Multi-Factor Authentication is not supported as it's nearly to manage any media break (e.g. browser ↔ mobile) in authentication flows out of the box
!> Multi-Factor Authentication is not supported as it's nearly impossible to manage any media break (e.g. browser ↔ mobile) in authentication flows out of the box

For you as users, authentication is done at design-time, meaning: **by configuration only, not programmatically**.
This especially means that no changes in the test code are needed for using authentication in `wdi5` tests!
Expand Down
12 changes: 12 additions & 0 deletions examples/cucumber/features/login.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Feature: The Internet Guinea Pig Website

Scenario Outline: As a user, I can log into the secure area

Given I am on the login page
When I login with <username> and <password>
Then I should see a flash message saying <message>

Examples:
| username | password | message |
| tomsmith | SuperSecretPassword! | You logged into a secure area! |
| foobar | barfoo | Your username is invalid! |
40 changes: 40 additions & 0 deletions examples/cucumber/features/pageobjects/login.page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const Page = require("./page")

/**
* sub page containing specific selectors and methods for a specific page
*/
class LoginPage extends Page {
/**
* define selectors using getter methods
*/
get inputUsername() {
return $("#username")
}

get inputPassword() {
return $("#password")
}

get btnSubmit() {
return $('button[type="submit"]')
}

/**
* a method to encapsule automation code to interact with the page
* e.g. to login using username and password
*/
async login(username, password) {
await this.inputUsername.setValue(username)
await this.inputPassword.setValue(password)
await this.btnSubmit.click()
}

/**
* overwrite specific options to adapt it to page object
*/
open() {
return super.open("login")
}
}

module.exports = new LoginPage()
13 changes: 13 additions & 0 deletions examples/cucumber/features/pageobjects/page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* main page object containing all methods, selectors and functionality
* that is shared across all page objects
*/
module.exports = class Page {
/**
* Opens a sub page of the page
* @param path path of the sub page (e.g. /path/to/page.html)
*/
open(path) {
return browser.url(`https://the-internet.herokuapp.com/${path}`)
}
}
15 changes: 15 additions & 0 deletions examples/cucumber/features/pageobjects/secure.page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const Page = require("./page")

/**
* sub page containing specific selectors and methods for a specific page
*/
class SecurePage extends Page {
/**
* define selectors using getter methods
*/
get flashAlert() {
return $("#flash")
}
}

module.exports = new SecurePage()
21 changes: 21 additions & 0 deletions examples/cucumber/features/step-definitions/steps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const { Given, When, Then } = require("@wdio/cucumber-framework")

const LoginPage = require("../pageobjects/login.page")
const SecurePage = require("../pageobjects/secure.page")

const pages = {
login: LoginPage
}

Given(/^I am on the (\w+) page$/, async (page) => {
await pages[page].open()
})

When(/^I login with (\w+) and (.+)$/, async (username, password) => {
await LoginPage.login(username, password)
})

Then(/^I should see a flash message saying (.*)$/, async (message) => {
await expect(SecurePage.flashAlert).toBeExisting()
await expect(SecurePage.flashAlert).toHaveTextContaining(message)
})
15 changes: 15 additions & 0 deletions examples/cucumber/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"devDependencies": {
"@wdio/cli": "^7.27.0",
"@wdio/cucumber-framework": "^7.27.0",
"@wdio/local-runner": "^7.27.0",
"@wdio/mocha-framework": "^7.26.0",
"@wdio/spec-reporter": "^7.26.0",
"chromedriver": "latest",
"wdio-chromedriver-service": "^7.3.2",
"wdio-ui5-service": "*"
},
"scripts": {
"test": "wdio run ./wdio.conf.js"
}
}
Loading