-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ec5971e
Showing
25 changed files
with
7,712 additions
and
0 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,10 @@ | ||
# Environment variables for acceptance tests | ||
# | ||
# This is an example. In your own project create the file .env. Then add these | ||
# env vars to it but with the actual values. | ||
# | ||
# The file will be ignored by git and should not be committed. Typically it | ||
# is used for things you don't wanted visible in the code such as passwords. | ||
|
||
# Password used for test accounts | ||
CYPRESS_PASSWORD=MySecretPassword123 |
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,40 @@ | ||
# See https://help.github.com/articles/ignoring-files for more about ignoring files. | ||
|
||
# IDE's and text editors # | ||
# Ruby mine | ||
/.idea | ||
# VS Code | ||
/.vscode | ||
# Symbol tags (e.g. generated by Atom Editor) | ||
/tags | ||
|
||
# Logs, temp and OS specific files | ||
/log/* | ||
!/log/.keep | ||
/tmp/* | ||
!/tmp/.keep | ||
*~ | ||
.DS_Store | ||
.svn | ||
.*.swp | ||
___* | ||
pkg/ | ||
chromedriver.log | ||
/.byebug_history | ||
*.log | ||
|
||
# Dependency directories | ||
node_modules/ | ||
|
||
# Videos generated by Cypress | ||
cypress/videos/ | ||
|
||
# Screenshots generated by Cypress | ||
cypress/screenshots/ | ||
|
||
# Dotenv https://github.com/motdotla/dotenv | ||
# Ignore the .env file as this may contain actual credentials. The .env.example | ||
# file gets committed which acts as documentation on what environment | ||
# variables will need to be set up | ||
.env | ||
.env.local |
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,74 @@ | ||
The Open Government Licence (OGL) Version 3 | ||
|
||
Copyright (c) 2020 Defra | ||
|
||
You are encouraged to use and re-use the Information that is available under this licence freely and flexibly, with only a few conditions. | ||
|
||
Using Information under this licence | ||
|
||
Use of copyright and database right material expressly made available under this licence (the 'Information') indicates your acceptance of the terms and conditions below. | ||
|
||
The Licensor grants you a worldwide, royalty-free, perpetual, non-exclusive licence to use the Information subject to the conditions below. | ||
|
||
This licence does not affect your freedom under fair dealing or fair use or any other copyright or database right exceptions and limitations. | ||
|
||
You are free to: | ||
|
||
copy, publish, distribute and transmit the Information; | ||
adapt the Information; | ||
exploit the Information commercially and non-commercially for example, by combining it with other Information, or by including it in your own product or application. | ||
You must (where you do any of the above): | ||
|
||
acknowledge the source of the Information in your product or application by including or linking to any attribution statement specified by the Information Provider(s) and, where possible, provide a link to this licence; | ||
If the Information Provider does not provide a specific attribution statement, you must use the following: | ||
Contains public sector information licensed under the Open Government Licence v3.0. | ||
|
||
If you are using Information from several Information Providers and listing multiple attributions is not practical in your product or application, you may include a URI or hyperlink to a resource that contains the required attribution statements. | ||
|
||
These are important conditions of this licence and if you fail to comply with them the rights granted to you under this licence, or any similar licence granted by the Licensor, will end automatically. | ||
|
||
Exemptions | ||
|
||
This licence does not cover: | ||
|
||
personal data in the Information; | ||
Information that has not been accessed by way of publication or disclosure under information access legislation (including the Freedom of Information Acts for the UK and Scotland) by or with the consent of the Information Provider; | ||
departmental or public sector organisation logos, crests and the Royal Arms except where they form an integral part of a document or dataset; | ||
military insignia; | ||
third party rights the Information Provider is not authorised to license; | ||
other intellectual property rights, including patents, trade marks, and design rights; and | ||
identity documents such as the British Passport | ||
Non-endorsement | ||
|
||
This licence does not grant you any right to use the Information in a way that suggests any official status or that the Information Provider and/or Licensor endorse you or your use of the Information. | ||
|
||
No warranty | ||
|
||
The Information is licensed 'as is' and the Information Provider and/or Licensor excludes all representations, warranties, obligations and liabilities in relation to the Information to the maximum extent permitted by law. | ||
|
||
The Information Provider and/or Licensor are not liable for any errors or omissions in the Information and shall not be liable for any loss, injury or damage of any kind caused by its use. The Information Provider does not guarantee the continued supply of the Information. | ||
|
||
Governing Law | ||
|
||
This licence is governed by the laws of the jurisdiction in which the Information Provider has its principal place of business, unless otherwise specified by the Information Provider. | ||
|
||
Definitions | ||
|
||
In this licence, the terms below have the following meanings: | ||
|
||
'Information' means information protected by copyright or by database right (for example, literary and artistic works, content, data and source code) offered for use under the terms of this licence. | ||
'Information Provider' means the person or organisation providing the Information under this licence. | ||
'Licensor' means any Information Provider which has the authority to offer Information under the terms of this licence or the Keeper of Public Records, who has the authority to offer Information subject to Crown copyright and Crown database rights and Information subject to copyright and database right that has been assigned to or acquired by the Crown, under the terms of this licence. | ||
'Use' means doing any act which is restricted by copyright or database right, whether in the original medium or in any other medium, and includes without limitation distributing, copying, adapting, modifying as may be technically necessary to use it in a different mode or format. | ||
'You', 'you' and 'your' means the natural or legal person, or body of persons corporate or incorporate, acquiring rights in the Information (whether the Information is obtained directly from the Licensor or otherwise) under this licence. | ||
About the Open Government Licence | ||
|
||
The National Archives has developed this licence as a tool to enable Information Providers in the public sector to license the use and re-use of their Information under a common open licence. The National Archives invites public sector bodies owning their own copyright and database rights to permit the use of their Information under this licence. | ||
|
||
The Keeper of the Public Records has authority to license Information subject to copyright and database right owned by the Crown. The extent of the offer to license this Information under the terms of this licence is set out in the UK Government Licensing Framework. | ||
|
||
This is version 3.0 of the Open Government Licence. The National Archives may, from time to time, issue new versions of the Open Government Licence. If you are already using Information under a previous version of the Open Government Licence, the terms of that licence will continue to apply. | ||
|
||
These terms are compatible with the Creative Commons Attribution License 4.0 and the Open Data Commons Attribution License, both of which license copyright and database rights. This means that when the Information is adapted and licensed under either of those licences, you automatically satisfy the conditions of the OGL when you comply with the other licence. The OGLv3.0 is Open Definition compliant. | ||
|
||
Further context, best practice and guidance can be found in the UK Government Licensing Framework section on The National Archives website. |
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,117 @@ | ||
# SROC acceptance tests | ||
|
||
> Work in progress! Currently is a possible project to use for our acceptance tests. It includes some simple examples and is only configured to run against a locally running instance of the TCM. | ||
The Tactical Charging Module (TCM) is a web application designed to enable billing adminstrators to apply new categories to permit charges to enable correct amounts to be processed. | ||
|
||
This service is an internally facing service only, used by billing administration staff. | ||
|
||
This project contains acceptance tests for the service. It is built using [Cypress](https://www.cypress.io/) and the [cypress-cucumber-preprocessor](https://github.com/TheBrainFamily/cypress-cucumber-preprocessor). We favour writing our tests in a BBD style using [Gherkin](https://cucumber.io/docs/gherkin/) hence the cucumber-preprocessor plugin. | ||
|
||
## Pre-requisites | ||
|
||
You just need [Node.js](https://nodejs.org/en/) installed, ideally an LTS version. | ||
|
||
You'll also need [Chrome](https://www.google.com/intl/en_uk/chrome/). It's what we use when working on the tests, and is one of 2 browsers available to our users. | ||
|
||
## Installation | ||
|
||
First clone the repository and then drop into your new local repo | ||
|
||
```bash | ||
git clone https://github.com/DEFRA/sroc-acceptance-tests.git && cd sroc-acceptance-tests | ||
``` | ||
|
||
Next download and install the dependencies | ||
|
||
```bash | ||
npm install | ||
``` | ||
|
||
## Configuration | ||
|
||
> Important! Do not store credentials such as passwords in the config files | ||
We have 5 environments where the TCM could be running; local, development, test, pre-production, and production. | ||
|
||
Each has its own config file stored in `config/`. Any configuration shared across the environments is stored in `cypress.json`. But these can be overidden in the environment config file. | ||
|
||
### Dotenv | ||
|
||
Via the [Cypress dotenv](https://github.com/morficus/cypress-dotenv) plugin you can store environment variables in a local `.env` file. | ||
|
||
Things like credentials, which we don't want stored in the project, we'll pass in as environment variables. Dotenv and the `.env` file saves you having to add them to your session. | ||
|
||
Checkout `.env.example` for an example of the file you'll need to create to run the project. | ||
|
||
## Execution | ||
|
||
You can run tests using the Cypress test runner or headlessly using the Cypress CLI. | ||
|
||
### Test runner | ||
|
||
> Cypress runs tests in a unique interactive runner that allows you to see commands as they execute while also viewing the application under test. | ||
<img src="docs/test_runner.png" width="800" alt="Screenshot of test runner" /> | ||
|
||
To open the test runner use `npm run cy:open:[env]` replacing `[env]` with your chosen environment | ||
|
||
```bash | ||
npm run cy:open:local | ||
``` | ||
|
||
### CLI | ||
|
||
> Runs Cypress tests to completion. By default, cypress run will run all tests headlessly in the Electron browser. | ||
<img src="docs/cli.png" width="800" alt="Screenshot of test runner" /> | ||
|
||
To open the test runner use `npm run cy:run:[env]` replacing `[env]` with your chosen environment | ||
|
||
```bash | ||
npm run cy:run:local | ||
``` | ||
|
||
## Test structure | ||
|
||
In order to test our environments as well as our application, we created a standalone project rather than install Cypress into an existing one. | ||
|
||
We have also opted to write our tests as `features` using the BDD style. As such our project's structure is a little different from the common examples you'll find Googling. | ||
|
||
### Features | ||
|
||
Feature files (`*.feature`) need to be stored in `cypress/integration/` to be visible as tests. Along with each feature you will need to create a folder with the same name. In the folder create a `*.js` and add your steps for the feature there. | ||
|
||
The steps file can be called anything. But we have opted to use the same name as the feature file and folder. This way makes it a little easier to track things when working across multiple files. | ||
|
||
#### Common steps | ||
|
||
Any steps which can be shared across features can be placed in `cypress/integration/common/`. Check the existing files to see if one that fits already exists and add your steps to it. Else create a new `*.js` file. Again, the name of the file does not matter. | ||
|
||
### Pages | ||
|
||
Another preference of the team is to use the [Page object pattern](https://martinfowler.com/bliki/PageObject.html). Essentially, we store the code to interact with a page of our service in one place. Tests interact with our page object not the page directly. So should something change, we only have to change it in one place. | ||
|
||
Pages live in `cypress/pages`. | ||
|
||
## Contributing to this project | ||
|
||
If you have an idea you'd like to contribute please log an issue. | ||
|
||
All contributions should be submitted via a pull request. | ||
|
||
## Licence | ||
|
||
THIS INFORMATION IS LICENSED UNDER THE CONDITIONS OF THE OPEN GOVERNMENT LICENCE found at: | ||
|
||
<http://www.nationalarchives.gov.uk/doc/open-government-licence/version/3> | ||
|
||
The following attribution statement MUST be cited in your products and applications when using this information. | ||
|
||
> Contains public sector information licensed under the Open Government licence v3 | ||
### About the licence | ||
|
||
The Open Government Licence (OGL) was developed by the Controller of Her Majesty's Stationery Office (HMSO) to enable information providers in the public sector to license the use and re-use of their information under a common open licence. | ||
|
||
It is designed to encourage use and re-use of information freely and flexibly, with only a few conditions. |
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,3 @@ | ||
{ | ||
"baseUrl": "https://tcm-dev.aws.defra.cloud" | ||
} |
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,3 @@ | ||
{ | ||
"baseUrl": "http://localhost:3000" | ||
} |
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,3 @@ | ||
{ | ||
"baseUrl": "https://tcm-pre.aws.defra.cloud" | ||
} |
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,3 @@ | ||
{ | ||
"baseUrl": "https://tcm-tst.aws.defra.cloud" | ||
} |
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,11 @@ | ||
{ | ||
"env": { | ||
"TAGS": "not @ignore" | ||
}, | ||
"testFiles": "**/*.feature", | ||
"video": false, | ||
"baseUrl": "http://localhost:3000", | ||
"users": { | ||
"system": "[email protected]" | ||
} | ||
} |
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,5 @@ | ||
import { Then } from 'cypress-cucumber-preprocessor/steps' | ||
|
||
Then(`I see {string} in the main heading`, (title) => { | ||
cy.get('h1').contains(title) | ||
}) |
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,10 @@ | ||
import { Given } from 'cypress-cucumber-preprocessor/steps' | ||
import SignInPage from '../../pages/sign_in_page' | ||
|
||
Given('I sign in as the {string} user', (user) => { | ||
SignInPage.visit() | ||
SignInPage.email().type(Cypress.config().users[user]) | ||
SignInPage.password().type(Cypress.env('PASSWORD')) | ||
|
||
SignInPage.logIn().click() | ||
}) |
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,10 @@ | ||
Feature: Sign in | ||
|
||
Scenario: Visit sign in page | ||
Given I visit the sign in page | ||
Then I see 'Sign in' in the main heading | ||
|
||
Scenario: Log in to service | ||
Given I visit the sign in page | ||
When I enter my credentials | ||
Then I see 'Transactions to be billed' in the main heading |
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,13 @@ | ||
import { Given, When } from 'cypress-cucumber-preprocessor/steps' | ||
import SignInPage from '../../pages/sign_in_page' | ||
|
||
Given('I visit the sign in page', () => { | ||
SignInPage.visit() | ||
}) | ||
|
||
When('I enter my credentials', () => { | ||
SignInPage.email().type(Cypress.config().users.system) | ||
SignInPage.password().type(Cypress.env('PASSWORD')) | ||
|
||
SignInPage.logIn().click() | ||
}) |
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,8 @@ | ||
Feature: Transactions | ||
|
||
Background: | ||
Given I sign in as the 'system' user | ||
|
||
Scenario: Search for customer | ||
When I search for the customer 'A1234B' | ||
Then I see only results for customer 'A1234B' |
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,38 @@ | ||
import { Then, When, Before } from 'cypress-cucumber-preprocessor/steps' | ||
import TransactionsPage from '../../pages/transactions_page' | ||
|
||
Before(() => { | ||
// The TCM uses JavaScript and XHR requests to avoid page refreshes. So, for | ||
// example, we want to test that searching for a customer results in a table | ||
// of transactions containing only that customer. For that we have to wait for | ||
// the XHR request to complete and the JavaScript to kick in and update the | ||
// page. Only then can we check we use cypress to grab the table elements we | ||
// need to check. | ||
// | ||
// To do that we have to register the XHR call with Cypress and give it an | ||
// 'alias'. When we complete an action we know will result in a request, we | ||
// need to tell Cypress to wait for our aliased XHR call to complete. | ||
// | ||
// Here, we have chosen to register the XHR in a before block so we know its | ||
// available throughout, and to keep the tests a little cleaner. | ||
// | ||
// https://docs.cypress.io/guides/guides/network-requests.html#Waiting | ||
cy.server() | ||
cy.route({ | ||
method: 'GET', | ||
url: '/regimes/cfd/transactions*' | ||
}).as('getTransactions') | ||
}) | ||
|
||
When('I search for the customer {string}', (customer) => { | ||
TransactionsPage.search().type(customer) | ||
TransactionsPage.searchBtn().click() | ||
|
||
cy.wait('@getTransactions') | ||
}) | ||
|
||
Then('I see only results for customer {string}', (customer) => { | ||
TransactionsPage.customerColumn().each(($el) => { | ||
expect($el.text()).to.have.string(customer) | ||
}) | ||
}) |
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,23 @@ | ||
class SignInPage { | ||
static visit () { | ||
cy.visit('/auth/sign_in') | ||
} | ||
|
||
static mainHeading () { | ||
return cy.get('h1') | ||
} | ||
|
||
static email () { | ||
return cy.get('#user_email') | ||
} | ||
|
||
static password () { | ||
return cy.get('#user_password') | ||
} | ||
|
||
static logIn () { | ||
return cy.get('[name=commit]') | ||
} | ||
} | ||
|
||
export default SignInPage |
Oops, something went wrong.