Clear and scalable e2e tests written in plain English
Clear and scalable e2e tests written in plain English
Based on cypress-cucumber-example
This project is designed to quickly start e2e testing. It includes the integration ofCypress.io
with Cucumber
and the implementation of the PageObject pattern. You just
need to add ‘Page Objects’ following the instruction below.
After that, you can use Gherkin
statements which are generated
based on added Page Objects. Thus, writing and supporting tests becomes more convenient.
The following basic tools are used in this project:
npm install
npm run test:open
or npm run test:run
npm i -D git+ssh://git@github.com/SparkEquation/e2e-behaviour-testing.git
e2e-bdd-copy-files
to create necessary directories and config files.'e2e-bdd'
to your package.json
file with following contente2e-bdd-startup -c e2e/config/cypress.integration.json
baseUrl
in e2e/config/cypress.integration.json
file to base url of your projecte2e/pageObjects
directory.e2e/features
folder based on Gherkin
TODO add build step with webpack
Due to poor support of Gherkin custom types in IntelliJ IDEA,
we use {string}
parameter instead of {pageObjectSelector}
in our steps definitions.
In the available statements list, however, we will use
the following syntax:{POS:Type}
to improve semantics, reduce step definitions length and show constraints.
Available types are listed in page object’s details section.
I logged in at {ApiUrl} as {Role} and visit {PageUrl}
POS:Navigation
- log in post endpointPOS:RoleCredentials
- credentials for desired rolePOS:Navigation
- page to visit after authorizationTODO: add limitations list
I logged in at {ApiUrl} as {Role}
I open page {PageUrl}
POS:Navigation
- page to visitI click {Element}
POS:Selector | POS:Xpath
- selector of element on the pageI click blank link {LinkElement}
POS:Selector | POS:Xpath
- clickable element which opens blank pageI hover element {HoverableElement} without sub hovers
POS:Selector | POS:Xpath
I log in at {Form} as {Role}
POS:Selector | POS:Xpath
- selector of form elementI see (element) {Element}
I type {string} into element {Element}
URL is {PageUrl}
I see {string} in title
Check lib directory for available steps and cypress folder for examples
Most steps expect selector as "RegisteredPageObjectName.classFieldName"
This list will expand and may change over time.
e2e
directory contains examples of tests, page objectsdist
provides bundled codeTODO delete from git when published to npm
src
Contains source codescripts
include some files which will be executables for your projectcore
contains functions and classes that works ‘under the hood’util
contains utils functionslib
Source code that will be downloaded on installation to provide step definitionspostinstall
contains templates of files that can be copied to projectcredentials
. We recommend doing it withcypress.env.json
file because it should contain JSON object of CredentialsObject
typeCredentials
page object will be accessible in feature flies.beforeEach
cypress hook. Default value is ‘/‘ but you can override it withstartPage
env variable. It should contain relative to basePath url.Page object file should export one class with any name.
Every one of classes should be annotated with @registerPageObject
directive with
either name
parameter or object with name
and optional type
fields.
When you are trying to resolve page object in your .feature
files
you address the class just as you name it.
Do not use same name for multiple classes.
Do not forget that Credentials
is built-in page object,
as mentioned here
All class fields you are going to use in your tests should have type.
You can set class-global type with self-titled param of registerPageObject
decorator
or decorate your field \ method with registerSelector
decorator, which overrides
the global value if it is present.
Selector can either be simple field or function that returns an expected type.
Type should be one of the following
jquery
like selector to get elementor array of two elements, where the first one is selector
@registerSelector('Selector')
public form = '#sign-in';
@registerSelector('Selector')
public header = ['h1', 'Example.com'];
Attention only one element is going to be selected if text is present
If you need to select multiple elements with some text use
`:contains` pseudo class in selector instead
Selector
with one argument but uses xpath to select element
@registerSelector('Xpath')
public menuLink = '//a[@id="menu-link"]';
@registerSelector('Navigation')
public usernameElement = 'Users/login';
<IRoleCredentials>
objectsCredentials
built-in page object.
@registerSelector('RoleCredentials')
public admin: = LogInRole = [
{
fieldName: 'Username',
value: 'user@domain.com'
},
{
fieldName: 'Password',
value: 'password'
}
];
Let’s assume you have installed the library and created the following feature file
Feature: My first feature
Scenario: Visit start page
Given I open "ExampleDomain.IndexPage"
Then I see "Example Domain" in title
And URL is "ExampleDomain.IndexPage"
To successfully run it you need to do the following steps:
https://example.com
@registerPageObject('ExampleDomain')
export class ExampleDomainClass {
@registerSelector('Navigation')
IndexPage: string = ''
}
page-objects-create && cypress open