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

Oksana_Kachmar_qa_cypress_e2e_book_store_Solution #326

Open
wants to merge 1 commit into
base: master
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
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/',

Choose a reason for hiding this comment

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

You need to remove "/" after .com. It may create a link like https://demoqa.com//login with two "/". Because you use cy.visit('/login'); with "/" at the beginning. It isn't a big deal but better to remove it

Copy link
Author

Choose a reason for hiding this comment

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

Ok, I will fix it. thank you.

setupNodeEvents(on, config) {
}
}
Expand Down
29 changes: 26 additions & 3 deletions cypress/e2e/bookStore.cy.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,34 @@
/// <reference types='cypress' />

describe('Book Store app', () => {
before(() => {

const user = {
username: 'Cokka',
password: 'Cokka2024!'
};

it('should provide an ability to login', () => {
cy.visit('/login');
cy.get('#userName').type(user.username);
cy.get('#password').type(user.password);
cy.get('#login').click()

cy.url().should('include', '/profile');
cy.get('#userName-value').should('contain', user.username);
});

it('should allow to search for a book', () => {
const bookName = 'Speaking JavaScript';

it('', () => {
cy.login();
cy.visit('/books');

cy.get('#userName-value').should('contain.text', user.username);
cy.get('#searchBox').type(bookName);
cy.get('[href="/books?book=9781449365035"]')
.should('contain.text', bookName);
cy.get('.rt-td').should('contain.text', 'Axel Rauschmayer');
cy.get('.rt-td').should('contain.text', 'O\'Reilly Media');
});
});

})
16 changes: 16 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,19 @@
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })

Cypress.Commands.add('login', () => {
cy.request({
method: 'POST',
url: 'https://demoqa.com/Account/v1/Login', // baseUrl is prepend to URL
body: {
userName: 'Cokka',
password: 'Cokka2024!',
},
}).then((response) => {
cy.setCookie('token', response.body.token);
cy.setCookie('userID', response.body.userId);
cy.setCookie('userName', response.body.username);
cy.setCookie('expires', response.body.expires);
})
})