Skip to content

Commit

Permalink
add gmail-tester and prepare S3 config
Browse files Browse the repository at this point in the history
  • Loading branch information
riccardogiorato committed Aug 29, 2021
1 parent 54ff17b commit 563d462
Show file tree
Hide file tree
Showing 7 changed files with 330 additions and 15 deletions.
13 changes: 9 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,26 @@ on:
branches:
- main

env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
CYPRESS_CACHE_FOLDER: ./.cache/Cypress

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}

jobs:
build:
name: Build and Install ⚙️
runs-on: ubuntu-latest
env:
CYPRESS_CACHE_FOLDER: ./.cache/Cypress
steps:
- name: Checkout 🛎️
uses: actions/checkout@v2

- name: Download Config from S3 📥
run: aws s3 sync s3://cypress-for-everything ./

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
Expand Down Expand Up @@ -66,8 +73,6 @@ jobs:
name: Test Cypress 🤖
runs-on: ubuntu-latest
needs: build
env:
CYPRESS_CACHE_FOLDER: ./.cache/Cypress
steps:
- name: Restore Cache 💾
uses: actions/cache@v2
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,6 @@ report/*.xml
report.xml

cypress/videos/*.*
cypress/screenshots/*.*
cypress/screenshots/*.*
cypress/plugins/credentials.json
cypress/plugins/token.json
33 changes: 33 additions & 0 deletions cypress/integration/tesla-form.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
describe("Tesla Newsletter Form", async function () {
const test_id = new Date().getTime();
const fake_email = `fake.email.cypress4everything+${test_id}@gmail.com`;

it("Newsletter Form: Email is submitted from UI to server!", function () {
cy.visit("https://www.tesla.com/updates");
cy.wait(2000);
cy.get(".tds-modal-close > .tds-icon").click({
force: true,
});

cy.contains("Stay Connected");

cy.get('body input[name="/firstName"]').type(`name ${test_id}`);
cy.get('body input[name="/lastName"]').type(`name ${test_id}`);

cy.get('body input[name="/email"]').type(fake_email);

cy.get('body input[name="/zip"]').type(test_id.toString());

cy.get("fieldset input[id='/productInterested_Model S']").click();
cy.get("fieldset input[id='/productInterested_Model 3']").click();
cy.get("fieldset input[id='/productInterested_Model X']").click();
cy.get("fieldset input[id='/productInterested_Model Y']").click();

cy.get('body button[type="submit"]').within(($button) => {
cy.wrap($button).should("have.text", "Submit");
cy.wrap($button).click();
});
cy.contains("Thank you");
cy.contains("We'll notify you of any product updates, news or events.");
});
});
30 changes: 30 additions & 0 deletions cypress/plugins/gmailCheck.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const path = require("path");
const gmail = require("gmail-tester");

export interface GmailCheckParam {
from: string;
to: string;
subject: string;
}

// node ..\..\node_modules\gmail-tester\init.js ./credentials.json token.json [email protected]

export const gmailCheck = async ({
from,
to,
subject,
}: GmailCheckParam): Promise<void> => {
const email = await gmail.check_inbox(
path.resolve(__dirname, "credentials.json"), // credentials.json is inside plugins/ directory.
path.resolve(__dirname, "token.json"), // token.json is inside plugins/ directory.
{
subject: subject,
from: from,
to: to,
wait_time_sec: 5, // Poll interval (in seconds).
max_wait_time_sec: 30, // Maximum poll time (in seconds), after which we'll giveup.
include_body: true,
}
);
return email;
};
7 changes: 7 additions & 0 deletions cypress/plugins/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { gmailCheck, GmailCheckParam } from "./gmailCheck";
import {
structuredData,
StructuredDataParam,
Expand All @@ -19,4 +20,10 @@ module.exports = (on, config) => {
return await structuredData(param);
},
});

on("task", {
async gmailCheck(args: GmailCheckParam) {
return await gmailCheck(args);
},
});
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
},
"dependencies": {
"cypress": "^8.3.1",
"gmail-tester": "^1.3.2",
"junit-report-merger": "^3.0.1",
"structured-data-testing-tool": "^4.5.0",
"xml-js": "^1.6.11"
Expand Down
Loading

0 comments on commit 563d462

Please sign in to comment.