2.Create Sample API Test Script
2.Create Sample API Test Script
GENERAL
cy.request(url)
• cy.request("https://
jsonplaceholder.cypress.io/comments");
GENERAL
cy.request(url, body)
• cy.request('https://
jsonplaceholder.cypress.io/posts', {
"key": "value1",
"key2": "value2"
})
GENERAL
cy.request(method, url)
cy.request("GET",
"https://jsonplaceholder.cypress.io/comments");
GENERAL
cy.request(method, url, body)
• cy.request( "POST",
'https://jsonplaceholder.cypress.io/posts',
{"one": "1 value","two": "2 value"})
GENERAL
Cypress project Structure
• Create cypress test cy.js files under e2e folder
• Json files under fixtures folder
• Test file creenshots save under screenshots folder
• Support folder use support files(command.js and e2e.js)
• Create commands in command.js file
• e2e.js file loaded automatically before running tests
• Test file videos save under videos folder
• cypress.config.js for configuration
• package.json (add dependency and needed scripts)
GENERAL
Real project Package.json
• Scripts for run shortcut, repository for git and devDependencies for
dependency used in real project
GENERAL
Test Structure
• The test interface, borrowed from Mocha,
provides describe(), context(), it() and specify().
GENERAL
Test hook
• describe('TestSuite Name', function() { });
• it('Test Case Name', function() { })
• Cypress provides two tags: ".only" and ".skip"to implement the
inclusion/exclusion strategy for the test runs
• describe.only('TestSuite Name', function() { });//only run testSuite
• describe.skip('TestSuite Name', function() { });//skip testSuite
• it.only('Test Case Name', function() { })//only run this test case
• it.skip('Test Case Name', function() { })//skip this test case
GENERAL
Mostly used assertions in project
Chainer Example
not expect(name).to.not.equal('Jane')
true expect(true).to.be.true
false expect(false).to.be.false
property(name, [value]) expect(obj).to.have.property('name')
lengthOf(value) expect('test').to.have.lengthOf(4)
equal expect(1).to.equal(1);
expect('foo').to.equal('foo');
GENERAL
feeTable Get Method
GENERAL
Assignment Get promotion list &
details (get-promotion.cy.js)
• https://preprodnewapi.wavemoney.io:8112/v2/mfs-
customer/categories (Get category)
• https://preprodnewapi.wavemoney.io:8112/v2/mfs-
customer/promotions/categories/categoryId(from get
category API)
GENERAL