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

Solution #336

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

module.exports = defineConfig({
e2e: {
baseUrl: 'https://demoqa.com/login',
setupNodeEvents(on, config) {
on("task", {
generateUser() {
return {
password: '12345Qwert!',
username:'Kasia'
};
}
});
}
}
});
35 changes: 30 additions & 5 deletions cypress/e2e/bookStore.cy.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,36 @@
/// <reference types='cypress' />

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

});
const user = {
username: 'Kasia',
password: '12345Qwert!'
}
const book = {
title: 'Speaking JavaScript',
author: 'Axel Rauschmayer',
publisher: `O'Reilly Media`
}

it('', () => {
before(() => {
cy.visit('https://demoqa.com/login')
})

});
it('should provide the ability to login', () => {
cy.get('#userName').type(user.username)
cy.get('#password').type(user.password)
cy.get('#login').click()
cy.url().should('not.include', 'https://demoqa.com/login')
cy.url().should('include', 'https://demoqa.com/profile')
cy.get('#userName-value').should('contain', user.username)
})

it('should provide the ability to search for the book', () => {
cy.login()
cy.visit('https://demoqa.com/books')
cy.contains('#item-2', 'Book Store').click()
cy.findByPlaceholder('Type to search').type(book.title)
cy.contains('[role="row"]', book.title)
.should('contain', book.author)
.and('contain', book.publisher)
})
});
20 changes: 20 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,23 @@
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })

Cypress.Commands.add('login', (username = 'Kasia', password = '12345Qwert!') => {
cy.request({
method: 'POST',
url: 'https://demoqa.com/Account/v1/login',
body: {
"userName": username,
"password": password
}
}).then((response) => {
cy.setCookie('token', response.body.token)
cy.setCookie('userID', '3')
cy.setCookie('expires', response.body.expires)
cy.setCookie('userName', 'Kasia')
});
});

Cypress.Commands.add('findByPlaceholder', (placeholder) => {
cy.get(`[placeholder="${placeholder}"]`)
});
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

## Task

App for testing: [BookStore](https://demoqa.com/register)
App for testing: [BookStore](https://demoqa.com/login)

[Create](https://demoqa.com/register) your account **manually** before completing the task.
[Create](https://demoqa.com/login) your account **manually** before completing the task.

**Your task** is to check the following flow:

Expand Down