0% found this document useful (0 votes)
179 views8 pages

Cypress Interview Questions

Cypress is a modern JavaScript-based front-end testing tool that operates within the browser, allowing for easier and more reliable testing. It features automatic waiting, built-in assertions, and the ability to take snapshots and record videos of tests, but supports only JavaScript and certain browsers. Cypress offers a unique architecture that interacts with a Node server process, differentiating it from tools like Selenium, and includes capabilities for API testing, handling test data, and generating reports through third-party plugins.

Uploaded by

sadiq
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
179 views8 pages

Cypress Interview Questions

Cypress is a modern JavaScript-based front-end testing tool that operates within the browser, allowing for easier and more reliable testing. It features automatic waiting, built-in assertions, and the ability to take snapshots and record videos of tests, but supports only JavaScript and certain browsers. Cypress offers a unique architecture that interacts with a Node server process, differentiating it from tools like Selenium, and includes capabilities for API testing, handling test data, and generating reports through third-party plugins.

Uploaded by

sadiq
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

1)What is the Cypress Tool used for?

Cypress is a modern javascript-based front-end testing tool written in node js. Cypress runs tests
within the browser, which makes testing easier and more reliable.

2)Explain Cypress architecture.

Behind Cypress is a Node server process. Tools like Selenium operates outside the web browser
while The Cypress engine is coupled within the browser.

Cypress and the Node process constantly interact, synchronise, and conduct tasks on each other’s
behalf. Cypress operates at the network layer, reading and modifying web traffic in real-time.
This allows Cypress to modify not just everything coming in and out of the browser, but also
code that may interfere with its ability to automate the browser.

3)What are the Cypress features?

1)Cypress can run tests and also execute commands on the browser. so tests are less flaky and
much fast.
2)Automatic wait
3)Cypress can take snapshots and record videos of tests after executing each step. We don’t need
to configure extra plugins like we do in Selenium.
4)Built-in assertions available.
5)Network traffic control.

4)What browsers are supported by Cypress?

Cypress supports the following browsers:-

Chrome, Chromium, Edge, Firefox, Electron

5)How Cypress is different then Selenium.

• Cypress Supports only JavaScript/Typescript languages while Selenium supports all


major languages like C#, Java, Python, JavaScript, Ruby, etc.
• Selenium supports all major browsers Chrome, Edge, Internet Explorer, Safari, and
Firefox while Cypress support only Chrome, Firefox, and Edge.
• Configuration is difficult in Selenium however Cypress comes with ready to use
framework.
• Cypress is built on top of the mocha framework.

6)What Testing Framework does Cypress come with?

We cannot use the Junit or TestNG in Cypress, Cypress comes with Mocha and Chai assertion
libraries.
7)How to create a test suit in Cypress?

A test suit referred to a collection of test cases. We can create a test suit in Cypress using
describe() block or context() block. The describe() block acts as a suite, and inside that block,
each test can be written as a single it() block.

describe('Test Suite', () => {


it('Tc01', () => {
//code
})
})

8)How to interact with DOM elements in Cypress?

Cypress only supports CSS Selector. However, we can use the Cypress-Xpath plugin to work
with Xpath.

9)Can we use XPath in Cypress?

Cypress by default does not support XPath. However, there is one plugin Cypress-Xpath by
which we can use XPath to interact with DOM elements.

install this plugin using the npm

npm install -D @cypress/xpath

Go to support->e2e.js and add the following dependency

require('@cypress/xpath');

10)Can we use BDD with Cypress?

Cypress does not offer official BDD built-in support, however, the NPM Cypress-Cucumber-
Preprocessor plugin allows you to write your tests in BDD Cucumber Syntax. This plugin
automatically translates Gherkin syntax into Cypress.

11)How to verify the title of the page in Cypress?

There are built-in assertions available in Cypress. By using the “should” assertion we can verify
the title of a webpage in Cypress.

cy.title().should('eq','My Site Title')

12)What are hooks in Cypress?

Cypress hooks are used to define or set preconditions that we want to execute before a set of tests
or before each test. For example, if we want to read test data from a fixture file or we want to
perform some configuration tasks, or cleanup tasks then we can utilize Cypress hooks concepts.
The available hooks in Cypress are before(),beforeEach(), after() and afterEach().

13)How to read values from the Configuration file in Cypress.

We can read the configuration values from Cypress using Cypress.config();

For example, if we have defined the env in the config.json file like this:

{"env": stage}

same can be accessed in scripts like

let timeout = Cypress.config('env')

14)How is the test data maintained in Cypress?

The fixtures folder keeps all the necessary data in the Cypress project. It helps us to get the input
data from external files. This directory can store multiple JSON files and these JSON files are
read by multiple tests. All fixture data has to be declared within the before hook block.

Refer to the sample fixture file.

{
"Username": "AQH",
"City" : "DELHI"
}
cy.fixture(path of test data)

path: Location of the JSON file.

