-
Notifications
You must be signed in to change notification settings - Fork 0
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
Maximilian Bels
committed
Jul 7, 2024
1 parent
abe473f
commit 7fef85e
Showing
4 changed files
with
188 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,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(); |
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,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(); |
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
57 changes: 57 additions & 0 deletions
57
cypress/e2e/Übung 08 (Alternative) - Tests strukturieren (POM).spec.ts
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,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(); | ||
}); | ||
}); |