Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Web Automation Testing Setup #556

Merged
merged 36 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
8e86279
feat(cypress-tests): setting up automation testing in web
Aug 6, 2024
121b9ee
refactor: remove keys
Aug 7, 2024
0cef597
refactor: change folder structure to not run failing cases
Aug 7, 2024
64dfec6
fix: merge with main
Aug 7, 2024
e66d50d
feat: github action to run tests
Aug 7, 2024
5b5efdf
refactor: refactor github action
Aug 7, 2024
150a60e
fix: fix bug on last commit
Aug 7, 2024
0e3f324
fix: fix bug on last commit
Aug 7, 2024
c765949
fix: trailing comma in pkg.json
Aug 7, 2024
2f4d729
fix: github action to run the command
Aug 7, 2024
634bbaa
chore: setting up actions for automation testing
Aug 7, 2024
da1a963
chore: add caching to npm in action
Aug 7, 2024
486ef8e
chore: add pkg lock to run actions
Aug 7, 2024
d8f4b06
refactor: scripts, readme, ignore screenshots
Aug 8, 2024
0eb3a5d
refactor: readme to accomodate cypress first time install
Aug 8, 2024
59ab302
feat(github-actions): add action to configure env variables
Aug 12, 2024
f205dd9
refactor(git-actions): add env file config before server start
Aug 12, 2024
1bd729c
fix: fix env creation action
Aug 12, 2024
830b14b
fix: debug faling iframe loader
Aug 12, 2024
d9d8e7c
fix(git-actions): add env for given variable | remove console
Aug 12, 2024
70466dc
fix(git-actions): place env correctly
Aug 12, 2024
bcfe605
chore(git-actions): trying out git actions
Aug 12, 2024
00b959d
fix(git-actions): add mandatory step to test
Aug 12, 2024
5cd1124
chore(git-actions): git and trial
Aug 12, 2024
e4c1431
chore(gi-actions): gettin env variables
Aug 12, 2024
97edcbf
chore(actions): trial git actions
Aug 12, 2024
ff6ee0d
fix(github-actions): fix for github actions
Aug 12, 2024
f6dacfc
refactor(setup-git-actions-for automation): remove redundant steps, t…
Aug 12, 2024
0867ec8
feat(git-actions): testing framework finish set up
Aug 12, 2024
3240993
chore(merge): merge with main
Aug 12, 2024
2c55bef
fix(git-actions): add final steps to make the action run post enable
Aug 12, 2024
904b822
Merge branch 'main' into swamu/526-web-testing-automation
swamu Aug 12, 2024
2fff691
refactor(.vscode): remove unecessary extension
Aug 12, 2024
233577a
Merge branch 'swamu/526-web-testing-automation' of https://github.com…
Aug 12, 2024
68a2d71
Merge branch 'main' into swamu/526-web-testing-automation
Aug 12, 2024
54679a5
chore(checkoutform): remove extra demo code
Aug 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions .github/workflows/run-automation-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Run Cypress Tests

on:
pull_request:
merge_group:
push:
branches:
- main

jobs:
cypress:
runs-on: ubuntu-latest
environment: Testing
env:
HS_Pub_Key: ${{ secrets.HYPERSWITCH_PUBLISHABLE_KEY }}
HS_Sec_Key: ${{ secrets.HYPERSWITCH_SECRET_KEY }}
HS_Prof_Id: ${{ secrets.PROFILE_ID }}
HS_Server_Url: "https://sandbox.hyperswitch.io"
HS_Client_Url: "http://localhost:9050"
# Environment variables for Hyperswitch credentials and URLs

steps:
- name: Checkout repository
uses: actions/checkout@v3
# Checks out the repository so that the workflow can access the code

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: "20" # Specifies the version of Node.js to use
cache: "npm" # Caches npm dependencies to speed up subsequent installs

- name: Install dependencies
run: npm install
# Installs the necessary npm dependencies for the project

- name: Create .env file
working-directory: ./Hyperswitch-React-Demo-App
run: |
touch .env
echo STATIC_DIR = ./dist >> .env
echo HYPERSWITCH_PUBLISHABLE_KEY = $HS_Pub_Key >> .env
echo HYPERSWITCH_SECRET_KEY = $HS_Sec_Key >> .env
echo PROFILE_ID = $HS_Prof_Id >> .env
echo HYPERSWITCH_SERVER_URL = $HS_Server_Url >> .env
echo HYPERSWITCH_CLIENT_URL = $HS_Client_Url >> .env
# Creates a .env file with environment variables needed for the application

