How to Run Cypress Test from command line
PS C:\Users\T460\AppData\Local\Cypress\Cache\4.9.0\Cypress\project> cypress run --spec cypress/integration/code/cura.js --browser=chrome
Here cura.js is the file where you have written test cases, So note here we have given relative path
cypress/integration/code/
To Parameterize the baseURL
Example
describe('Cura Make an Appointment',function(){
it('Visit URL',function(){
cy.visit(Cypress.env('baseUrl'))
})
})
In command line, type below commands
PS C:\Users\T460\AppData\Local\Cypress\Cache\4.9.0\Cypress\project> cypress run --spec cypress/integration/code/cura.js --browser=chrome --env baseUrl="https://katalon-demo-cura.herokuapp.com/profile.php"
Sample Test case
describe('Cura Make an Appointment',function(){
it('Visit URL',function(){
cy.visit(Cypress.env('baseUrl'))
})
it('Click on Make Appointment',function(){
cy.get('#btn-make-appointment').click()
cy.get('#txt-username').type('John Doe')
cy.get('#txt-password').type('ThisIsNotAPassword')
cy.get('#btn-login').click()
})
it(' Make Appointment',function(){
cy.get('select').select('Hongkong CURA Healthcare Center')
cy.get('#chk_hospotal_readmission').click({force:true})
cy.get('#radio_program_medicaid').click()
cy.get('#txt_visit_date').type('11/03/2020')
cy.get('#txt_comment').click({force:true})
cy.get('#txt_comment').type('txt_comment')
cy.get('#btn-book-appointment').click({force:true})
})
it('Verify Appointment',function(){
cy.get('h2').contains('Appointment Confirmation')
cy.get('#comment').contains('txt_comment')
})
})
Note: For certain cases we have used click({force:true})
Force a click regardless of its actionable state
Cypress Visit with Timeout
cy.visit('https://katalon-demo-cura.herokuapp.com/profile.php',{timeout:3})
cy.visit('https://katalon-demo-cura.herokuapp.com/profile.php',{retryOnNetworkFailure:true})
Assertions
describe('Inputs',function(){
it('Visit URL',function(){
cy.visit('https://the-internet.herokuapp.com/inputs',{retryOnNetworkFailure:true})
cy.get('#content > div > div > div > input[type=number]').as('numbersText')
cy.get('@numbersText').should('have.text','')
cy.get('@numbersText').should(function($numbersText){
expect($numbersText).to.have.length(1)
})
})
})
as('numbersText')--> This is a variable which we are storing
No comments:
Post a Comment