Page History
...
cypress/integration/common
: step implementation files, in JavaScript.cypress/integration/pages
: abstraction of different pages, somehow based on the page-objects modelcypress/integration/login
: Cucumber .feature files, containing the tests as Gherkin Scenario(s)/Scenario Outline(s)Code Block language js title cypress/integration/common/login.js collapse true import { Given, When } from 'cypress-cucumber-preprocessor/steps'; import LoginPage from '../../pages/login-page'; import LoginResultsPage from '../../pages/login-results-page'; Given(/^browser is opened to login page$/, () => { LoginPage.visit(); }); When('user {string} logs in with password {string}', (username, password) => { LoginPage.enter_username(username); LoginPage.enter_password(password); LoginPage.pressLogin(); }); Then(/^welcome page should be open$/, () => { LoginResultsPage.expect().toBeSuccessful(); }); Then(/^error page should be open$/, () => { LoginResultsPage.expect().toBeUnsuccessful(); });
Code Block language js title cypress/integration/common/logout.js collapse true import { Given, When } from 'cypress-cucumber-preprocessor/steps'; import LoginPage from '../../pages/login-page'; import LoginResultsPage from '../../pages/login-results-page'; Given(/^browser is opened to login page$/, () => { LoginPage.visit(); }); When('user {string} logs in with password {string}', (username, password) => { LoginPage.enter_username(username); LoginPage.enter_password(password); LoginPage.pressLogin(); }); Then(/^welcome page should be open$/, () => { LoginResultsPage.expect().toBeSuccessful(); }); Then(/^error page should be open$/, () => { LoginResultsPage.expect().toBeUnsuccessful(); });
...
cypress/integration/
...
pages
: abstraction of different pages, somehow based on the page-objects modelCode Block language js title cypress/integration/pages/login.js collapse true import LoginResultsPage from './login-results-page'; const USERNAME_FIELD = 'input[id=username_field]'; const PASSWORD_FIELD = 'input[id=password_field]'; const LOGIN_BUTTON = 'input[type=submit]'; const LOGIN_TEXT = 'LOGIN'; class LoginPage { static visit() { cy.visit('/'); } static enter_username(username) { cy.get(USERNAME_FIELD) .type(username); } static enter_password(password) { cy.get(PASSWORD_FIELD) .type(password); } static pressLogin() { cy.get(LOGIN_BUTTON).contains(LOGIN_TEXT) .click(); return new LoginResultsPage(); } } export default LoginPage;
Code Block language js title cypress/integration/pages/login-results-page.js collapse true const RESULT_HEADER = 'h1'; class LoginResultsPage { static expect() { return { toBeSuccessful: () => { cy.get(RESULT_HEADER).should('have.text', 'Welcome Page') },
...
toBeUnsuccessful:
...
()
...
=> {
...
...
cy.get(RESULT_HEADER).should('have.text', 'Error Page')
...
},
...
};
...
...
...
} } export
...
default LoginResultsPage;
Code Block language js
title cypress/integration/
...
pages/logout-results-page.
...
js collapse true
...
const RESULT_HEADER = 'h1'; class LogoutResultsPage { static expect() {
...
...
...
return
...
{
...
...
...
...
...
toBeSuccessful:
...
()
...
=>
...
{
...
...
...
...
...
...
...
language | js |
---|---|
title | cypress/integration/pages/login.js |
collapse | true |
...
...
...
cy.get(RESULT_HEADER).should('have.text', 'Login Page') }, }; } } export default LogoutResultsPage;
Code Block language js title cypress/integration/pages/welcome-page.js collapse true import LoginPage from './login-page'; const LOGOUT_LINK = 'a'; const LOGOUT_TEXT = 'logout'; class WelcomePage { static visit() { cy.
...
visit('/welcome.html'); } static
...
pressLogout() { cy.get(
...
LOGOUT_
...
LINK).contains(
...
LOGOUT_TEXT) .click(); return new
...
LoginPage(); } } export default
...
WelcomePage;
cypress/integration/login
: Cucumber .feature files, containing the tests as Gherkin Scenario(s)/Scenario Outline(s)Code Block
...
title cypress/integration/
...
login/login
...
.
...
feature collapse true
...
@REQ_CALC-7905 Feature: As a user, I can login the applicaiton Scenario: Valid Login Given browser is opened to login page When user "demo" logs in with password "mode" Then welcome page should be open Scenario: Invalid Login Given browser is opened to login page When user "dummy" logs in
...
with password "password" Then error page should be
...
open Scenario
...
Outline: Login With Invalid
...
Credentials
...
Should Fail Given browser is opened to login
...
page When user "<username>" logs in with password "<password>" Then error
...
page should be
...
open
...
Examples:
...
...
...
language | js |
---|---|
title | cypress/integration/pages/logout-results-page.js |
collapse | true |
...
...
...
...
...
...
| username
...
|
...
password
...
|
...
...
| invalid |
...
mode
...
...
...
|
...
| demo | invalid
...
|
...
...
|
...
invalid
...
|
...
invalid
...
...
|
Code Block
...
title cypress/integration/
...
login/
...
logout.
...
feature collapse true
...
@REQ_CALC-7906 Feature: As a user, I can logout the application Scenario: Valid Logout Given user is on the welcome page When user chooses to logout Then login page should be open
You can then export the specification of the test to a Cucumber .feature file via the REST API, or the Export to Cucumber UI action from within the Test/Test Execution issue or even based on an existing saved filter. A plugin for your CI tool of choice can be used to ease this task.
...