From 081984c3413c1197f3207169a4cfe7b17b2c352a Mon Sep 17 00:00:00 2001 From: ChrissyDev Date: Mon, 18 Mar 2024 17:44:08 +0200 Subject: [PATCH 1/8] check --- cypress/e2e/modal-and-overlays/dialog.spec.js | 14 ++++++++ cypress/e2e/stepper/stepperHomework.spec.js | 13 +++++++ .../e2e/tables-and-data/smart-tables.spec.js | 35 +++++++++++++++++++ package-lock.json | 8 ++--- package.json | 2 +- 5 files changed, 67 insertions(+), 5 deletions(-) create mode 100644 cypress/e2e/modal-and-overlays/dialog.spec.js create mode 100644 cypress/e2e/stepper/stepperHomework.spec.js create mode 100644 cypress/e2e/tables-and-data/smart-tables.spec.js diff --git a/cypress/e2e/modal-and-overlays/dialog.spec.js b/cypress/e2e/modal-and-overlays/dialog.spec.js new file mode 100644 index 0000000..f4233e4 --- /dev/null +++ b/cypress/e2e/modal-and-overlays/dialog.spec.js @@ -0,0 +1,14 @@ +describe("Dialog page functionality", () => { + it("Opening 'Enter your name' modal window", () => { + cy.visit("/pages/modal-overlays/dialog"); + cy.get(".result-from-dialog").find("button").click(); + cy.get(".ng-star-inserted > nb-card") + .should("be.visible") + .within(() => { + cy.get("nb-card-header").should("contain", "Enter your name"); + cy.get("nb-card-body > .size-medium").should("exist"); + cy.get(".cancel").should("be.visible"); + cy.get(".status-success").should("be.visible"); + }); + }); + }); \ No newline at end of file diff --git a/cypress/e2e/stepper/stepperHomework.spec.js b/cypress/e2e/stepper/stepperHomework.spec.js new file mode 100644 index 0000000..78de184 --- /dev/null +++ b/cypress/e2e/stepper/stepperHomework.spec.js @@ -0,0 +1,13 @@ +describe("stepper functionality", () => { + it("after click on next button moves to following step", () => { + const stepperSelector = ".col-lg-12 > nb-card-body"; + cy.visit("/pages/layout/stepper"); + cy.get(`${stepperSelector} h3`).contains("Step content #1"); + cy.get(`${stepperSelector} button`).contains("next").click(); + cy.get(`${stepperSelector} h3`).contains("Step content #2"); + cy.get(`${stepperSelector} button`).contains("next").click(); + cy.get(`${stepperSelector} h3`).contains("Step content #3"); + cy.get(`${stepperSelector} button`).contains("next").click(); + cy.get(`${stepperSelector} h3`).contains("Step content #4"); + }); + }); \ No newline at end of file diff --git a/cypress/e2e/tables-and-data/smart-tables.spec.js b/cypress/e2e/tables-and-data/smart-tables.spec.js new file mode 100644 index 0000000..969e241 --- /dev/null +++ b/cypress/e2e/tables-and-data/smart-tables.spec.js @@ -0,0 +1,35 @@ +describe("Smart tables functionality", () => { + it("Creates new user and checks if its added to the table", () => { + cy.visit("pages/tables/smart-table"); + cy.get(".ng2-smart-actions-title").should("be.visible").click(); + cy.get('[ng2-st-thead-form-row=""] > :nth-child(2)').should("be.visible").type("1"); + cy.get('[ng2-st-thead-form-row=""] > :nth-child(3)').should("be.visible").type("Jeri"); + cy.get('[ng2-st-thead-form-row=""] > :nth-child(4)').should("be.visible").type("Lennit"); + cy.get('[ng2-st-thead-form-row=""] > :nth-child(5)').should("be.visible").type("JerLen"); + cy.get('[ng2-st-thead-form-row=""] > :nth-child(6)').should("be.visible").type("JeriLennit@gmail.com"); + cy.get('[ng2-st-thead-form-row=""] > :nth-child(7)').should("be.visible").type("21"); + cy.get('.nb-checkmark').click(); + + //it("Filters created user") + cy.get('.ng2-smart-filters > .id').should("be.visible").type("1"); + cy.get('.ng2-smart-filters > .firstName').should("be.visible").type("Jeri") + cy.get('.ng2-smart-filters > .lastName').should("be.visible").type("Lennit") + cy.get('.ng2-smart-filters > .username').should("be.visible").type("JerLen") + cy.get('.ng2-smart-filters > .email').should("be.visible").type("JeriLennit@gmail.com") + cy.get('.ng2-smart-filters > .age').should("be.visible").type("21") + + //it("Filter check") + cy.get('.ng2-smart-row > :nth-child(2)') + cy.get('.ng2-smart-row > :nth-child(3)') + cy.get('.ng2-smart-row > :nth-child(4)') + cy.get('.ng2-smart-row > :nth-child(5)') + cy.get('.ng2-smart-row > :nth-child(6)') + cy.get('.ng2-smart-row > :nth-child(7)') + }); + }); + +// function generateRandomName() { +// const length = Math.floor(Math.random() * 7) + 3; +// const name = Array.from({ length }, () => String.fromCharCode(97 + Math.floor(Math.random() * 26))).join(''); +// return name; +// } \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 963a157..cf94e37 100644 --- a/package-lock.json +++ b/package-lock.json @@ -76,7 +76,7 @@ "@typescript-eslint/parser": "^5.43.0", "codelyzer": "^6.0.2", "conventional-changelog-cli": "1.3.4", - "cypress": "^13.6.6", + "cypress": "^13.7.0", "eslint": "^8.28.0", "husky": "0.13.3", "jasmine-core": "~3.6.0", @@ -12274,9 +12274,9 @@ "dev": true }, "node_modules/cypress": { - "version": "13.6.6", - "resolved": "https://registry.npmjs.org/cypress/-/cypress-13.6.6.tgz", - "integrity": "sha512-S+2S9S94611hXimH9a3EAYt81QM913ZVA03pUmGDfLTFa5gyp85NJ8dJGSlEAEmyRsYkioS1TtnWtbv/Fzt11A==", + "version": "13.7.0", + "resolved": "https://registry.npmjs.org/cypress/-/cypress-13.7.0.tgz", + "integrity": "sha512-UimjRSJJYdTlvkChcdcfywKJ6tUYuwYuk/n1uMMglrvi+ZthNhoRYcxnWgTqUtkl17fXrPAsD5XT2rcQYN1xKA==", "dev": true, "hasInstallScript": true, "dependencies": { diff --git a/package.json b/package.json index a1fc57d..27c00ed 100644 --- a/package.json +++ b/package.json @@ -97,7 +97,7 @@ "@typescript-eslint/parser": "^5.43.0", "codelyzer": "^6.0.2", "conventional-changelog-cli": "1.3.4", - "cypress": "^13.6.6", + "cypress": "^13.7.0", "eslint": "^8.28.0", "husky": "0.13.3", "jasmine-core": "~3.6.0", From 1d6a66a944ea2307b78aa40aebb3448f05d0198e Mon Sep 17 00:00:00 2001 From: ChrissyDev Date: Tue, 19 Mar 2024 09:52:07 +0200 Subject: [PATCH 2/8] homework 14 --- cypress/e2e/auth/login.spec.js | 11 +++++ .../e2e/tables-and-data/smart-tables.spec.js | 48 +++++++------------ cypress/page-Objects/AuthTab.js | 12 +++++ cypress/page-Objects/SmartTablePage.js | 44 +++++++++++++++++ cypress/support/commands.ts | 2 +- package-lock.json | 22 +++++++++ package.json | 2 + 7 files changed, 108 insertions(+), 33 deletions(-) create mode 100644 cypress/e2e/auth/login.spec.js create mode 100644 cypress/page-Objects/AuthTab.js create mode 100644 cypress/page-Objects/SmartTablePage.js diff --git a/cypress/e2e/auth/login.spec.js b/cypress/e2e/auth/login.spec.js new file mode 100644 index 0000000..b58f5d1 --- /dev/null +++ b/cypress/e2e/auth/login.spec.js @@ -0,0 +1,11 @@ +import AuthTab from "../../page-Objects/AuthTab.js"; + +const authTab = new AuthTab(); + +describe("Auth tab functionality", () => { + it("Login to dashboard", () => { + cy.visit("/auth/login"); + authTab.login(); + cy.url().should("eq", "http://localhost:4200/pages/dashboard") + }); + }); \ No newline at end of file diff --git a/cypress/e2e/tables-and-data/smart-tables.spec.js b/cypress/e2e/tables-and-data/smart-tables.spec.js index 969e241..6b12f26 100644 --- a/cypress/e2e/tables-and-data/smart-tables.spec.js +++ b/cypress/e2e/tables-and-data/smart-tables.spec.js @@ -1,35 +1,19 @@ -describe("Smart tables functionality", () => { - it("Creates new user and checks if its added to the table", () => { - cy.visit("pages/tables/smart-table"); - cy.get(".ng2-smart-actions-title").should("be.visible").click(); - cy.get('[ng2-st-thead-form-row=""] > :nth-child(2)').should("be.visible").type("1"); - cy.get('[ng2-st-thead-form-row=""] > :nth-child(3)').should("be.visible").type("Jeri"); - cy.get('[ng2-st-thead-form-row=""] > :nth-child(4)').should("be.visible").type("Lennit"); - cy.get('[ng2-st-thead-form-row=""] > :nth-child(5)').should("be.visible").type("JerLen"); - cy.get('[ng2-st-thead-form-row=""] > :nth-child(6)').should("be.visible").type("JeriLennit@gmail.com"); - cy.get('[ng2-st-thead-form-row=""] > :nth-child(7)').should("be.visible").type("21"); - cy.get('.nb-checkmark').click(); +import SmartTablePage from "../../page-Objects/SmartTablePage.js"; - //it("Filters created user") - cy.get('.ng2-smart-filters > .id').should("be.visible").type("1"); - cy.get('.ng2-smart-filters > .firstName').should("be.visible").type("Jeri") - cy.get('.ng2-smart-filters > .lastName').should("be.visible").type("Lennit") - cy.get('.ng2-smart-filters > .username').should("be.visible").type("JerLen") - cy.get('.ng2-smart-filters > .email').should("be.visible").type("JeriLennit@gmail.com") - cy.get('.ng2-smart-filters > .age').should("be.visible").type("21") +const smartTablePage = new SmartTablePage(); - //it("Filter check") - cy.get('.ng2-smart-row > :nth-child(2)') - cy.get('.ng2-smart-row > :nth-child(3)') - cy.get('.ng2-smart-row > :nth-child(4)') - cy.get('.ng2-smart-row > :nth-child(5)') - cy.get('.ng2-smart-row > :nth-child(6)') - cy.get('.ng2-smart-row > :nth-child(7)') - }); - }); +describe("Smart tables functionality", () => { + beforeEach(() => { + cy.visit("pages/tables/smart-table"); + }) -// function generateRandomName() { -// const length = Math.floor(Math.random() * 7) + 3; -// const name = Array.from({ length }, () => String.fromCharCode(97 + Math.floor(Math.random() * 26))).join(''); -// return name; -// } \ No newline at end of file + it("Creates new user and checks if it's added to the table", () => { + cy.get(".ng2-smart-actions-title").should("be.visible").click(); + const newUser = smartTablePage.createUser(); + smartTablePage.filterCreatedUser(newUser); + cy.get("tbody").should("be.visible").within(() => { + cy.get('.ng2-smart-row').should("have.length", 1); + smartTablePage.verifyCreatedUserData(newUser); + }) + }); +}) \ No newline at end of file diff --git a/cypress/page-Objects/AuthTab.js b/cypress/page-Objects/AuthTab.js new file mode 100644 index 0000000..661f781 --- /dev/null +++ b/cypress/page-Objects/AuthTab.js @@ -0,0 +1,12 @@ +import { faker } from '@faker-js/faker'; + +class AuthTab { + login() { + cy.get('#input-email').type(faker.internet.email()); + cy.get('#input-password').type(faker.internet.password()); + cy.get('.custom-checkbox').click(); + cy.get('.appearance-filled').click(); + } +} + +export default AuthTab; \ No newline at end of file diff --git a/cypress/page-Objects/SmartTablePage.js b/cypress/page-Objects/SmartTablePage.js new file mode 100644 index 0000000..6d58f7b --- /dev/null +++ b/cypress/page-Objects/SmartTablePage.js @@ -0,0 +1,44 @@ +import { faker } from '@faker-js/faker'; + +class SmartTablePage { + createUser() { + const user = { + id: faker.number.int(), + firstName: faker.person.firstName(), + lastName: faker.person.lastName(), + username: faker.internet.userName(), + email: faker.internet.email(), + age: faker.number.int({ min: 18, max: 100 }) + }; + + cy.get('[ng2-st-thead-form-row=""] > :nth-child(2)').should("be.visible").type(user.id.toString()); + cy.get('[ng2-st-thead-form-row=""] > :nth-child(3)').should("be.visible").type(user.firstName); + cy.get('[ng2-st-thead-form-row=""] > :nth-child(4)').should("be.visible").type(user.lastName); + cy.get('[ng2-st-thead-form-row=""] > :nth-child(5)').should("be.visible").type(user.username); + cy.get('[ng2-st-thead-form-row=""] > :nth-child(6)').should("be.visible").type(user.email); + cy.get('[ng2-st-thead-form-row=""] > :nth-child(7)').should("be.visible").type(user.age.toString()); + cy.get('.nb-checkmark').click(); + + return user; + } + + filterCreatedUser(user) { + cy.get('.ng2-smart-filters > .id').should("be.visible").type(user.id.toString()); + cy.get('.ng2-smart-filters > .firstName').should("be.visible").type(user.firstName); + cy.get('.ng2-smart-filters > .lastName').should("be.visible").type(user.lastName); + cy.get('.ng2-smart-filters > .username').should("be.visible").type(user.username); + cy.get('.ng2-smart-filters > .email').should("be.visible").type(user.email); + cy.get('.ng2-smart-filters > .age').should("be.visible").type(user.age.toString()); + } + + verifyCreatedUserData(newUser) { + cy.get(':nth-child(2)').should("contain.text", newUser.id); + cy.get(':nth-child(3)').should("contain.text", newUser.firstName); + cy.get(':nth-child(4)').should("contain.text", newUser.lastName); + cy.get(':nth-child(5)').should("contain.text", newUser.username); + cy.get(':nth-child(6)').should("contain.text", newUser.email); + cy.get(':nth-child(7)').should("contain.text", newUser.age); + } +} + +export default SmartTablePage; \ No newline at end of file diff --git a/cypress/support/commands.ts b/cypress/support/commands.ts index 698b01a..eb0288e 100644 --- a/cypress/support/commands.ts +++ b/cypress/support/commands.ts @@ -34,4 +34,4 @@ // visit(originalFn: CommandOriginalFn, url: string, options: Partial): Chainable // } // } -// } \ No newline at end of file +// } \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index cf94e37..01cc535 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,6 +21,7 @@ "@angular/platform-browser-dynamic": "^15.2.10", "@angular/router": "^15.2.10", "@asymmetrik/ngx-leaflet": "3.0.1", + "@faker-js/faker": "^8.4.1", "@nebular/auth": "11.0.1", "@nebular/eva-icons": "11.0.1", "@nebular/security": "11.0.1", @@ -34,6 +35,7 @@ "core-js": "2.5.1", "echarts": "^4.9.0", "eva-icons": "^1.1.3", + "faker": "^6.6.6", "intl": "1.2.5", "ionicons": "2.0.1", "leaflet": "1.2.0", @@ -6601,6 +6603,21 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/@faker-js/faker": { + "version": "8.4.1", + "resolved": "https://registry.npmjs.org/@faker-js/faker/-/faker-8.4.1.tgz", + "integrity": "sha512-XQ3cU+Q8Uqmrbf2e0cIC/QN43sTBSC8KF12u29Mb47tWrt2hAgBXSgpZMj4Ao8Uk0iJcU99QsOCaIL8934obCg==", + "funding": [ + { + "type": "opencollective", + "url": "https://opencollective.com/fakerjs" + } + ], + "engines": { + "node": "^14.17.0 || ^16.13.0 || >=18.0.0", + "npm": ">=6.14.13" + } + }, "node_modules/@fortawesome/fontawesome-free": { "version": "5.15.4", "resolved": "https://registry.npmjs.org/@fortawesome/fontawesome-free/-/fontawesome-free-5.15.4.tgz", @@ -14830,6 +14847,11 @@ "node >=0.6.0" ] }, + "node_modules/faker": { + "version": "6.6.6", + "resolved": "https://registry.npmjs.org/faker/-/faker-6.6.6.tgz", + "integrity": "sha512-9tCqYEDHI5RYFQigXFwF1hnCwcWCOJl/hmll0lr5D2Ljjb0o4wphb69wikeJDz5qCEzXCoPvG6ss5SDP6IfOdg==" + }, "node_modules/fancy-log": { "version": "1.3.3", "resolved": "https://registry.npmjs.org/fancy-log/-/fancy-log-1.3.3.tgz", diff --git a/package.json b/package.json index 27c00ed..faeb326 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,7 @@ "@angular/platform-browser-dynamic": "^15.2.10", "@angular/router": "^15.2.10", "@asymmetrik/ngx-leaflet": "3.0.1", + "@faker-js/faker": "^8.4.1", "@nebular/auth": "11.0.1", "@nebular/eva-icons": "11.0.1", "@nebular/security": "11.0.1", @@ -55,6 +56,7 @@ "core-js": "2.5.1", "echarts": "^4.9.0", "eva-icons": "^1.1.3", + "faker": "^6.6.6", "intl": "1.2.5", "ionicons": "2.0.1", "leaflet": "1.2.0", From 883df627ba0f477190a540669f710326f91d2c1c Mon Sep 17 00:00:00 2001 From: ChrissyDev Date: Tue, 19 Mar 2024 11:36:19 +0200 Subject: [PATCH 3/8] homework 15 --- cypress.config.ts | 2 +- cypress/e2e/auth/login.spec.js | 4 +- .../e2e/tables-and-data/smart-tables.spec.js | 42 +++++++++----- cypress/page-Objects/SmartTablePage.js | 58 +++++++++++++++++-- 4 files changed, 83 insertions(+), 23 deletions(-) diff --git a/cypress.config.ts b/cypress.config.ts index 22755f9..d4a396c 100644 --- a/cypress.config.ts +++ b/cypress.config.ts @@ -7,7 +7,7 @@ export default defineConfig({ viewportWidth: 1920, viewportHeight: 1080, defaultCommandTimeout: 4000, - retries: { runMode: 1, openMode: 1 }, + retries: { runMode: 1, openMode: 0 }, scrollBehavior: 'center', setupNodeEvents(on, config) { // implement node event listeners here diff --git a/cypress/e2e/auth/login.spec.js b/cypress/e2e/auth/login.spec.js index b58f5d1..abd109d 100644 --- a/cypress/e2e/auth/login.spec.js +++ b/cypress/e2e/auth/login.spec.js @@ -6,6 +6,6 @@ describe("Auth tab functionality", () => { it("Login to dashboard", () => { cy.visit("/auth/login"); authTab.login(); - cy.url().should("eq", "http://localhost:4200/pages/dashboard") - }); + cy.url({timeout: 6000}).should("contains", "/pages/dashboard") + }); }); \ No newline at end of file diff --git a/cypress/e2e/tables-and-data/smart-tables.spec.js b/cypress/e2e/tables-and-data/smart-tables.spec.js index 6b12f26..4b635d7 100644 --- a/cypress/e2e/tables-and-data/smart-tables.spec.js +++ b/cypress/e2e/tables-and-data/smart-tables.spec.js @@ -2,18 +2,32 @@ import SmartTablePage from "../../page-Objects/SmartTablePage.js"; const smartTablePage = new SmartTablePage(); -describe("Smart tables functionality", () => { - beforeEach(() => { - cy.visit("pages/tables/smart-table"); - }) +describe("Smart tables functionality", () => { + beforeEach(() => { + cy.visit("pages/tables/smart-table"); + }); - it("Creates new user and checks if it's added to the table", () => { - cy.get(".ng2-smart-actions-title").should("be.visible").click(); - const newUser = smartTablePage.createUser(); - smartTablePage.filterCreatedUser(newUser); - cy.get("tbody").should("be.visible").within(() => { - cy.get('.ng2-smart-row').should("have.length", 1); - smartTablePage.verifyCreatedUserData(newUser); - }) - }); -}) \ No newline at end of file + it("Creates new user and checks if it's added to the table", () => { + cy.get(".ng2-smart-actions-title").should("be.visible").click(); + const newUser = smartTablePage.createUser(); + smartTablePage.filterCreatedUser(newUser); + cy.get("tbody") + .should("be.visible") + .within(() => { + cy.get(".ng2-smart-row").should("have.length", 1); + smartTablePage.verifyCreatedUserData(newUser); + }); + }); + + it.only("Creates new user and checks if it's added to the table", () => { + cy.get(".ng2-smart-actions-title").should("be.visible").click(); + const newUser = smartTablePage.createUser(); + smartTablePage.filterCreatedUser(newUser); + smartTablePage.verifyCreatedUserData(newUser); + cy.wait(1000); + cy.get(".nb-edit").click(); + smartTablePage.clearEditFields(); + const editedUser = smartTablePage.editUser(newUser); + smartTablePage.verifyEditedUserData(editedUser); + }); +}); \ No newline at end of file diff --git a/cypress/page-Objects/SmartTablePage.js b/cypress/page-Objects/SmartTablePage.js index 6d58f7b..b4ea767 100644 --- a/cypress/page-Objects/SmartTablePage.js +++ b/cypress/page-Objects/SmartTablePage.js @@ -32,13 +32,59 @@ class SmartTablePage { } verifyCreatedUserData(newUser) { - cy.get(':nth-child(2)').should("contain.text", newUser.id); - cy.get(':nth-child(3)').should("contain.text", newUser.firstName); - cy.get(':nth-child(4)').should("contain.text", newUser.lastName); - cy.get(':nth-child(5)').should("contain.text", newUser.username); - cy.get(':nth-child(6)').should("contain.text", newUser.email); - cy.get(':nth-child(7)').should("contain.text", newUser.age); + cy.get("tbody") + .should("be.visible") + .within(() => { + cy.get(".ng2-smart-row").should("have.length", 1); + cy.get(':nth-child(2)').should("contain.text", newUser.id); + cy.get(':nth-child(3)').should("contain.text", newUser.firstName); + cy.get(':nth-child(4)').should("contain.text", newUser.lastName); + cy.get(':nth-child(5)').should("contain.text", newUser.username); + cy.get(':nth-child(6)').should("contain.text", newUser.email); + cy.get(':nth-child(7)').should("contain.text", newUser.age); + }); } + + clearEditFields() { + cy.get('[ng-reflect-name="id"]').clear(); + cy.get('[ng-reflect-name="firstName"]').clear(); + cy.get('[ng-reflect-name="lastName"]').clear(); + cy.get('[ng-reflect-name="username"]').clear(); + cy.get('[ng-reflect-name="email"]').clear(); + cy.get('[ng-reflect-name="age"]').clear(); + } + + editUser(user) { + const editedUser = { + editedId: "edited" + user.id, + editedFirstName: "edited" + user.firstName, + editedLastName: "edited" + user.lastName, + editedUsername: "edited" + user.username, + editedEmail: "edited" + user.email, + editedAge: "edited" + user.age + }; + + cy.get('[ng-reflect-name="id"]').type(editedUser.editedId); + cy.get('[ng-reflect-name="firstName"]').type(editedUser.editedFirstName); + cy.get('[ng-reflect-name="lastName"]').type(editedUser.editedLastName); + cy.get('[ng-reflect-name="username"]').type(editedUser.editedUsername); + cy.get('[ng-reflect-name="email"]').type(editedUser.editedEmail); + cy.get('[ng-reflect-name="age"]').type(editedUser.editedAge); + + cy.get('.ng2-smart-action-edit-save').click(); + + return editedUser; + } + + verifyEditedUserData(user) { + cy.get('.ng2-smart-row > :nth-child(2)').should("contain.text", user.editedId); + cy.get('.ng2-smart-row > :nth-child(3)').should("contain.text", user.editedFirstName); + cy.get('.ng2-smart-row > :nth-child(4)').should("contain.text", user.editedLastName); + cy.get('.ng2-smart-row > :nth-child(5)').should("contain.text", user.editedUsername); + cy.get('.ng2-smart-row > :nth-child(6)').should("contain.text", user.editedEmail); + cy.get('.ng2-smart-row > :nth-child(7)').should("contain.text", user.editedAge); + } + } export default SmartTablePage; \ No newline at end of file From 909b9fcedf8945d9b1868f798ae45e7b5889ccf6 Mon Sep 17 00:00:00 2001 From: ChrissyDev Date: Tue, 19 Mar 2024 21:38:21 +0200 Subject: [PATCH 4/8] fixed authTab to authPage --- cypress/e2e/auth/login.spec.js | 8 ++++---- cypress/page-Objects/AuthTab.js | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/cypress/e2e/auth/login.spec.js b/cypress/e2e/auth/login.spec.js index abd109d..cdd8abd 100644 --- a/cypress/e2e/auth/login.spec.js +++ b/cypress/e2e/auth/login.spec.js @@ -1,11 +1,11 @@ -import AuthTab from "../../page-Objects/AuthTab.js"; +import AuthPage from "../../page-Objects/AuthTab.js"; -const authTab = new AuthTab(); +const authPage = new AuthPage(); -describe("Auth tab functionality", () => { +describe("Auth page functionality", () => { it("Login to dashboard", () => { cy.visit("/auth/login"); - authTab.login(); + authPage.login(); cy.url({timeout: 6000}).should("contains", "/pages/dashboard") }); }); \ No newline at end of file diff --git a/cypress/page-Objects/AuthTab.js b/cypress/page-Objects/AuthTab.js index 661f781..a98dfd8 100644 --- a/cypress/page-Objects/AuthTab.js +++ b/cypress/page-Objects/AuthTab.js @@ -1,12 +1,12 @@ import { faker } from '@faker-js/faker'; -class AuthTab { +class AuthPage { login() { - cy.get('#input-email').type(faker.internet.email()); - cy.get('#input-password').type(faker.internet.password()); + cy.get('#input-email').type("somerandomemail@gmail.com"); + cy.get('#input-password').type("12345678"); cy.get('.custom-checkbox').click(); cy.get('.appearance-filled').click(); } } -export default AuthTab; \ No newline at end of file +export default AuthPage; \ No newline at end of file From f5ae26b4c351e629aa3b553bc5ee9ef4f81b0c0e Mon Sep 17 00:00:00 2001 From: ChrissyDev Date: Wed, 20 Mar 2024 11:45:27 +0200 Subject: [PATCH 5/8] updated homework 15, moved user to code instead of POM --- .../e2e/tables-and-data/smart-tables.spec.js | 37 +++++++++++++++---- cypress/page-Objects/SmartTablePage.js | 13 +------ 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/cypress/e2e/tables-and-data/smart-tables.spec.js b/cypress/e2e/tables-and-data/smart-tables.spec.js index 4b635d7..fd4d450 100644 --- a/cypress/e2e/tables-and-data/smart-tables.spec.js +++ b/cypress/e2e/tables-and-data/smart-tables.spec.js @@ -1,4 +1,5 @@ import SmartTablePage from "../../page-Objects/SmartTablePage.js"; +import { faker } from '@faker-js/faker'; const smartTablePage = new SmartTablePage(); @@ -9,25 +10,45 @@ describe("Smart tables functionality", () => { it("Creates new user and checks if it's added to the table", () => { cy.get(".ng2-smart-actions-title").should("be.visible").click(); - const newUser = smartTablePage.createUser(); - smartTablePage.filterCreatedUser(newUser); + + const user = { + id: faker.number.int(), + firstName: faker.person.firstName(), + lastName: faker.person.lastName(), + username: faker.internet.userName(), + email: faker.internet.email(), + age: faker.number.int({ min: 18, max: 100 }) + }; + + smartTablePage.createUser(user); + smartTablePage.filterCreatedUser(user); cy.get("tbody") .should("be.visible") .within(() => { cy.get(".ng2-smart-row").should("have.length", 1); - smartTablePage.verifyCreatedUserData(newUser); + smartTablePage.verifyCreatedUserData(user); }); }); - it.only("Creates new user and checks if it's added to the table", () => { + it.only("Creates new user, edits it and checks if edited values are added to the table", () => { cy.get(".ng2-smart-actions-title").should("be.visible").click(); - const newUser = smartTablePage.createUser(); - smartTablePage.filterCreatedUser(newUser); - smartTablePage.verifyCreatedUserData(newUser); + + const user = { + id: faker.number.int(), + firstName: faker.person.firstName(), + lastName: faker.person.lastName(), + username: faker.internet.userName(), + email: faker.internet.email(), + age: faker.number.int({ min: 18, max: 100 }) + }; + + smartTablePage.createUser(user); + smartTablePage.filterCreatedUser(user); + smartTablePage.verifyCreatedUserData(user); cy.wait(1000); cy.get(".nb-edit").click(); smartTablePage.clearEditFields(); - const editedUser = smartTablePage.editUser(newUser); + const editedUser = smartTablePage.editUser(user); smartTablePage.verifyEditedUserData(editedUser); }); }); \ No newline at end of file diff --git a/cypress/page-Objects/SmartTablePage.js b/cypress/page-Objects/SmartTablePage.js index b4ea767..da67b72 100644 --- a/cypress/page-Objects/SmartTablePage.js +++ b/cypress/page-Objects/SmartTablePage.js @@ -1,16 +1,7 @@ import { faker } from '@faker-js/faker'; class SmartTablePage { - createUser() { - const user = { - id: faker.number.int(), - firstName: faker.person.firstName(), - lastName: faker.person.lastName(), - username: faker.internet.userName(), - email: faker.internet.email(), - age: faker.number.int({ min: 18, max: 100 }) - }; - + createUser(user) { cy.get('[ng2-st-thead-form-row=""] > :nth-child(2)').should("be.visible").type(user.id.toString()); cy.get('[ng2-st-thead-form-row=""] > :nth-child(3)').should("be.visible").type(user.firstName); cy.get('[ng2-st-thead-form-row=""] > :nth-child(4)').should("be.visible").type(user.lastName); @@ -18,8 +9,6 @@ class SmartTablePage { cy.get('[ng2-st-thead-form-row=""] > :nth-child(6)').should("be.visible").type(user.email); cy.get('[ng2-st-thead-form-row=""] > :nth-child(7)').should("be.visible").type(user.age.toString()); cy.get('.nb-checkmark').click(); - - return user; } filterCreatedUser(user) { From 96d03246d15b3c6944d25f522325bf47e5299470 Mon Sep 17 00:00:00 2001 From: ChrissyDev Date: Wed, 20 Mar 2024 12:01:26 +0200 Subject: [PATCH 6/8] fixed verifyCreatedUserData method --- .../e2e/tables-and-data/smart-tables.spec.js | 2 +- cypress/page-Objects/SmartTablePage.js | 20 ++++++++----------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/cypress/e2e/tables-and-data/smart-tables.spec.js b/cypress/e2e/tables-and-data/smart-tables.spec.js index fd4d450..aa28b0a 100644 --- a/cypress/e2e/tables-and-data/smart-tables.spec.js +++ b/cypress/e2e/tables-and-data/smart-tables.spec.js @@ -30,7 +30,7 @@ describe("Smart tables functionality", () => { }); }); - it.only("Creates new user, edits it and checks if edited values are added to the table", () => { + it("Creates new user, edits it and checks if edited values are added to the table", () => { cy.get(".ng2-smart-actions-title").should("be.visible").click(); const user = { diff --git a/cypress/page-Objects/SmartTablePage.js b/cypress/page-Objects/SmartTablePage.js index da67b72..506c64d 100644 --- a/cypress/page-Objects/SmartTablePage.js +++ b/cypress/page-Objects/SmartTablePage.js @@ -20,18 +20,14 @@ class SmartTablePage { cy.get('.ng2-smart-filters > .age').should("be.visible").type(user.age.toString()); } - verifyCreatedUserData(newUser) { - cy.get("tbody") - .should("be.visible") - .within(() => { - cy.get(".ng2-smart-row").should("have.length", 1); - cy.get(':nth-child(2)').should("contain.text", newUser.id); - cy.get(':nth-child(3)').should("contain.text", newUser.firstName); - cy.get(':nth-child(4)').should("contain.text", newUser.lastName); - cy.get(':nth-child(5)').should("contain.text", newUser.username); - cy.get(':nth-child(6)').should("contain.text", newUser.email); - cy.get(':nth-child(7)').should("contain.text", newUser.age); - }); + verifyCreatedUserData(newUser) { + cy.get(".ng2-smart-row").should("have.length", 1); + cy.get(':nth-child(2)').should("contain.text", newUser.id); + cy.get(':nth-child(3)').should("contain.text", newUser.firstName); + cy.get(':nth-child(4)').should("contain.text", newUser.lastName); + cy.get(':nth-child(5)').should("contain.text", newUser.username); + cy.get(':nth-child(6)').should("contain.text", newUser.email); + cy.get(':nth-child(7)').should("contain.text", newUser.age); } clearEditFields() { From 2308399cfd2e00b2d4444ca3fa3b8e80263813d3 Mon Sep 17 00:00:00 2001 From: ChrissyDev Date: Wed, 20 Mar 2024 14:02:13 +0200 Subject: [PATCH 7/8] forgot to rename 1 file --- cypress/page-Objects/{AuthTab.js => AuthPage.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename cypress/page-Objects/{AuthTab.js => AuthPage.js} (100%) diff --git a/cypress/page-Objects/AuthTab.js b/cypress/page-Objects/AuthPage.js similarity index 100% rename from cypress/page-Objects/AuthTab.js rename to cypress/page-Objects/AuthPage.js From c647f1182446900acb8418def36164526763b81c Mon Sep 17 00:00:00 2001 From: ChrissyDev Date: Mon, 25 Mar 2024 17:05:18 +0200 Subject: [PATCH 8/8] Homework 16 --- cypress/e2e/api/api.spec.js | 46 +++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 cypress/e2e/api/api.spec.js diff --git a/cypress/e2e/api/api.spec.js b/cypress/e2e/api/api.spec.js new file mode 100644 index 0000000..e22d88c --- /dev/null +++ b/cypress/e2e/api/api.spec.js @@ -0,0 +1,46 @@ +describe('API Tests', () => { + const baseUrl = 'https://jsonplaceholder.typicode.com'; + + it('should get a post by id', () => { + cy.request(`${baseUrl}/posts/1`) + .its('status') + .should('eq', 200); + }); + + it('should get a list of posts', () => { + cy.request(`${baseUrl}/posts`) + .its('status') + .should('eq', 200); + cy.request(`${baseUrl}/posts`) + .its('body') + .should('not.be.empty') + }); + + it('should create a new post', () => { + const newPost = { + title: 'New Post', + body: 'This is a new post.', + userId: 1 + }; + cy.request('POST', `${baseUrl}/posts`, newPost) + .its('status') + .should('eq', 201); + }); + + it('should update a post by id', () => { + const updatedPost = { + title: 'Updated Post', + body: 'This post has been updated.', + userId: 1 + }; + cy.request('PUT', `${baseUrl}/posts/1`, updatedPost) + .its('status') + .should('eq', 200); + }); + + it('should delete a post by id', () => { + cy.request('DELETE', `${baseUrl}/posts/1`) + .its('status') + .should('eq', 200); + }); +}); \ No newline at end of file