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

M1 #345

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

M1 #345

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
1 change: 1 addition & 0 deletions cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const { defineConfig } = require('cypress');

module.exports = defineConfig({
e2e: {
baseUrl: 'https://demoqa.com',
setupNodeEvents(on, config) {
}
}
Expand Down
23 changes: 20 additions & 3 deletions cypress/e2e/bookStore.cy.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
/// <reference types='cypress' />

describe('Book Store app', () => {
before(() => {
const { userInfo, bookData } = require("../support/userData");

describe("Book Store app", () => {
const { username, password } = userInfo();
const { title, author, publisher } = bookData();

beforeEach(() => {
cy.visit("/register");
});

it('', () => {
it("should provide the ability to logged in", () => {
cy.loginByUI(username, password);
});

it("should provide the ability to add a book", () => {
cy.loginByApi(username, password);
cy.visit("/books");
cy.get("#searchBox").type(title);
//cy.get('.rt-td').eq(1).should('contain', book.title)
cy.assertBook(1, title);
//cy.get('.rt-td').eq(2).should('contain', book.author)
cy.assertBook(2, author);
//cy.get('.rt-td').eq(3).should('contain', book.publisher)
cy.assertBook(3, publisher);
});
});
49 changes: 24 additions & 25 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add('login', (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
Cypress.Commands.add("loginByApi", (username, password) => {
cy.request("POST", "https://demoqa.com/Account/v1/Login", {
userName: username,
password: password,
}).then((response) => {
cy.setCookie("token", response.body.token);
cy.setCookie("userID", response.body.userId);
cy.setCookie("expires", response.body.expires);
cy.setCookie("userName", response.body.username);
});
});

Cypress.Commands.add("assertBook", (id, book) => {
cy.get(".rt-td").eq(id).should("contain", book);
});

Cypress.Commands.add("loginByUI", (username, password) => {
cy.contains("#item-0", "Login").click();
cy.get('[placeholder="UserName"]').type(username);
cy.get('[placeholder="Password"]').type(password);
cy.contains("#login", "Login").click();
cy.get("#userName-value").should("contain", username);
cy.url().should("include", "profile");
});
16 changes: 0 additions & 16 deletions cypress/support/e2e.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
// ***********************************************************
// This example support/index.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

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

// Alternatively you can use CommonJS syntax:
Expand Down
16 changes: 16 additions & 0 deletions cypress/support/userData.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
function userInfo() {
let username = "Gusith";
let password = "Gusith1!_";

return { username, password };
}

function bookData() {
let title = "Speaking JavaScript";
let author = "Axel Rauschmayer";
let publisher = "O'Reilly Media";

return { title, author, publisher };
}

module.exports = { userInfo, bookData };
Binary file added cypress/videos/bookStore.cy.js.mp4
Binary file not shown.