- name: Build and start local server
run: |
npm run re:build && npm start &
echo "Hyperswitch Web started" && cd Hyperswitch-React-Demo-App && npm start &
echo "Demo App started"
# Builds the project and starts both the Hyperswitch Web and Demo App servers in the background

- name: Run Cypress
uses: cypress-io/github-action@v6
with:
working-directory: ./cypress-tests
# Runs Cypress tests located in the specified directory
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public/app.css
/dist/
**/*.bs.js
.github/CODEOWNERS
screenshots
!cypress-tests/package-lock.json

# yarn
.pnp.*
Expand Down
3 changes: 0 additions & 3 deletions .vscode/settings.json

This file was deleted.

2 changes: 1 addition & 1 deletion Hyperswitch-React-Demo-App/.env
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ HYPERSWITCH_SECRET_KEY=
HYPERSWITCH_SERVER_URL=
HYPERSWITCH_CLIENT_URL=
SELF_SERVER_URL=

PROFILE_ID=""
115 changes: 61 additions & 54 deletions Hyperswitch-React-Demo-App/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,63 +39,70 @@ app.get("/urls", (req, res) => {
});
});

function createPaymentRequest() {
return {
currency: "USD",
amount: 2999,
order_details: [
{
product_name: "Apple iPhone 15",
quantity: 1,
amount: 2999,
},
],
confirm: false,
capture_method: "automatic",
authentication_type: "three_ds",
customer_id: "hyperswitch_sdk_demo_id",
email: "[email protected]",
description: "Hello this is description",
shipping: {
address: {
line1: "1467",
line2: "Harrison Street",
line3: "Harrison Street",
city: "San Fransico",
state: "California",
zip: "94122",
country: "US",
first_name: "joseph",
last_name: "Doe",
},
phone: {
number: "8056594427",
country_code: "+91",
},
const paymentData = {
currency: "USD",
amount: 2999,
order_details: [
{
product_name: "Apple iPhone 15",
quantity: 1,
amount: 2999,
},
metadata: {
udf1: "value1",
new_customer: "true",
login_date: "2019-09-10T10:11:12Z",
],
confirm: false,
capture_method: "automatic",
authentication_type: "three_ds",
customer_id: "hyperswitch_sdk_demo_id",
email: "[email protected]",
description: "Hello this is description",
shipping: {
address: {
line1: "1467",
line2: "Harrison Street",
line3: "Harrison Street",
city: "San Fransico",
state: "California",
zip: "94122",
country: "US",
first_name: "joseph",
last_name: "Doe",
},
billing: {
address: {
line1: "1467",
line2: "Harrison Street",
line3: "Harrison Street",
city: "San Fransico",
state: "California",
zip: "94122",
country: "US",
first_name: "joseph",
last_name: "Doe",
},
phone: {
number: "8056594427",
country_code: "+91",
},
phone: {
number: "8056594427",
country_code: "+91",
},
},
metadata: {
udf1: "value1",
new_customer: "true",
login_date: "2019-09-10T10:11:12Z",
},
billing: {
address: {
line1: "1467",
line2: "Harrison Street",
line3: "Harrison Street",
city: "San Fransico",
state: "California",
zip: "94122",
country: "US",
first_name: "joseph",
last_name: "Doe",
},
};
phone: {
number: "8056594427",
country_code: "+91",
},
},
}

const profileId = process.env.PROFILE_ID;
if(profileId) {
paymentData.profile_id = profileId;
}

function createPaymentRequest() {
return paymentData;
}

app.get("/create-payment-intent", async (_, res) => {
Expand Down
Empty file added cypress-tests/.env
Empty file.
10 changes: 10 additions & 0 deletions cypress-tests/cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const { defineConfig } = require("cypress");

module.exports = defineConfig({
projectId: "6r9ayw",
chromeWebSecurity: false,
e2e: {
baseUrl: "http://localhost:9050",
},
retries: { runMode: 1, openMode: 1 },
});
47 changes: 47 additions & 0 deletions cypress-tests/cypress/e2e/card-flow-e2e-test.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import * as testIds from "../../../src/Utilities/TestUtils.bs";
import { CLIENT_URL } from "../support/utils";

describe("Card payment flow test", () => {
let getIframeBody : () => Cypress.Chainable<JQuery<HTMLBodyElement>>;
let iframeSelector =
"#orca-payment-element-iframeRef-orca-elements-payment-element-payment-element";
beforeEach(() => {
getIframeBody = () => cy.iframe(iframeSelector);

cy.visit(CLIENT_URL);
});

it("page loaded successfully", () => {
cy.visit(CLIENT_URL);
});

it("title rendered correctly", () => {
cy.contains("Hyperswitch Unified Checkout").should("be.visible");
});

it("orca-payment-element iframe loaded", () => {
cy.get(
"#orca-payment-element-iframeRef-orca-elements-payment-element-payment-element"
)
.should("be.visible")
.its("0.contentDocument")
.its("body");
});

it('should check if cards are saved', () => {
// Visit the page where the test will be performed
cy.visit(CLIENT_URL);

getIframeBody().find(`[data-testid=${testIds.addNewCardIcon}]`)
.then($element => {
if ($element.length > 0) {
getIframeBody().find('[data-testid=cvvInput]').type('123');
getIframeBody().get("#submit").click();
cy.wait(2000);
cy.contains("Thanks for your order!").should("be.visible");
} else {
cy.log(' new card card flow');
}
});
});
});
9 changes: 9 additions & 0 deletions cypress-tests/cypress/fixtures/paymentMethods.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"card":"Card",
"klarna":"Klarna",
"affirm":"Affirm",
"aliPay":"Ali Pay",
"weChatPay":"WeChat"

}

15 changes: 15 additions & 0 deletions cypress-tests/cypress/fixtures/testCustomer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"cardNo":"4242 4242 4242 4242",
"threeDSCardNo":"4000000000003220",
"cardExpiry":"04/24",
"cardCVV":"424",
"billingName":"Arun Mishra",
"cardHolderName":"Arun Mishra",
"email":"[email protected]",
"address":"123 Main Street Apt 4B",
"city":"New York",
"country":"United States",
"state":"New York",
"postalCode":"10001",
"paymentSuccessfulText":"Payment successful"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import * as testIds from "../../src/Utilities/TestUtils.bs";
describe("affirm payment flow test", () => {
let customerData;
let paymentMethodsData;
beforeEach(() => {
cy.visit("http://localhost:9060");

cy.wrap(
Cypress.automation("remote:debugger:protocol", {
command: "Network.clearBrowserCache",
})
);

cy.fixture("testCustomer").then((customer) => {
customerData = customer;
});
cy.fixture("paymentMethods").then((paymentMethods) => {
paymentMethodsData = paymentMethods;
});
});
it("page loaded successfully", () => {
cy.visit("http://localhost:9060");
});
it("title rendered correctly", () => {
cy.contains("Hyperswitch Unified Checkout").should("be.visible");
});

it("orca-payment-element iframe loaded", () => {
cy.get(
"#orca-payment-element-iframeRef-orca-elements-payment-element-payment-element"
)
.should("be.visible")
.its("0.contentDocument")
.its("body");
});
it("affirm payment flow successful", () => {
let iframeSelector =
"#orca-payment-element-iframeRef-orca-elements-payment-element-payment-element";

cy.frameLoaded(iframeSelector);
cy.wait(2000);

cy.iframe(iframeSelector)
.find(`[data-testid=${testIds.paymentMethodListTestId}]`)
.should("be.visible")
.contains(paymentMethodsData.affirm)
.click();

cy.get("#submit").click();

cy.url().should("include", "sandbox.hyperswitch");
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import * as testIds from "../../src/Utilities/TestUtils.bs";
describe("Ali Pay payment flow test", () => {
let customerData;
let paymentMethodsData;
beforeEach(() => {
// cy.visit("http://localhost:9060", { cache: false });
cy.visit("http://localhost:9060");

cy.wrap(
Cypress.automation("remote:debugger:protocol", {
command: "Network.clearBrowserCache",
})
);
cy.fixture("testCustomer").then((customer) => {
customerData = customer;
});
cy.fixture("paymentMethods").then((paymentMethods) => {
paymentMethodsData = paymentMethods;
});
});
it("page loaded successfully", () => {
cy.visit("http://localhost:9060");
});
it("title rendered correctly", () => {
cy.contains("Hyperswitch Unified Checkout").should("be.visible");
});

it("orca-payment-element iframe loaded", () => {
cy.get(
"#orca-payment-element-iframeRef-orca-elements-payment-element-payment-element"
)
.should("be.visible")
.its("0.contentDocument")
.its("body");
});
it("ali pay payment flow successful", () => {
let iframeSelector =
"#orca-payment-element-iframeRef-orca-elements-payment-element-payment-element";
cy.frameLoaded(iframeSelector);
cy.wait(2000);
cy.iframe(iframeSelector)
.find(`[data-testid=${testIds.paymentMethodDropDownTestId}]`)
.should("be.visible")
.select(paymentMethodsData.aliPay);

cy.get("#submit").click();

cy.url().should("include", "sandbox.hyperswitch");
});
});
Loading
Loading