Skip to content

Commit

Permalink
Add alternative POM example
Browse files Browse the repository at this point in the history
  • Loading branch information
Maximilian Bels committed Jul 7, 2024
1 parent abe473f commit 7fef85e
Show file tree
Hide file tree
Showing 4 changed files with 188 additions and 0 deletions.
91 changes: 91 additions & 0 deletions cypress/e2e/FunctionLibraries/LoginIntercepts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
class LoginIntercepts {

registerInvalidAccountRequestAs(responseName: string) {
cy.intercept("POST", `**/login/111111`, {
statusCode: 404,
body: {
timestamp: "May 20, 2024, 6:43:31 PM",
status: 404,
error: "Not Found",
message: "404 NOT_FOUND",
path: "/api/contracts/login/111111"
}
}).as(responseName);
}

registerFaultyLoginOn(userId: string) {
cy.intercept("POST", `**/login/${userId}`, {
statusCode: 400,
body: {
error: {
error: "BadCredentials"
}
}
}).as("failedLoginRequest");
}

registerExemplaryLoginAs(asPrefix: string, responseName: string) {
cy.intercept("POST", `**/login/${responseName}`, {
statusCode: 200,
body: {
result: "eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIyNSIsImlhdCI6MTcxNDY1NDI5Nn0.7RvioDzaHM9nEMP3imlBghveUetX3dRiLYUXZW-9Pd71y7pmA2Bh2uBPXAwZ96GEztgDJ-jAdu9O3Af9aAyJGg"
}
}).as(asPrefix + responseName);
}

interceptAccountDetailsAfterSuccessfulLoginAs(responseName: string) {
cy.intercept("GET", "**/api/contracts", {
statusCode: 200,
body: {
id: {
counter: 7,
parent: 33,
child: 0
},
customer: {
type: "com.simplytest.core.customers.CustomerPrivate",
data: {
birthDay: "Oct 10, 1980, 12:00:00 AM",
schufaScore: 0.0,
transactionFee: 0.0,
monthlyFee: 2.99,
firstName: "Max",
lastName: "Wendeley",
address: {
country: "Deutschland",
zipCode: "897897",
street: "Hauptstraße",
house: "1",
city: "Musterstadt",
email: "[email protected]"
}
}
},
accounts: {
"00033:00001": {
type: "com.simplytest.core.accounts.AccountGiro",
data: {
sendLimit: 3000.0,
dispoLimit: 0.0,
dispoRate: 0.0,
balance: 9000.0,
boundPeriod: 0.0,
interestRate: 0.0
}
},
"00033:00007": {
type: "com.simplytest.core.accounts.AccountFixedRate",
data: {
runtime: 0.0,
balance: 1000.0,
boundPeriod: 0.0,
interestRate: 0.0
}
}
}
}
}).as(responseName);
}
}

export default new LoginIntercepts();
27 changes: 27 additions & 0 deletions cypress/e2e/FunctionLibraries/ResponseUtility.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
class ResponseUtility {

waitForInvalidAccountOn(requestName: string) {
cy.wait("@" + requestName).then((interception) => {
expect(interception.response.statusCode).to.equal(404);
expect(interception.request.url).to.contain("/login/111111");
expect(interception.request.method).to.equal("POST");
});
}

waitForFailureOn(requestName: string) {
cy.wait("@" + requestName).then((interception) => {
expect(interception.response.statusCode).to.equal(400);
expect(interception.request.url).to.contain("/login/00033");
expect(interception.request.method).to.equal("POST");
});
}

waitForStatus200On(requestName: string) {
cy.wait("@" + requestName).then((interception) => {
expect(interception.response.statusCode).to.equal(200);
});
}

}

export default new ResponseUtility();
13 changes: 13 additions & 0 deletions cypress/e2e/PageObjects/DashboardPage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
class DashboardPage {

checkNoContractMessage() {
cy.get("dialog-contract-not-found").should("be.visible")
.and("contain.text", "Vertrag nicht gefunden!");
}
checkWelcomeMessage() {
cy.get('label[data-testid="customer_Label"]', { timeout: 10000 })
.should("contain.text", "Willkommen Max!");
}
checkForRedirectionAndAccountDetails() {
cy.url().should("include", "/mainPage");
}

locators = {
customerLabel: 'label[data-testid="customer_Label"]',
receiveMoneyButton: "button[id='0-empfangen']",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import LoginPage from "./PageObjects/LoginPage";
import DashboardPage from "./PageObjects/DashboardPage";
import LoginIntercepts from "./FunctionLibraries/LoginIntercepts";
import ResponseUtility from "./FunctionLibraries/ResponseUtility";

describe("Übung 4.2 - Anmeldung", () => {

beforeEach(() => {
// Visit the dashboard URL before each test
const dashboardUrl = "http://localhost:4200/dashboard";
cy.visit(dashboardUrl);
cy.url().should("eq", dashboardUrl);

LoginIntercepts.interceptAccountDetailsAfterSuccessfulLoginAs("contractsRequest");
});

it("Erfolgreiche Anmeldung", () => {

LoginIntercepts.registerExemplaryLoginAs("loginRequest", "00025");

LoginPage.login("00025", "admin");
ResponseUtility.waitForStatus200On("loginRequest00025");

DashboardPage.checkForRedirectionAndAccountDetails();
ResponseUtility.waitForStatus200On("contractsRequest");
DashboardPage.checkWelcomeMessage();
});

it("Erfolgreiche Anmeldung mit anderen Nutzerdaten", () => {

LoginIntercepts.registerExemplaryLoginAs("loginRequest", "00026");

LoginPage.login("00026", "password");
ResponseUtility.waitForStatus200On("loginRequest00026");
DashboardPage.checkForRedirectionAndAccountDetails();

ResponseUtility.waitForStatus200On("contractsRequest");
DashboardPage.checkWelcomeMessage();
});

it("Gescheiterte Anmeldung mit korrektem Vertragscode und falschem Passwort", () => {

LoginIntercepts.registerFaultyLoginOn("00033");

LoginPage.login("00033", "123456");
ResponseUtility.waitForFailureOn("failedLoginRequest");
DashboardPage.checkNoContractMessage();
});

it("Gescheiterte Anmeldung mit ungültigem Vertragscode", () => {

LoginIntercepts.registerInvalidAccountRequestAs("invalidAccountRequest");
LoginPage.login("111111", "1212");
ResponseUtility.waitForInvalidAccountOn("invalidAccountRequest");
DashboardPage.checkNoContractMessage();
});
});

0 comments on commit 7fef85e

Please sign in to comment.