http://www.technicalpage.net/search/label/SQL

CypressQAndA

 Cypress InterView Quesitons And Answers

1.      Cy.log and console.log

Cy.log gives the log in the cypress console,

Console.log gives the log in the browser console.

 

2.      Different way to run cypress test

npx cypress run -- headed -b chrome --spec "path\specfile.js" 

./node_modules/.bin/cypress run --spec cypress/integration/specfile.js --browser chrome

 

3.           How to read file in cypress ?
cy.readFile('path'.then((value)=>{
cy.log(value.id);
})

 

4.      How can I write to a file ?
cy.writeFile('path',{name:'testing', last: 'something'})

  

5.    Mention some cypress commands ?
Cy.get()
Cy.visit()
Cy.url()
Cy.get().type()
Cy.get().click()
Cy.get().clear()
Cy.log()
Cy.get().check()

Cy.wait()

Cy.title()

 

6.      Define environment variable in Cypress and change it dynamically.
In cypress.json we define environment variable as key and value pair like below :
{
     “env” : {
            Key : value
}
       }

To save the variable:
let envValue = Cypress.env(‘key’)
And we use the environment variable like below :
Cy.visit(Cypress.env(‘key’))
Or
Cy.visit(envValue)

To change the value dynamically, we use below code:
Cypress run – env “key” = “newValue”

 

7.      How you install cypress with a particular version ?

 

Npm install cypress@versionNumber

 

8.      How you avoid automatic execution after any change or edit ?

In cypress.config.js we add a command : “watchForFileChanges: false”

 

9.      Assertions in Cypress;

Implicit such as should(be,have,eq,contain, be.visible, be.disabled, be.selected, have.length, have.text, have.html, not have ), and(chained Assertion)

Explicit such as expect, assert

 

10.   Open Cypress:

Npx cypress open

 

11.   How to use “Only” and “skip” in the test cases

it.only('TestCase1', function () {}

it.skip('TestCase3', function () {}

 

12.   How to upload a file in Cypress?

We can upload a file in cypress by using .selectFile() command.

cy.get('locator’)

.selectFile('path/file.png')

No comments:

Post a Comment