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

Task is done and waiting for review #253

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ const { defineConfig } = require('cypress');

module.exports = defineConfig({
e2e: {
baseUrl: 'https://demoqa.com/webtables',

setupNodeEvents(on, config) {
// implement node event listeners here
}
Expand Down
165 changes: 164 additions & 1 deletion cypress/e2e/webTables.cy.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,170 @@
/// <reference types='cypress' />

import WebTables from '../support/pageObjects/pages/webTables';
import RegistrationForm from
'../support/pageObjects/components/registrationForm';
import Pagination from '../support/pageObjects/components/pagination';
import generateWorker from '../support/generateData';
import workersData from '../support/fixtures/workersData.json';
import titles from '../support/fixtures/titles.json';

const webTables = new WebTables();
const registrationForm = new RegistrationForm();
const pagination = new Pagination();

describe('Web Tables page', () => {
it('', () => {
beforeEach(() => {
cy.wrap(generateWorker()).as('workerData');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. move all aliases to constants
  2. not sure if we need this wrap, we can reduce amount of code by not using wrap, but directly this function. For this, we need just to make sure that function returns something


cy.wrap(generateWorker()).as('newWorker');

cy.visit('');
});

it('should allow to add a new worker', () => {
webTables.assertAddBtnExists(titles.addBtn)
.clickOnAddBtn();

cy.get('@workerData').then((workerData) => {
registrationForm
.assertFormExists(titles.registrationForm, titles.submitDataBtn)
.fillFormAndSubmit(workerData);

webTables.assertWorkerDataInTable(workerData);
});
});

it('should allow to delete a worker', () => {
cy.get('@workerData').then((workerData) => {
webTables.addWorker(workerData)
.assertWorkerDataInTable(workerData)
.deleteWorker(workerData)
.assertWorkerIsDeleted(workerData);
});
});

it('should allow to delete all workers', () => {
webTables.deleteAllWorkers()
.assertTableIsClear(titles.emptyTable);
});

it('should allow to find a worker by first name', () => {
cy.get('@workerData').then((workerData) => {
const { firstName } = workerData;

webTables.addWorker(workerData)
.assertSearchFieldExists()
.searchForWorker(firstName)
.assertWorkerDataInTable(workerData);
});
});

it('should allow to find a worker by last name', () => {
cy.get('@workerData').then((workerData) => {
const { lastName } = workerData;

webTables.addWorker(workerData)
.searchForWorker(lastName)
.assertWorkerDataInTable(workerData);
});
});

it('should allow to find a worker by age', () => {
cy.get('@workerData').then((workerData) => {
const { age } = workerData;

webTables.addWorker(workerData)
.searchForWorker(age)
.assertWorkerDataInTable(workerData);
});
});

it('should allow to find a worker by email', () => {
cy.get('@workerData').then((workerData) => {
const { email } = workerData;

webTables.addWorker(workerData)
.searchForWorker(email)
.assertWorkerDataInTable(workerData);
});
});

it('should allow to find a worker by salary', () => {
cy.get('@workerData').then((workerData) => {
const { salary } = workerData;

webTables.addWorker(workerData)
.searchForWorker(salary)
.assertWorkerDataInTable(workerData);
});
});

it('should allow to find a worker by department', () => {
cy.get('@workerData').then((workerData) => {
const { department } = workerData;

webTables.addWorker(workerData)
.searchForWorker(department)
.assertWorkerDataInTable(workerData);
});
});

it('should allow to edit the found worker', () => {
cy.get('@workerData').then((workerData) => {
const { email } = workerData;

webTables.addWorker(workerData)
.searchForWorker(email)
.clickOnEditBtnOfParticularWorker(email);

registrationForm.assertFormContainsWorkerData(workerData);

const updatedFirstName = workerData.firstName + ' edited';
const updatedLastName = workerData.lastName + ' edited';

cy.get('@newWorker').then((newWorkerData) => {
registrationForm.editFormAndSubmit(newWorkerData);

webTables.clearSearchField()
.assertWorkerDataIsEdited(
updatedFirstName, updatedLastName, newWorkerData
);
});
});
});

it(`should allow to change the rows count selection of the table data`, () => {
const rowsCount = ['5', '10', '20', '25', '50', '100'];

webTables.assertRowsSelection(rowsCount);
});

it(`should allow to navigate to the next table pages by entering page number into the "Page input" field`, () => {
webTables.addMultipleWorkers(workersData);

pagination.selectRowsCount()
.navigateUntilLastPageByPageNumber();
});

it(`should allow to navigate to the previous table pages by entering page number into the "Page input" field`, () => {
webTables.addMultipleWorkers(workersData);

pagination.selectRowsCount()
.navigateUntilFirstPageByPageNumber();
});

it(`should allow to navigate to the next table pages by clicking on [Next]`, () => {
webTables.addMultipleWorkers(workersData);

pagination.selectRowsCount()
.navigateUntilLastPageByClickingOnNextBtn();
});

it(`should allow to navigate to the previous table pages by clicking on [Previous]`, () => {
webTables.addMultipleWorkers(workersData);

pagination.selectRowsCount()
.navigateToLastPage()
.navigateUntilFirstPageByClickingOnPreviousBtn();
});
});
6 changes: 5 additions & 1 deletion cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })

Cypress.Commands.add('getById', (selector) => {
cy.get(`#${selector}`);
});
4 changes: 2 additions & 2 deletions cypress/support/e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands'
import './commands';

Cypress.on('uncaught:exception', () => {
return false;
Expand All @@ -31,4 +31,4 @@ if (!app.document.head.querySelector('[data-hide-command-log-request]')) {
};

// Alternatively you can use CommonJS syntax:
// require('./commands')
// require('./commands')
6 changes: 6 additions & 0 deletions cypress/support/fixtures/titles.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"addBtn": "Add",
"registrationForm": "Registration Form",
"submitDataBtn": "Submit",
"emptyTable": "No rows found"
}
26 changes: 26 additions & 0 deletions cypress/support/fixtures/workersData.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[
{
"firstName": "Test1",
"lastName": "Customer1",
"email": "[email protected]",
"age": 35,
"salary": 2500,
"department": "Sales"
},
{
"firstName": "Test2",
"lastName": "Customer2",
"email": "[email protected]",
"age": 39,
"salary": 3500,
"department": "Finance"
},
{
"firstName": "Test3",
"lastName": "Customer3",
"email": "[email protected]",
"age": 40,
"salary": 5500,
"department": "Marketing"
}
]
22 changes: 22 additions & 0 deletions cypress/support/generateData.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { faker } from '@faker-js/faker';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generateData - to general file name, please make it more specific


function generateWorker() {
const gender = faker.helpers.arrayElement(['male', 'female']);
const firstName = faker.person.firstName(gender);
const lastName = faker.person.lastName(gender);
const email = faker.internet.email();
const age = faker.finance.amount({ min: 16, max: 60, dec: 0 });
const salary = faker.finance.amount({ min: 600, max: 100000, dec: 0 });
const department = faker.commerce.department();

return {
firstName,
lastName,
email,
age,
salary,
department
};
}

export default generateWorker;
7 changes: 7 additions & 0 deletions cypress/support/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/// <reference types="cypress" />

declare namespace Cypress {
interface Chainable<Subject> {
getById(selector: string): Chainable<any>
}
}
Loading