15)How to read Fixture file?

To read the fixture file we need to use the before hook.

describe("Cypress Fixtures Example", function () {


before(function () {
cy.fixture('file.json').then(function (testdata) {
this.testdata = testdata
})
})
})

16)How to verify that a button is visible or not?

To verify whether the button is visible or not on the webpage use inbuilt Cypress assertion.

cy.get('button#form-submit').should('be.visible')
17)How many types of assertions are available in Cypress?

Assertions are the validations that verify that this behaviour or functionality is intended or not.
There are 2 types of assertions available in Cypress.

1)Implicit Assertions: These are inbuilt assertions. We can have positive as well as negative
implicit assertions. Perfect examples of implicit assertions are should() or and() type assertions.

1.1)Positive Assertion

cy.get('li.todo').should('have.length', 3)

1.2)Negative Assertion

cy.get('li.todo').should('not.have.length', 2)

2)Explicit Assertions: Explicit assertions are used to perform some custom logic before
applying assertion. An example of explicit assertion is the “expect()” assertion.

const employee =
{ name: 'QA', age: 30, }

assert.isObject(employee, 'value is object')

18)How to perform API testing in Cypress?

To perform API testing in Cypress use cy. request().

describe('API Testing in cypress', function () {

it('Hit Get Request validate its response status code and body', () => {
cy.request({
method: 'GET',
url: 'https://randomuser.me/api/',
qs: 'results=1'
}).then((response) => {
expect(response.status).to.eq(200)
expect(response.body).to.have.property('info')
})
})
})

19)How to execute tests in a particular order in Cypress?

To execute Cypress tests, put all the file names in the desired order in the Cypress.JSON file
under the test files property section.
20)How to handle reusability in the Cypress framework?

By default Cypress includes the index.js and commands.js in the Support folder. Index.js
executes before every test file. We can put reusable behaviour such as custom commands and
global overrides in this folder.

21)What are the drawbacks of the Cypress testing tool?

• Supports only JavaScript.


• No support for multiple tabs.
• Iframes are not supported.
• Only available for Web Testing.

22)How to perform browser navigation in Cypress?

Cypress has a go() command to navigate forward and backwards in the browser.

1. To go forward

cy.go('forward')
or
cy.go(1)

2. To go backwards

cy.go('back')
or
cy.go(-1)

23)How to click a hidden element in Cypress?


cy.get('.checkbox').check({ force: true })

24)How to skip a test in Cypress?

We can use it.skip() or describe.skip(). That it/describe block will be skipped during test
execution.

25)How to upload a file in Cypress?

By using .selectFile() command, a file can be uploaded easily.

cy.get('#upload')
.selectFile('cypress/images/logo.png')

26)How to scroll into view in Cypress?

Cypress has the scrollIntoView() command which scrolls an element into view.

cy.get('footer').scrollIntoView()
or
cy.get('#nav').scrollIntoView({ offset: { top: 150, left: 0 } }) //scroll
using offset

27)How to select the child element in Cypress?

Use the cy. children() command to select the child element of a given element.

cy.get('div.icon-nav > ul').children('.mobile-search').click()

28)How to run tests in headless mode in Cypress?


cypress run --headless --browser chrome

29)What are the other alternatives to the Cypress tool?

Several alternatives are available in the market of Cypress. A few of them are as followed.

1.WebdriverIO

2. CasperJS

3. Playwright
4. Jest

30)How to generate a test report in Cypress?

Cypress does not provide built-in support to generate test reports but we can integrate third-party
plugins like Mochawesome, and Allure to generate HTML reports. Please visit this article to
know how to generate reports in the Cypress framework.

31)How do logging in to Cypress?

We don’t need to add any plugin to perform logging in Cypress. Cypress provides the “cy.log()”
command. This command prints the message on the console.

32)What is the role of the cy.visit() command in Cypress?

The cy. visit() command is used to navigate to a specific URL or route in Cypress tests. It allows
you to start your test at a specific page or state.

{
"baseUrl" : "https://www.programsbuzz.com/"
}
describe('Automating The Signin',()=> {
it('visit the site ',()=>{
cy.visit('/')
})
})

33)How to check your application’s responsiveness?

To check the application’s responsiveness we can use “cy. viewport()” command. It manages the
orientation and dimension of the application.

describe('Test to get window size', function() {


it('Get the window size', function() {
cy.viewport()
cy.viewport(320, 480)
})
})

34)How to capture screenshots in the Cypress framework?

In Cypress, we don’t need to add any dependency or plugin to capture screenshots like we used
to do in Selenium. Cypress has the inbuilt capability to capture screenshots of the fail tests. It
also allows us to take explicit screenshots during test execution. For example, if for debugging
purposes later I want to take a screenshot of a step where the user provided some input then we
can do this by using the following command.

cy.screenshot()
This post covers a wide range of topics related to Cypress interview questions. Gain Practical
experience in Cypress tool to understand the topics.

You might also like