├── .gitignore ├── cypress.config.js ├── cypress ├── e2e │ ├── TC01.cy.js │ ├── TC02_fixtures.cy.js │ ├── TC03_writeReadFile.cy.js │ ├── TC04_each.cy.js │ ├── TC05_conditionalTesting.cy.js │ ├── TC06_fileUpload.cy.js │ ├── TC07_fileDownload.cy.js │ ├── TC08_apiTesting.cy.js │ ├── TC09_apiChaining.cy.js │ ├── TC_10_apiMocking.cy.js │ ├── TC_11_jsAlertConfirmPrompt.cy.js │ ├── TC_12_usingskip.cy.js │ ├── TC_13_usingOnly.cy.js │ ├── TC_14_shadowDOM.cy.js │ ├── TC_15_numberOfRetries.cy.js │ ├── TC_16_iFrames.cy.js │ ├── TC_17_pageObject1.cy.js │ ├── TC_18_cypressStudio.cy.js │ ├── TC_19_intercept.cy.js │ ├── TC_20_hoverOverElement.cy.js │ ├── TC_21_databaseTesting.cy.js │ ├── TC_22_parentParentsChildren.cy.js │ ├── TC_23_dragAndDrop.cy.js │ ├── TC_24_newBrowserTabWindow.cy.js │ ├── TC_25_filterFindWithin.cy.js │ ├── TC_26_jqueryCommands.cy.js │ ├── TC_27_cypressRecursion.cy.js │ ├── TC_28_basicAuth.cy.js │ ├── TC_29_cypressRecorder.cy.js │ ├── cucumber-test │ │ ├── login.feature │ │ └── login │ │ │ └── login.js │ ├── examples │ │ ├── actions.spec.js │ │ ├── aliasing.spec.js │ │ ├── assertions.spec.js │ │ ├── connectors.spec.js │ │ ├── cookies.spec.js │ │ ├── cypress_api.spec.js │ │ ├── files.spec.js │ │ ├── local_storage.spec.js │ │ ├── location.spec.js │ │ ├── misc.spec.js │ │ ├── navigation.spec.js │ │ ├── network_requests.spec.js │ │ ├── querying.spec.js │ │ ├── spies_stubs_clocks.spec.js │ │ ├── traversal.spec.js │ │ ├── utilities.spec.js │ │ ├── viewport.spec.js │ │ ├── waiting.spec.js │ │ └── window.spec.js │ ├── pages │ │ ├── dashboardPage.js │ │ └── loginPage.js │ ├── sequenced-tests.cy.js │ └── utils │ │ ├── dashboard.js │ │ └── login.js ├── fixtures │ ├── Download │ │ └── test.txt │ ├── articlefeed.json │ ├── example.json │ ├── images │ │ ├── evening.png │ │ ├── morning.jpg │ │ └── night.jpg │ ├── profile.json │ ├── tags.json │ ├── test1.txt │ ├── test2.json │ ├── testdata.json │ └── users.json ├── plugins │ └── index.js └── support │ ├── commands.js │ ├── e2e.js │ └── filterTests.js ├── jsconfig.json ├── package-lock.json ├── package.json ├── readme.md └── testdata └── test1.txt /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules/ 3 | cypress/videos 4 | cypress/screenshots 5 | TestReport/ 6 | mochawesome-report/ 7 | cypress-combined-report.json 8 | cypress/integration/dummy.js 9 | cypress/fixtures/url.json 10 | cypress/fixtures/data.txt 11 | abcd.html 12 | dummy.cy.js -------------------------------------------------------------------------------- /cypress.config.js: -------------------------------------------------------------------------------- 1 | const { defineConfig } = require('cypress') 2 | 3 | module.exports = defineConfig({ 4 | watchForFileChanges: false, 5 | chromeWebSecurity: false, 6 | retries: 1, 7 | reporter: '../node_modules/mochawesome/src/mochawesome.js', 8 | reporterOptions: { 9 | overwrite: false, 10 | html: false, 11 | json: true, 12 | }, 13 | projectId: 'd5zibb', 14 | env: { 15 | db: { 16 | host: 'db4free.net', 17 | user: 'username', 18 | password: 'password', 19 | database: 'db_name', 20 | }, 21 | }, 22 | e2e: { 23 | // We've imported your old cypress plugins here. 24 | // You may want to clean this up later by importing these. 25 | setupNodeEvents(on, config) { 26 | require("@deploysentinel/cypress-recorder")(on, config) 27 | return require('./cypress/plugins/index.js')(on, config) 28 | }, 29 | specPattern: 30 | ["**/*.feature", "cypress/e2e/**/*.cy.{js,jsx,ts,tsx}"], 31 | baseUrl: 'https://opensource-demo.orangehrmlive.com/', 32 | }, 33 | }) 34 | -------------------------------------------------------------------------------- /cypress/e2e/TC01.cy.js: -------------------------------------------------------------------------------- 1 | import TestFilters from '../support/filterTests.js' 2 | 3 | TestFilters([], () => { 4 | describe('Search for Google Wiki page from Wikipedia website (Smoke)', () => { 5 | before(() => { 6 | cy.visit('https://wikipedia.org') 7 | }) 8 | 9 | it('Validate Page Title', () => { 10 | cy.title().should('eq', 'Wikipedia') 11 | }) 12 | 13 | it('Search for Google Wiki Page', () => { 14 | cy.get('#searchInput').type('google') 15 | cy.get('button[type="submit"]').click() 16 | }) 17 | 18 | it('Validate Google Wiki Page has opened', () => { 19 | cy.get('h1#firstHeading').contains('Google') 20 | cy.title().should('eq', 'Google - Wikipedia') 21 | }) 22 | }) 23 | }) -------------------------------------------------------------------------------- /cypress/e2e/TC02_fixtures.cy.js: -------------------------------------------------------------------------------- 1 | import TestFilters from '../support/filterTests.js' 2 | 3 | TestFilters([], () => { 4 | describe('Login to OrangeHRM website (E2E)', function () { 5 | before(function () { 6 | cy.visit('https://opensource-demo.orangehrmlive.com/') 7 | cy.fixture('testdata').then(function (testdata) { 8 | this.testdata = testdata 9 | }) 10 | }) 11 | 12 | it('Validate successful Login', function () { 13 | cy.get('#txtUsername').type(this.testdata.username) 14 | cy.get('#txtPassword').type(this.testdata.password) 15 | cy.get('#btnLogin').click() 16 | cy.get('#welcome').contains(this.testdata.welcomeText) 17 | }) 18 | }) 19 | }) 20 | -------------------------------------------------------------------------------- /cypress/e2e/TC03_writeReadFile.cy.js: -------------------------------------------------------------------------------- 1 | import TestFilters from '../support/filterTests.js' 2 | 3 | TestFilters([], () => { 4 | describe('Example for writeFile and readFile (Smoke,E2E)', function () { 5 | 6 | it('Write to a text file test1.txt using writeFile', function () { 7 | cy.writeFile('cypress/fixtures/test1.txt', 'Testersdock.com\n') 8 | }) 9 | 10 | it('Append content to the end of the text file test1.txt using the flag a+', function () { 11 | cy.writeFile('cypress/fixtures/test1.txt', 'Info Hub for Testers', { flag: 'a+' }) 12 | }) 13 | 14 | it('Write to a JSON file test2.json using writeFile', function () { 15 | cy.writeFile('cypress/fixtures/test2.json', { firstname: 'Alapan', lastname: 'Das' }) 16 | }) 17 | 18 | it('Validate the content of both text and JSON file using readFile', function () { 19 | cy.readFile('cypress/fixtures/test1.txt').should('contain', 'Testersdock') 20 | cy.readFile('cypress/fixtures/test1.txt').should('eq', 'Testersdock.com\nInfo Hub for Testers') 21 | cy.readFile('cypress/fixtures/test2.json').its('firstname').should('eq', 'Alapan') 22 | }) 23 | 24 | }) 25 | }) -------------------------------------------------------------------------------- /cypress/e2e/TC04_each.cy.js: -------------------------------------------------------------------------------- 1 | import TestFilters from '../support/filterTests.js' 2 | 3 | TestFilters([], () => { 4 | describe('Example to demonstrate the use each in Cypress', function () { 5 | before(function () { 6 | cy.visit('https://opensource-demo.orangehrmlive.com/') 7 | }) 8 | 9 | beforeEach(function () { 10 | cy.fixture('testdata').then(function (testdata) { 11 | this.testdata = testdata 12 | }) 13 | }) 14 | 15 | it('Validate successful Login', function () { 16 | cy.get('#txtUsername').type(this.testdata.username) 17 | cy.get('#txtPassword').type(this.testdata.password) 18 | cy.get('#btnLogin').click() 19 | cy.get('#welcome').contains(this.testdata.welcomeText) 20 | }) 21 | 22 | it('Validate all the Quick Launch Texts', function () { 23 | cy.get('.quickLaunge').each(($el, index) => { 24 | expect($el).to.contain(this.testdata.quickLaunch[index]) 25 | }) 26 | }) 27 | 28 | /*Please check the pie chart percentage values before execution. 29 | I realized it very late that the pie chart values changes after few days. 30 | Update the empDistPieChart from the testdata.json file with the latest values.*/ 31 | 32 | it('Validate the Employee Distribution by Subunit Piechart Values and sum of percentage values', function () { 33 | var total = 0 34 | cy.get('.pieLabel').each(($el, index) => { 35 | expect($el).to.contain(this.testdata.empDistPieChart[index]) 36 | total = total + parseInt($el.text()) 37 | }).then(() => { 38 | expect(total).to.equal(99) 39 | }) 40 | }) 41 | }) 42 | }) -------------------------------------------------------------------------------- /cypress/e2e/TC05_conditionalTesting.cy.js: -------------------------------------------------------------------------------- 1 | import TestFilters from '../support/filterTests.js' 2 | 3 | TestFilters(['regression'], () => { 4 | describe('Example to demo conditional testing in cypress', () => { 5 | beforeEach(() => { 6 | cy.visit('https://wikipedia.org') 7 | }) 8 | 9 | it('Check that if you find WikiVoyage on the page, then click on it and validate (Go to If)', () => { 10 | cy.title().should('eq', 'Wikipedia') 11 | cy.get('body').then((body) => { 12 | if (body.find('[data-jsl10n="wikivoyage.name"]').length > 0) { 13 | cy.get('[data-jsl10n="wikivoyage.name"]').click() 14 | } 15 | else { 16 | cy.get('[data-jsl10n="wiktionary.name"]').click() 17 | } 18 | }) 19 | cy.title().should('eq', 'Wikivoyage') 20 | }) 21 | 22 | it('Check that if you dont find WikiVoyage in the page, then click on Wiktionary and validate (Go to Else)', () => { 23 | cy.title().should('eq', 'Wikipedia') 24 | cy.get('body').then((body) => { 25 | if (body.find('wrongLocator').length > 0) { 26 | cy.get('[data-jsl10n="wikivoyage.name"]').click() 27 | } 28 | else { 29 | cy.get('[data-jsl10n="wiktionary.name"]').click() 30 | } 31 | }) 32 | cy.title().should('eq', 'Wiktionary') 33 | }) 34 | }) 35 | }) -------------------------------------------------------------------------------- /cypress/e2e/TC06_fileUpload.cy.js: -------------------------------------------------------------------------------- 1 | import TestFilters from '../support/filterTests.js' 2 | 3 | TestFilters([], () => { 4 | describe('Example to demonstrate file upload in cypress', function () { 5 | 6 | it('File Upload using cypress-file-upload npm package', () => { 7 | cy.visit('https://the-internet.herokuapp.com/upload') 8 | const filepath = 'images/evening.png' 9 | cy.get('input[type="file"]').attachFile(filepath) 10 | cy.get('#file-submit').click() 11 | cy.get('#uploaded-files').contains('evening.png') 12 | }) 13 | 14 | it('File Upload using selectFile with select mode', () => { 15 | cy.visit('https://the-internet.herokuapp.com/upload') 16 | cy.get('#file-upload').selectFile('cypress/fixtures/images/evening.png') 17 | cy.get('#file-submit').click() 18 | cy.get('#uploaded-files').contains('evening.png') 19 | }) 20 | 21 | it('File Upload using selectFile with drag and drop mode', () => { 22 | cy.visit('https://postimages.org/') 23 | cy.get('#uploadFile').selectFile('cypress/fixtures/images/evening.png', { action: 'drag-drop' }) 24 | cy.get('.controls > h2', { timeout: 7000 }).should('have.text', 'Upload completed!') 25 | cy.get('.imagetitle').should('have.text', 'evening') 26 | }) 27 | 28 | it.only('Multiple file upload using selectFile', () => { 29 | cy.visit('https://postimages.org/') 30 | cy.get('#uploadFile').selectFile([ 31 | 'cypress/fixtures/images/morning.jpg', 32 | 'cypress/fixtures/images/evening.png', 33 | 'cypress/fixtures/images/night.jpg', 34 | ], { action: 'drag-drop' }) 35 | cy.get('.controls > h2', { timeout: 9000 }).should('have.text', 'Upload completed!') 36 | cy.get('.imagetitle').eq(0).should('have.text', 'evening') 37 | cy.get('.imagetitle').eq(1).should('have.text', 'morning') 38 | cy.get('.imagetitle').eq(2).should('have.text', 'night') 39 | }) 40 | }) 41 | }) -------------------------------------------------------------------------------- /cypress/e2e/TC07_fileDownload.cy.js: -------------------------------------------------------------------------------- 1 | import TestFilters from '../support/filterTests.js' 2 | 3 | TestFilters([], () => { 4 | describe('Example to demonstrate file download in cypress', function () { 5 | 6 | it('File Download using cypress-downloadfile npm package', () => { 7 | cy.downloadFile('https://www.learningcontainer.com/wp-content/uploads/2020/04/sample-text-file.txt', 8 | 'cypress/fixtures/Download', 'test.txt') 9 | cy.readFile('cypress/fixtures/Download/test.txt').should('contain', 'Lorem ipsum dolor sit amet') 10 | }) 11 | }) 12 | }) -------------------------------------------------------------------------------- /cypress/e2e/TC08_apiTesting.cy.js: -------------------------------------------------------------------------------- 1 | import TestFilters from '../support/filterTests.js' 2 | 3 | TestFilters(['regression','smoke'], () => { 4 | describe('Example to demonstrate API Testing in cypress', function () { 5 | 6 | it('Hit an API End point and validate its response status code and body', () => { 7 | cy.request({ 8 | method: 'GET', 9 | url: 'https://randomuser.me/api/', 10 | qs: 'results=1' 11 | }).then((response) => { 12 | expect(response.status).to.eq(200) 13 | expect(response.body).to.have.property('info') 14 | expect(response.body.info).to.have.property('version', '1.3') 15 | }) 16 | }) 17 | }) 18 | }) -------------------------------------------------------------------------------- /cypress/e2e/TC09_apiChaining.cy.js: -------------------------------------------------------------------------------- 1 | import TestFilters from '../support/filterTests.js' 2 | 3 | TestFilters([], () => { 4 | describe('Example to demonstrate API Chaining in Cypress', function () { 5 | 6 | it('Chain two API requests and validate the response', () => { 7 | //Part 1 8 | cy.request({ 9 | method: 'GET', 10 | url: 'https://www.metaweather.com/api/location/search/?query=sn', 11 | }).then((response) => { 12 | const location = response.body[0].title 13 | return location 14 | }) 15 | //Part 2 16 | .then((location) => { 17 | cy.request({ 18 | method: 'GET', 19 | url: 'https://www.metaweather.com/api/location/search/?query=' + location 20 | }).then((response) => { 21 | expect(response.status).to.eq(200) 22 | expect(response.body[0]).to.have.property('title', location) 23 | }) 24 | }) 25 | }) 26 | }) 27 | }) -------------------------------------------------------------------------------- /cypress/e2e/TC_10_apiMocking.cy.js: -------------------------------------------------------------------------------- 1 | import TestFilters from '../support/filterTests.js' 2 | 3 | TestFilters([], () => { 4 | describe('Example to demonstrate API Mocking in Cypress', () => { 5 | 6 | beforeEach(() => { 7 | cy.server() 8 | cy.route('GET', '**/tags', 'fixture:tags.json') 9 | cy.route('GET', '**/articles*', 'fixture:articlefeed.json') 10 | cy.visit('https://angular.realworld.io/') 11 | }) 12 | 13 | it('Mock the Tags from the API Response and then validate on UI', () => { 14 | cy.get('.tag-list') 15 | .should('contain', 'cypress') 16 | .and('contain', 'selenium') 17 | 18 | }) 19 | 20 | it('Mock the Article feed from the API Response and then validate on UI', () => { 21 | cy.get('app-favorite-button.pull-xs-right').contains('10') 22 | cy.get('.author').contains('testersdock') 23 | cy.get('.preview-link > p').contains('This is a test description') 24 | }) 25 | }) 26 | }) -------------------------------------------------------------------------------- /cypress/e2e/TC_11_jsAlertConfirmPrompt.cy.js: -------------------------------------------------------------------------------- 1 | describe('Example to demonstrate handling of JavaScript Alerts, Confirm, Prompt in Cypress', () => { 2 | 3 | beforeEach(() => { 4 | cy.visit('http://the-internet.herokuapp.com/javascript_alerts') 5 | }) 6 | 7 | it('Handling JS Alert - Validate Alert Text and Click OK', () => { 8 | cy.contains('Click for JS Alert').click() 9 | cy.on('window:alert', (str) => { 10 | expect(str).to.equal('I am a JS Alert') 11 | }) 12 | cy.on('window:confirm', () => true); 13 | cy.get('#result').should('have.text', 'You successfully clicked an alert') 14 | }) 15 | 16 | it('Handling JS Confirm - Validate Confirm Text and Click OK', () => { 17 | cy.contains('Click for JS Confirm').click() 18 | cy.on('window:confirm', (str) => { 19 | expect(str).to.equal(`I am a JS Confirm`) 20 | }) 21 | cy.on('window:confirm', () => true); 22 | cy.get('#result').should('have.text', 'You clicked: Ok') 23 | }) 24 | 25 | it('Handling JS Confirm - Click Cancel', () => { 26 | cy.contains('Click for JS Confirm').click() 27 | cy.on('window:confirm', () => false); 28 | cy.get('#result').should('have.text', 'You clicked: Cancel') 29 | }) 30 | 31 | it('Handling JS Prompt - Input text in prompt, Click OK and Validate Input Text', () => { 32 | cy.window().then(($win) => { 33 | cy.stub($win, 'prompt').returns('This is a test text') 34 | cy.contains('Click for JS Prompt').click() 35 | }) 36 | cy.get('#result').should('have.text', 'You entered: This is a test text') 37 | }) 38 | }) -------------------------------------------------------------------------------- /cypress/e2e/TC_12_usingskip.cy.js: -------------------------------------------------------------------------------- 1 | import TestFilters from '../support/filterTests.js' 2 | 3 | TestFilters([], () => { 4 | describe('Example to Demostrate the use of skip in cypress', () => { 5 | before(() => { 6 | cy.visit('https://wikipedia.org') 7 | }) 8 | 9 | it.skip('Validate Page Title', () => { 10 | cy.title().should('eq', 'Wikipedia') 11 | }) 12 | 13 | it('Search for Google Wiki Page', () => { 14 | cy.get('#searchInput').type('google') 15 | cy.get('button[type="submit"]').click() 16 | }) 17 | 18 | it.skip('Validate Google Wiki Page has opened', () => { 19 | cy.get('h1#firstHeading').contains('Google') 20 | cy.title().should('eq', 'Google - Wikipedia') 21 | }) 22 | }) 23 | }) -------------------------------------------------------------------------------- /cypress/e2e/TC_13_usingOnly.cy.js: -------------------------------------------------------------------------------- 1 | import TestFilters from '../support/filterTests.js' 2 | 3 | TestFilters([], () => { 4 | describe('Example to Demostrate the use of only in cypress', () => { 5 | before(() => { 6 | cy.visit('https://wikipedia.org') 7 | }) 8 | 9 | it.only('Validate Page Title', () => { 10 | cy.title().should('eq', 'Wikipedia') 11 | }) 12 | 13 | it('Search for Google Wiki Page', () => { 14 | cy.get('#searchInput').type('google') 15 | cy.get('button[type="submit"]').click() 16 | }) 17 | 18 | it('Validate Google Wiki Page has opened', () => { 19 | cy.get('h1#firstHeading').contains('Google') 20 | cy.title().should('eq', 'Google - Wikipedia') 21 | }) 22 | }) 23 | }) -------------------------------------------------------------------------------- /cypress/e2e/TC_14_shadowDOM.cy.js: -------------------------------------------------------------------------------- 1 | import TestFilters from '../support/filterTests.js' 2 | 3 | TestFilters([], () => { 4 | describe('Example to demonstrate the handling of Shadow Dom in Cypress', () => { 5 | beforeEach(() => { 6 | cy.visit('https://books-pwakit.appspot.com/') 7 | }) 8 | 9 | it('Input a text in the input box and after search validate the URL', () => { 10 | cy.get('book-app') //1 11 | .shadow() //2 12 | .find('app-header') //3 13 | .find('.toolbar-bottom') //4 14 | .find('book-input-decorator') //5 15 | .find('#input') //6 16 | .type('Science') 17 | .click() 18 | .url('contains', 'explore?q=Science') 19 | }) 20 | 21 | it('Input a text in the input box and after search validate the URL with includeShadowDom flag set to true', () => { 22 | cy.get('book-app') 23 | .find('#input') 24 | .type('Science', { force: true }) 25 | .click() 26 | .url('include', 'explore?q=Science') 27 | }) 28 | 29 | it('Input a text in the input box and after search validate the URL with includeShadowDom option', () => { 30 | cy.get('book-app') 31 | .find('#input', { includeShadowDom: true }) 32 | .type('Science', { force: true }) 33 | .click() 34 | .url('include', 'explore?q=Science') 35 | }) 36 | }) 37 | }) -------------------------------------------------------------------------------- /cypress/e2e/TC_15_numberOfRetries.cy.js: -------------------------------------------------------------------------------- 1 | import TestFilters from '../support/filterTests.js' 2 | 3 | TestFilters([], () => { 4 | describe('Test to demonstrate Test Retries in Cypress', () => { 5 | before(() => { 6 | cy.visit('https://wikipedia.org') 7 | }) 8 | 9 | it('Validate Page Title', () => { 10 | //Intentionally making it fail to check retries 11 | cy.title().should('eq', 'Wikipedia1111') 12 | }) 13 | }) 14 | }) -------------------------------------------------------------------------------- /cypress/e2e/TC_16_iFrames.cy.js: -------------------------------------------------------------------------------- 1 | import TestFilters from '../support/filterTests.js' 2 | 3 | TestFilters([], () => { 4 | describe('Test to demonstrate testing of iframes in Cypress', () => { 5 | before(() => { 6 | cy.visit('http://the-internet.herokuapp.com/iframe') 7 | }) 8 | 9 | it('Input text in the text editor which is inside an iframe', () => { 10 | cy.getIframe('#mce_0_ifr').clear().type('This is a test description.') 11 | }) 12 | }) 13 | }) -------------------------------------------------------------------------------- /cypress/e2e/TC_17_pageObject1.cy.js: -------------------------------------------------------------------------------- 1 | import TestFilters from '../support/filterTests.js' 2 | 3 | TestFilters([], () => { 4 | describe('Validate Login and Logout on OrangeHRM website', function () { 5 | 6 | beforeEach(function () { 7 | cy.fixture('testdata').then(function (testdata) { 8 | this.testdata = testdata 9 | }) 10 | }) 11 | 12 | it('Validate successful Login', function () { 13 | cy.login(this.testdata) 14 | }) 15 | 16 | it('Validate successful Logout', function () { 17 | cy.logout() 18 | }) 19 | 20 | }) 21 | }) -------------------------------------------------------------------------------- /cypress/e2e/TC_18_cypressStudio.cy.js: -------------------------------------------------------------------------------- 1 | import TestFilters from '../support/filterTests.js' 2 | 3 | TestFilters([], () => { 4 | describe('Example to Demonstrate Cypress Studio', () => { 5 | 6 | it('Extend Test via Cypress Studio', () => { 7 | cy.visit('https://opensource-demo.orangehrmlive.com/index.php/dashboard') 8 | /* ==== Generated with Cypress Studio ==== */ 9 | cy.get('#divUsername > .form-hint').click(); 10 | cy.get('#txtUsername').type('Admin'); 11 | cy.get('#txtPassword').type('admin123'); 12 | cy.get('#btnLogin').click(); 13 | cy.get('#welcome').click(); 14 | cy.get('#welcome-menu > :nth-child(1) > :nth-child(2) > a').click(); 15 | /* ==== End Cypress Studio ==== */ 16 | }) 17 | }) 18 | }) -------------------------------------------------------------------------------- /cypress/e2e/TC_19_intercept.cy.js: -------------------------------------------------------------------------------- 1 | import TestFilters from '../support/filterTests.js' 2 | 3 | TestFilters(['smoke'], () => { 4 | describe('Example to demonstrate API Mocking in Cypress using cy.intercept', () => { 5 | 6 | beforeEach(() => { 7 | cy.intercept('GET', '**/tags', { fixture: 'tags.json' }) 8 | cy.intercept('GET', '**/articles*', { fixture: 'articlefeed.json' }) 9 | cy.visit('https://angular.realworld.io/') 10 | }) 11 | 12 | it('Mock the Tags from the API Response and then validate on UI', () => { 13 | cy.get('.tag-list', { timeout: 10000 }) 14 | .should('contain', 'cypress') 15 | .and('contain', 'selenium') 16 | }) 17 | 18 | it('Mock the Article feed from the API Response and then validate on UI', () => { 19 | cy.get('app-favorite-button.pull-xs-right').contains('10') 20 | cy.get('.author').contains('testersdock') 21 | cy.get('.preview-link > p').contains('This is a test description') 22 | }) 23 | }) 24 | }) -------------------------------------------------------------------------------- /cypress/e2e/TC_20_hoverOverElement.cy.js: -------------------------------------------------------------------------------- 1 | describe('Example to Demostrate how to hover over element in cypress', () => { 2 | 3 | it('Hover and Validate Text using trigger(\'mouseover\')', function () { 4 | cy.visit('https://www.amazon.com/') 5 | cy.get('[data-csa-c-content-id="nav_ya_signin"]').trigger('mouseover') 6 | cy.contains('Create a List').click() 7 | cy.url().should('include','wishlist/intro') 8 | }) 9 | 10 | it('Hover and Validate Text using invoke(\'show\')', function () { 11 | cy.visit('http://automationpractice.com/index.php') 12 | cy.contains('Add to cart', {matchCase: false}).first().click() 13 | cy.get('.cross', {timeout: 5000}).click() 14 | cy.get('#searchbox').scrollTo('center',{ensureScrollable: false}) 15 | cy.get('.cart_block').invoke('show') 16 | cy.contains('Check out', {matchCase: false}).click() 17 | cy.get('.navigation_page').should('have.text', 'Your shopping cart') 18 | }) 19 | 20 | it('Hover and Validate Text using realHover()', function () { 21 | cy.visit('https://the-internet.herokuapp.com/hovers') 22 | cy.get('div:nth-child(3) > img').realHover('mouse') 23 | cy.get('div:nth-child(3) > div > h5').should('be.visible') 24 | cy.get('div:nth-child(4) > img').realHover('mouse') 25 | cy.get('div:nth-child(4) > div > h5').should('be.visible') 26 | cy.get('div:nth-child(5) > img').realHover('mouse') 27 | cy.get('div:nth-child(5) > div > h5').should('be.visible') 28 | }) 29 | }) -------------------------------------------------------------------------------- /cypress/e2e/TC_21_databaseTesting.cy.js: -------------------------------------------------------------------------------- 1 | describe('Example to Demonstrate SQL Database Testing in Cypress', () => { 2 | 3 | it('Create a Table', function () { 4 | cy.task('queryDb', "CREATE TABLE Persons (PersonID int, FirstName varchar(255), Address varchar(255), City varchar(255))") 5 | }) 6 | 7 | it('Input Entries into the table', function () { 8 | cy.task('queryDb', `INSERT INTO Persons (PersonID, FirstName, Address, City) VALUES 9 | (001, "John", "House No. 01", "Helsinki"), 10 | (002, "Pam", "House No. 02", "Espoo"), 11 | (003, "Dwight", "House No. 03", "Lapland"), 12 | (004, "Michael", "House No. 04", "Vantaa");`).then((result) => { 13 | expect(result.affectedRows).to.equal(4) 14 | }) 15 | }) 16 | 17 | it('Update an Entry into the table and verify', function () { 18 | cy.task('queryDb', `UPDATE Persons SET FirstName = "Kevin" WHERE City="Vantaa"`).then((result) => { 19 | expect(result.changedRows).to.equal(1) 20 | }) 21 | cy.task('queryDb', `SELECT FirstName FROM Persons WHERE City="Vantaa"`).then((result) => { 22 | expect(result[0].FirstName).to.equal('Kevin') 23 | }) 24 | }) 25 | 26 | it('Verify that there is only one row where the city is Espoo', function () { 27 | cy.task('queryDb', `SELECT COUNT(*) as "rowCount" FROM Persons WHERE City="Espoo"`).then((result) => { 28 | 29 | expect(result[0].rowCount).to.equal(1) 30 | }) 31 | }) 32 | 33 | it('Delete a Table and Verify', function () { 34 | cy.task('queryDb', `DROP TABLE Persons`).then((result) => { 35 | expect(result.message).to.equal("") 36 | }) 37 | }) 38 | }) -------------------------------------------------------------------------------- /cypress/e2e/TC_22_parentParentsChildren.cy.js: -------------------------------------------------------------------------------- 1 | describe('Example to demonstrate parent, parents and children commands in cypress', () => { 2 | 3 | before(() => { 4 | cy.visit('https://testautomationpractice.blogspot.com/') 5 | }) 6 | 7 | it('Using parents and children', function () { 8 | cy.get('employee#2') 9 | .parents('empinfo') 10 | .children('#3') 11 | .should('contain', 'Marry') 12 | }) 13 | 14 | it('Using parent and children', function () { 15 | cy.get('employee#2') 16 | .parent() 17 | .children('#1') 18 | .should('contain', 'david@myemail.com') 19 | }) 20 | 21 | }) -------------------------------------------------------------------------------- /cypress/e2e/TC_23_dragAndDrop.cy.js: -------------------------------------------------------------------------------- 1 | describe('Example to demonstrate Drag and Drop in cypress', () => { 2 | 3 | beforeEach(() => { 4 | 5 | //Defining browser resolution 6 | cy.viewport(1920, 1080) 7 | }) 8 | 9 | it('Using the cyess-drag-drop plugin on a HTML site', function () { 10 | 11 | cy.visit('https://the-internet.herokuapp.com/drag_and_drop') 12 | 13 | //Before Drag and Drop column-a has 'A' and 'column-b' has 'B' 14 | cy.get('#column-a') 15 | .should('have.text', 'A') 16 | cy.get('#column-b') 17 | .should('have.text', 'B') 18 | 19 | //Drag and drop using cyess-drag-drop plugin 20 | cy.get('#column-a').drag('#column-b') 21 | 22 | //After Drag and Drop column-a has 'B' and 'column-b' has 'A' 23 | cy.get('#column-a') 24 | .should('have.text', 'B') 25 | cy.get('#column-b') 26 | .should('have.text', 'A') 27 | }) 28 | 29 | it('Using custom commands on a Angular Material site', function () { 30 | 31 | cy.visit('https://material.angular.io/cdk/drag-drop/overview#cdk-drag-drop-connected-sorting') 32 | 33 | //Click on 'Accept Cookies' button 34 | cy.get('.buttons > .mat-primary').should('be.visible').click() 35 | 36 | //Check the drop list is visible 37 | cy.get('#cdk-drop-list-1 > div:nth-child(1)', { timeout: 7000 }) 38 | .should('be.visible') 39 | 40 | //Before Drag and Drop the first item is 'Get up' 41 | cy.get('#cdk-drop-list-2 > :nth-child(1)') 42 | .should('have.text', 'Get up') 43 | 44 | //Drag and Drop using custom command 45 | cy.draganddrop('#cdk-drop-list-1 > div:nth-child(1)', '#cdk-drop-list-2') 46 | 47 | //After Drag and Drop the first item is 'Get to work' 48 | cy.get('#cdk-drop-list-2 > :nth-child(1)') 49 | .should('have.text', 'Get to work') 50 | }) 51 | }) -------------------------------------------------------------------------------- /cypress/e2e/TC_24_newBrowserTabWindow.cy.js: -------------------------------------------------------------------------------- 1 | describe('Example to demonstrate the handling of new browser windows in cypress', () => { 2 | 3 | it('Handling new Browser Tab', function () { 4 | cy.visit('https://the-internet.herokuapp.com/windows') 5 | cy.get('.example > a').invoke('removeAttr', 'target').click() 6 | cy.url() 7 | .should('include', '/windows/new') 8 | cy.get('h3') 9 | .should('have.text', 'New Window') 10 | }) 11 | 12 | it('Handling new Browser Window', function () { 13 | cy.visit('https://alapanme.github.io/testing-cypress.html') 14 | cy.window().then((win) => { 15 | cy.stub(win, 'open', url => { 16 | win.location.href = 'https://the-internet.herokuapp.com/'; 17 | }).as("popup") 18 | }) 19 | cy.get('button').click() 20 | cy.get('@popup') 21 | .should("be.called") 22 | cy.get('h1') 23 | .should('have.text', 'Welcome to the-internet') 24 | }) 25 | }) -------------------------------------------------------------------------------- /cypress/e2e/TC_25_filterFindWithin.cy.js: -------------------------------------------------------------------------------- 1 | describe('Example to demonstrate filter, find and within commands in cypress', () => { 2 | 3 | it('Using filter with selector', { tags: 'regression' }, function () { 4 | cy.visit('/') 5 | cy.loginOrangeCRM('Admin', 'admin123') 6 | cy.get('.legendColorBox', { timeout: 7000 }).should('be.visible') 7 | cy.get('td').filter('.legendLabel').eq(1).should('have.text', 'Administration') 8 | }) 9 | 10 | it('Using filter with innerText', function () { 11 | cy.visit('/') 12 | cy.loginOrangeCRM('Admin', 'admin123') 13 | cy.get('.legendColorBox', { timeout: 7000 }).should('be.visible') 14 | cy.get('td').filter(':contains("Client Services")').should('have.text', 'Client Services') 15 | }) 16 | 17 | it('Using find', function () { 18 | cy.visit('https://testautomationpractice.blogspot.com/') 19 | cy.get('empinfo').find('#1 > name').should('have.text', 'David') 20 | }) 21 | 22 | it('Using within', function () { 23 | cy.visit('/index.php/performance/addPerformanceTrackerLog/trackId/3') 24 | cy.loginOrangeCRM('Admin', 'admin123') 25 | Cypress.on('uncaught:exception', (err, runnable) => { 26 | return false 27 | }) 28 | cy.get('tr.odd').should('be.visible').within(() => { 29 | cy.get('.left').eq(0).should('have.text', 'Fiona Grace') 30 | cy.get('.left').eq(1).should('have.text', 'Project X') 31 | cy.get('.left').eq(2).should('have.text', 'Worked long hours to achieve t...') 32 | cy.get('.left').eq(3).should('have.text', 'Positive') 33 | cy.get('.left').eq(4).should('have.text', '2020-10-09') 34 | }) 35 | }) 36 | }) -------------------------------------------------------------------------------- /cypress/e2e/TC_26_jqueryCommands.cy.js: -------------------------------------------------------------------------------- 1 | describe('Example to demonstrate commonly used JQuery commands in cypress', () => { 2 | 3 | it('Check if a button is disabled or enabled', { tags: 'smoke' }, function () { 4 | cy.visit('https://getbootstrap.com/docs/4.0/components/buttons/#disabled-state') 5 | cy.get('button.btn.btn-lg.btn-primary').eq(2).then(($btn) => { 6 | if ($btn.is(':disabled')) { cy.log('Button is disabled') } 7 | else { cy.log('Button is enabled') } 8 | }) 9 | cy.get('button.btn.btn-lg.btn-primary').eq(1).then(($btn) => { 10 | if ($btn.is(':enabled')) { cy.log('Button is enabled') } 11 | else { cy.log('Button is disabled') } 12 | }) 13 | }) 14 | 15 | it('Remove the disabled attribute and validate that button is enabled now', function () { 16 | cy.get('button.btn.btn-lg.btn-primary').eq(2).then(($btn) => { 17 | cy.wrap($btn.removeAttr('disabled')).should('be.enabled') 18 | }) 19 | }) 20 | 21 | it('Assert inner text', function () { 22 | cy.visit('https://testautomationpractice.blogspot.com/') 23 | cy.get('h2.title').eq(0).then(($ele) => { 24 | expect($ele.text()).to.equal('New Windows') 25 | }) 26 | }) 27 | 28 | it('Assert value', function () { 29 | cy.get('input#field1').eq(0).then(($ele) => { 30 | expect($ele.val()).to.equal('Hello World!') 31 | }) 32 | }) 33 | 34 | it('Assert the value of an attribute', function () { 35 | cy.get('#HTML7').then(($ele) => { 36 | expect($ele.attr('data-version')).to.equal('1') 37 | }) 38 | }) 39 | 40 | it('Assert CSS property', function () { 41 | cy.visit('https://the-internet.herokuapp.com/tables') 42 | cy.get('table#table1').then(($ele) => { 43 | expect($ele.css('margin-bottom')).to.equal('20px') 44 | }) 45 | }) 46 | }) -------------------------------------------------------------------------------- /cypress/e2e/TC_27_cypressRecursion.cy.js: -------------------------------------------------------------------------------- 1 | import { recurse } from 'cypress-recurse' 2 | 3 | describe('Example to demonstrate recursion in Cypress', { tags: 'smoke' }, () => { 4 | it('Validate the number 3 using recursion', function () { 5 | cy.visit('https://alapanme.github.io/random-number.html') 6 | recurse( 7 | () => { 8 | cy.reload() 9 | return cy.get('#myNumber').invoke('text').then(parseInt) 10 | }, 11 | (x) => x === 3, 12 | { 13 | log: false, 14 | timeout: 7000, // try up to 7 seconds 15 | limit: 20, // try up to 20 times 16 | delay: 50 // delay before next iteration, ms 17 | } 18 | ).should('equal', 3) 19 | }) 20 | }) -------------------------------------------------------------------------------- /cypress/e2e/TC_28_basicAuth.cy.js: -------------------------------------------------------------------------------- 1 | describe('Example to demonstrate handling of Basic Auth in Cypress', () => { 2 | 3 | it('Successfully login by appending username and password in URL', function () { 4 | cy.visit('https://admin:admin@the-internet.herokuapp.com/basic_auth') 5 | cy.get('p').should('include.text', 'Congratulations! You must have the proper credentials.') 6 | }) 7 | 8 | it('Successfully login using headers', function () { 9 | cy.visit("https://the-internet.herokuapp.com/basic_auth", { 10 | headers: { 11 | authorization: 'Basic YWRtaW46YWRtaW4=' 12 | }, 13 | failOnStatusCode: false 14 | }) 15 | cy.get('p').should('include.text', 'Congratulations! You must have the proper credentials.') 16 | }) 17 | }) -------------------------------------------------------------------------------- /cypress/e2e/TC_29_cypressRecorder.cy.js: -------------------------------------------------------------------------------- 1 | describe('Example to Demonstrate Cypress Recorder by Deploy Sentinel', () => { 2 | 3 | it('Written with DeploySentinel Recorder', () => { 4 | // Load "https://opensource-demo.orangehrmlive.com/index.php/dashboard" 5 | cy.visit('https://opensource-demo.orangehrmlive.com/index.php/dashboard'); 6 | 7 | // Resize window to 1000 x 660 8 | cy.viewport(1000, 660); 9 | 10 | // Click on #txtUsername 11 | cy.get('#txtUsername').click(); 12 | 13 | // Fill "Admin" on #txtUsername 14 | cy.get('#txtUsername').type("Admin"); 15 | 16 | // Click on #txtPassword 17 | cy.get('#txtPassword').click(); 18 | 19 | // Fill "admin123" on #txtPassword 20 | cy.get('#txtPassword').type("admin123"); 21 | 22 | // Click on #btnLogin 23 | cy.get('#btnLogin').click(); 24 | 25 | // Click on "Welcome Paul" 26 | cy.get('#welcome').click(); 27 | 28 | // Click on "Logout" 29 | cy.get('[href="/index.php/auth/logout"]').click(); 30 | }); 31 | }) -------------------------------------------------------------------------------- /cypress/e2e/cucumber-test/login.feature: -------------------------------------------------------------------------------- 1 | Feature: Login 2 | 3 | Scenario Outline: Login to Orange CRM Website 4 | 5 | Given User is at the login page 6 | When User enters username as '' and password as '' 7 | And User clicks on login button 8 | Then User is able to successfully login to the Website 9 | Examples: 10 | | username | password | 11 | | Admin | admin123 | 12 | -------------------------------------------------------------------------------- /cypress/e2e/cucumber-test/login/login.js: -------------------------------------------------------------------------------- 1 | import { Given, When, Then, And } from "@badeball/cypress-cucumber-preprocessor" 2 | 3 | Given('User is at the login page', () => { 4 | cy.visit('https://opensource-demo.orangehrmlive.com/') 5 | }) 6 | 7 | When('User enters username as {string} and password as {string}', (username, password) => { 8 | cy.get('#txtUsername').type(username) 9 | cy.get('#txtPassword').type(password) 10 | }) 11 | 12 | And('User clicks on login button', () => { 13 | cy.get('#btnLogin').click() 14 | }) 15 | 16 | Then('User is able to successfully login to the Website', () => { 17 | cy.get('#welcome').should('be.visible', {timeout: 10000}) 18 | }) -------------------------------------------------------------------------------- /cypress/e2e/examples/actions.spec.js: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | context('Actions', () => { 4 | beforeEach(() => { 5 | cy.visit('https://example.cypress.io/commands/actions') 6 | }) 7 | 8 | // https://on.cypress.io/interacting-with-elements 9 | 10 | it('.type() - type into a DOM element', () => { 11 | // https://on.cypress.io/type 12 | cy.get('.action-email') 13 | .type('fake@email.com').should('have.value', 'fake@email.com') 14 | 15 | // .type() with special character sequences 16 | .type('{leftarrow}{rightarrow}{uparrow}{downarrow}') 17 | .type('{del}{selectall}{backspace}') 18 | 19 | // .type() with key modifiers 20 | .type('{alt}{option}') //these are equivalent 21 | .type('{ctrl}{control}') //these are equivalent 22 | .type('{meta}{command}{cmd}') //these are equivalent 23 | .type('{shift}') 24 | 25 | // Delay each keypress by 0.1 sec 26 | .type('slow.typing@email.com', { delay: 100 }) 27 | .should('have.value', 'slow.typing@email.com') 28 | 29 | cy.get('.action-disabled') 30 | // Ignore error checking prior to type 31 | // like whether the input is visible or disabled 32 | .type('disabled error checking', { force: true }) 33 | .should('have.value', 'disabled error checking') 34 | }) 35 | 36 | it('.focus() - focus on a DOM element', () => { 37 | // https://on.cypress.io/focus 38 | cy.get('.action-focus').focus() 39 | .should('have.class', 'focus') 40 | .prev().should('have.attr', 'style', 'color: orange;') 41 | }) 42 | 43 | it('.blur() - blur off a DOM element', () => { 44 | // https://on.cypress.io/blur 45 | cy.get('.action-blur').type('About to blur').blur() 46 | .should('have.class', 'error') 47 | .prev().should('have.attr', 'style', 'color: red;') 48 | }) 49 | 50 | it('.clear() - clears an input or textarea element', () => { 51 | // https://on.cypress.io/clear 52 | cy.get('.action-clear').type('Clear this text') 53 | .should('have.value', 'Clear this text') 54 | .clear() 55 | .should('have.value', '') 56 | }) 57 | 58 | it('.submit() - submit a form', () => { 59 | // https://on.cypress.io/submit 60 | cy.get('.action-form') 61 | .find('[type="text"]').type('HALFOFF') 62 | 63 | cy.get('.action-form').submit() 64 | .next().should('contain', 'Your form has been submitted!') 65 | }) 66 | 67 | it('.click() - click on a DOM element', () => { 68 | // https://on.cypress.io/click 69 | cy.get('.action-btn').click() 70 | 71 | // You can click on 9 specific positions of an element: 72 | // ----------------------------------- 73 | // | topLeft top topRight | 74 | // | | 75 | // | | 76 | // | | 77 | // | left center right | 78 | // | | 79 | // | | 80 | // | | 81 | // | bottomLeft bottom bottomRight | 82 | // ----------------------------------- 83 | 84 | // clicking in the center of the element is the default 85 | cy.get('#action-canvas').click() 86 | 87 | cy.get('#action-canvas').click('topLeft') 88 | cy.get('#action-canvas').click('top') 89 | cy.get('#action-canvas').click('topRight') 90 | cy.get('#action-canvas').click('left') 91 | cy.get('#action-canvas').click('right') 92 | cy.get('#action-canvas').click('bottomLeft') 93 | cy.get('#action-canvas').click('bottom') 94 | cy.get('#action-canvas').click('bottomRight') 95 | 96 | // .click() accepts an x and y coordinate 97 | // that controls where the click occurs :) 98 | 99 | cy.get('#action-canvas') 100 | .click(80, 75) // click 80px on x coord and 75px on y coord 101 | .click(170, 75) 102 | .click(80, 165) 103 | .click(100, 185) 104 | .click(125, 190) 105 | .click(150, 185) 106 | .click(170, 165) 107 | 108 | // click multiple elements by passing multiple: true 109 | cy.get('.action-labels>.label').click({ multiple: true }) 110 | 111 | // Ignore error checking prior to clicking 112 | cy.get('.action-opacity>.btn').click({ force: true }) 113 | }) 114 | 115 | it('.dblclick() - double click on a DOM element', () => { 116 | // https://on.cypress.io/dblclick 117 | 118 | // Our app has a listener on 'dblclick' event in our 'scripts.js' 119 | // that hides the div and shows an input on double click 120 | cy.get('.action-div').dblclick().should('not.be.visible') 121 | cy.get('.action-input-hidden').should('be.visible') 122 | }) 123 | 124 | it('.rightclick() - right click on a DOM element', () => { 125 | // https://on.cypress.io/rightclick 126 | 127 | // Our app has a listener on 'contextmenu' event in our 'scripts.js' 128 | // that hides the div and shows an input on right click 129 | cy.get('.rightclick-action-div').rightclick().should('not.be.visible') 130 | cy.get('.rightclick-action-input-hidden').should('be.visible') 131 | }) 132 | 133 | it('.check() - check a checkbox or radio element', () => { 134 | // https://on.cypress.io/check 135 | 136 | // By default, .check() will check all 137 | // matching checkbox or radio elements in succession, one after another 138 | cy.get('.action-checkboxes [type="checkbox"]').not('[disabled]') 139 | .check().should('be.checked') 140 | 141 | cy.get('.action-radios [type="radio"]').not('[disabled]') 142 | .check().should('be.checked') 143 | 144 | // .check() accepts a value argument 145 | cy.get('.action-radios [type="radio"]') 146 | .check('radio1').should('be.checked') 147 | 148 | // .check() accepts an array of values 149 | cy.get('.action-multiple-checkboxes [type="checkbox"]') 150 | .check(['checkbox1', 'checkbox2']).should('be.checked') 151 | 152 | // Ignore error checking prior to checking 153 | cy.get('.action-checkboxes [disabled]') 154 | .check({ force: true }).should('be.checked') 155 | 156 | cy.get('.action-radios [type="radio"]') 157 | .check('radio3', { force: true }).should('be.checked') 158 | }) 159 | 160 | it('.uncheck() - uncheck a checkbox element', () => { 161 | // https://on.cypress.io/uncheck 162 | 163 | // By default, .uncheck() will uncheck all matching 164 | // checkbox elements in succession, one after another 165 | cy.get('.action-check [type="checkbox"]') 166 | .not('[disabled]') 167 | .uncheck().should('not.be.checked') 168 | 169 | // .uncheck() accepts a value argument 170 | cy.get('.action-check [type="checkbox"]') 171 | .check('checkbox1') 172 | .uncheck('checkbox1').should('not.be.checked') 173 | 174 | // .uncheck() accepts an array of values 175 | cy.get('.action-check [type="checkbox"]') 176 | .check(['checkbox1', 'checkbox3']) 177 | .uncheck(['checkbox1', 'checkbox3']).should('not.be.checked') 178 | 179 | // Ignore error checking prior to unchecking 180 | cy.get('.action-check [disabled]') 181 | .uncheck({ force: true }).should('not.be.checked') 182 | }) 183 | 184 | it('.select() - select an option in a