Skip to content

Commit f0ac89e

Browse files
authored
Merge pull request #388 from awslabs/dev
Merge Dev Branch: Setup E2E Test
2 parents 4b0eec8 + eb5afc3 commit f0ac89e

File tree

11 files changed

+5112
-405
lines changed

11 files changed

+5112
-405
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,7 @@ amplifyconfiguration.json
3939
amplify-build-config.json
4040
amplify-gradle-config.json
4141
amplifyxc.config
42+
43+
# Cypress
44+
cypress/videos
45+
cypress/screenshots

Documentation/UserDocumentation.md

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,32 @@ __[User Documentation](UserDocumentation.md)__ / [Client Developer Documentation
33
# User Documentation <!-- omit in toc -->
44

55
- [Presentation](#presentation)
6-
- [Choose your flow](#choose-your-flow)
7-
- [Difference with the OIDC standard](#difference-with-the-oidc-standard)
6+
- [Choose your flow](#choose-your-flow)
7+
- [Difference with the OIDC standard](#difference-with-the-oidc-standard)
88
- [Deployment](#deployment)
9-
- [Architecture](#architecture)
10-
- [Deployment Instructions](#deployment-instructions)
9+
- [Architecture](#architecture)
10+
- [Deployment Instructions](#deployment-instructions)
1111
- [Deploying with the AWS Amplify console](#deploying-with-the-aws-amplify-console)
12-
- [Step 1: Environment Variables|](#step-1-environment-variables)
13-
- [Step 2: Redirect rules](#step-2-redirect-rules)
14-
- [Step 3: Configure domain (mandatory)](#step-3-configure-domain-mandatory)
12+
- [Step 1: Environment Variables|](#step-1-environment-variables)
13+
- [Step 2: Redirect rules](#step-2-redirect-rules)
14+
- [Step 3: Configure domain (mandatory)](#step-3-configure-domain-mandatory)
15+
- [Step 4: E2E Test (Optional)](#step-4-e2e-test-optional)
1516
- [Register a client](#register-a-client)
1617
- [CSS & UI components customization instruction](#css--ui-components-customization-instruction)
1718
- [Identity Providers](#identity-providers)
18-
- [OIDC Provider (oauth2)](#oidc-provider-oauth2)
19-
- [SAML Provider](#saml-provider)
20-
- [Social Providers](#social-providers)
21-
- [Step 1: Register with Facebook to get a App ID and App Secret](#step-1-register-with-facebook-to-get-a-app-id-and-app-secret)
22-
- [Step 2: Finish registering with Facebook](#step-2-finish-registering-with-facebook)
23-
- [Step 1: Register with Google to get a OAuth client ID and client secret](#step-1-register-with-google-to-get-a-oauth-client-id-and-client-secret)
24-
- [Step 2: Finish registering with Google](#step-2-finish-registering-with-google)
25-
- [Step 1: Register with Amazon to get a Client ID and Client Secret](#step-1-register-with-amazon-to-get-a-client-id-and-client-secret)
26-
- [Step 2: Finish registering with Amazon](#step-2-finish-registering-with-amazon)
19+
- [OIDC Provider (oauth2)](#oidc-provider-oauth2)
20+
- [SAML Provider](#saml-provider)
21+
- [Social Providers](#social-providers)
22+
- [Step 1: Register with Facebook to get a App ID and App Secret](#step-1-register-with-facebook-to-get-a-app-id-and-app-secret)
23+
- [Step 2: Finish registering with Facebook](#step-2-finish-registering-with-facebook)
24+
- [Step 1: Register with Google to get a OAuth client ID and client secret](#step-1-register-with-google-to-get-a-oauth-client-id-and-client-secret)
25+
- [Step 2: Finish registering with Google](#step-2-finish-registering-with-google)
26+
- [Step 1: Register with Amazon to get a Client ID and Client Secret](#step-1-register-with-amazon-to-get-a-client-id-and-client-secret)
27+
- [Step 2: Finish registering with Amazon](#step-2-finish-registering-with-amazon)
2728
- [Migration instructions](#migration-instructions)
2829
- [Uninstall](#uninstall)
29-
- [Step 1 : stack deletion](#step-1--stack-deletion)
30-
- [Step 2 : delete the user pool](#step-2--delete-the-user-pool)
30+
- [Step 1 : stack deletion](#step-1--stack-deletion)
31+
- [Step 2 : delete the user pool](#step-2--delete-the-user-pool)
3132

3233
This document explains how to use the broker:
3334

@@ -325,6 +326,24 @@ amplify push --force
325326

326327
_To verify if the change have been propagated you can open one of the AWS Lambda within the AWS console and look at the value of the environment variable `HOSTING_DOMAIN`_
327328

329+
### Step 4: E2E Test (Optional)
330+
331+
This project is setup with End-to-end Testing with [Cypress](https://docs.aws.amazon.com/amplify/latest/userguide/running-tests.html).
332+
333+
If you use Amplify CICD Integration, you must either setup necessary step for testing or disable testing. You may only run test on specific branch.
334+
335+
__Option 1: Setup Testing__
336+
337+
1. Visit Cognito Console.
338+
2. Create a test user.
339+
3. Login with the test user and set the password.
340+
4. Add the test user email and password as `CYPRESS_EMAIL` and `CYPRESS_PASSWORD` in Amplify Environment Variable.
341+
5. When test locally, run `npx cypress run --env EMAIL=<email>,PASSWORD=<password>`
342+
343+
__Option 2: Disable Testing__
344+
345+
1. Set Amplify Environment Variable `USER_DISABLE_TESTS` to `true` on branch. Visit [Amplify Documentation](https://docs.aws.amazon.com/amplify/latest/userguide/running-tests.html#disabling-tests) for more detail.
346+
328347
## Register a client
329348

330349
To use the identity broker you must:

amplify.yml

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,40 @@
11
version: 1
22
backend:
3-
phases:
4-
build:
5-
commands:
6-
- '# Execute Amplify CLI with the helper script'
7-
- amplifyPush --simple
3+
phases:
4+
build:
5+
commands:
6+
- "# Execute Amplify CLI with the helper script"
7+
- amplifyPush --simple
88
frontend:
9-
phases:
10-
preBuild:
11-
commands:
12-
- npm ci
13-
build:
14-
commands:
15-
- npm run build
16-
artifacts:
17-
baseDirectory: build
18-
files:
19-
- '**/*'
20-
cache:
21-
paths:
22-
- node_modules/**/*
9+
phases:
10+
preBuild:
11+
commands:
12+
- npm ci
13+
build:
14+
commands:
15+
- npm run build
16+
artifacts:
17+
baseDirectory: build
18+
files:
19+
- "**/*"
20+
cache:
21+
paths:
22+
- node_modules/**/*
23+
test:
24+
artifacts:
25+
baseDirectory: cypress
26+
configFilePath: "**/mochawesome.json"
27+
files:
28+
- "**/*.png"
29+
- "**/*.mp4"
30+
phases:
31+
preTest:
32+
commands:
33+
- yarn install
34+
- yarn add mocha mochawesome mochawesome-merge mochawesome-report-generator
35+
test:
36+
commands:
37+
- npx start-test 'yarn start' 3000 'npx cypress run --reporter mochawesome --reporter-options "reportDir=cypress/report/mochawesome-report,overwrite=false,html=false,json=true,timestamp=mmddyyyy_HHMMss"'
38+
postTest:
39+
commands:
40+
- npx mochawesome-merge cypress/report/mochawesome-report/mochawesome*.json > cypress/report/mochawesome.json

cypress.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"baseUrl": "http://localhost:3000",
3+
"includeShadowDom": true
4+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
describe('Authenticator:', function () {
2+
beforeEach(function () {
3+
cy.visit('/');
4+
});
5+
describe('Sign In:', () => {
6+
it('allows a user to signin', () => {
7+
cy.get(selectors.emailInput).type(Cypress.env('EMAIL'));
8+
cy.get(selectors.signInPasswordInput).type(Cypress.env('PASSWORD'));
9+
cy.get(selectors.signInSignInButton).contains('Sign In').click();
10+
cy.wait(3000)
11+
cy.get(selectors.root).contains('Amplify Identity Broker');
12+
});
13+
});
14+
});
15+
export const selectors = {
16+
emailInput: '[data-test="sign-in-email-input"]',
17+
signInPasswordInput: '[data-test="sign-in-password-input"]',
18+
signInSignInButton: '[data-test="sign-in-sign-in-button"]',
19+
root: '#root'
20+
};

cypress/plugins/index.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/// <reference types="cypress" />
2+
// ***********************************************************
3+
// This example plugins/index.js can be used to load plugins
4+
//
5+
// You can change the location of this file or turn off loading
6+
// the plugins file with the 'pluginsFile' configuration option.
7+
//
8+
// You can read more here:
9+
// https://on.cypress.io/plugins-guide
10+
// ***********************************************************
11+
12+
// This function is called when a project is opened or re-opened (e.g. due to
13+
// the project's config changing)
14+
15+
/**
16+
* @type {Cypress.PluginConfig}
17+
*/
18+
module.exports = (on, config) => {
19+
// `on` is used to hook into various events Cypress emits
20+
// `config` is the resolved Cypress config
21+
}

cypress/support/commands.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// ***********************************************
2+
// This example commands.js shows you how to
3+
// create various custom commands and overwrite
4+
// existing commands.
5+
//
6+
// For more comprehensive examples of custom
7+
// commands please read more here:
8+
// https://on.cypress.io/custom-commands
9+
// ***********************************************
10+
//
11+
//
12+
// -- This is a parent command --
13+
// Cypress.Commands.add("login", (email, password) => { ... })
14+
//
15+
//
16+
// -- This is a child command --
17+
// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
18+
//
19+
//
20+
// -- This is a dual command --
21+
// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
22+
//
23+
//
24+
// -- This will overwrite an existing command --
25+
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })

cypress/support/index.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// ***********************************************************
2+
// This example support/index.js is processed and
3+
// loaded automatically before your test files.
4+
//
5+
// This is a great place to put global configuration and
6+
// behavior that modifies Cypress.
7+
//
8+
// You can change the location of this file or turn off
9+
// automatically serving support files with the
10+
// 'supportFile' configuration option.
11+
//
12+
// You can read more here:
13+
// https://on.cypress.io/configuration
14+
// ***********************************************************
15+
16+
// Import commands.js using ES2015 syntax:
17+
import './commands'
18+
19+
// Alternatively you can use CommonJS syntax:
20+
// require('./commands')

0 commit comments

Comments
 (0)