SlideShare a Scribd company logo
1 of 13
Om
Q: Explain Cypress Architecture?
Ans:
Most testing tools (such as Selenium) work by operating outside of the
browser and performing network commands. The Cypress engine, on the
other hand, runs entirely within the browser. In other words, your test code
is executed by the browser.
It allows Cypress to listen in on browser activity and manipulate it in real
time by manipulating the DOM and changing network requests and
responses on the fly.
In the case of Selenium, each browser has provided its own driver, which
communicates with the browser instances to carry out the commands. On the
contrary, in Cypress, all commands are executed within the browser.
Canary, Chrome, Electron(Default), Chromium, Mozilla Firefox (beta
support), and Microsoft Edge (Chromium-based) browsers are all supported
by Cypress.
Unit, functional, integration, and end-to-end testing are all possible with
Cypress. It meets all of the requirements for a Test Pyramid.
Q: What is Cy route?
Ans:
To manage the behaviour of network requests, use cy.route().
cy.server() and cy.route() have been deprecated in Cypress 6.0.0. Support
for .server() and cy.route() will be moved to a plugin in a future release.
What are the advantages of Cypress?
๏‚ท Cypress works with Single Page Applications and internal Ajax Calls.
๏‚ท Cypress can take snapshots of tests after executing each step.We don't
need to have configuration with cypress.
๏‚ท Cypress can provide access to the developer tools so they can debug
directly into the browser.
๏‚ท Cypress can run tests and also execute commands on the browser.
๏‚ท Cypress can execute commands easily and fast than Selenium based
tools.
What are the features of Cypress?
๏‚ท Time Travel - Cypress is used to take snapshots as our tests runs.
๏‚ท Debuggability - Cypress stops guessing why our tests are failing.It
can debug tools such as Developer Tools.
๏‚ท Automatic Waiting - Cypress will add to our tests and wait for
commands and assertions before moving on.
๏‚ท Screenshots and Videos - Cypress is used in viewing screenshots that
are taken automatically on the failure of our entire test suite while
running from CLI.
Test Runner helps in testing in an interactive runner which helps by
allowing us to see command and execute while viewing the application
under the test.
Test Status helps in showing us a summary of what tests Passed, Failed, or
in Progress.
URL Preview helps in showing us the URL of our test and also helps in
tracking the URL Route.
Viewport Sizing helps in setting our app viewport size for testing layouts.
Command Log helps in showing us the command logs while executing the
tests.
App Preview helps in seeing the the tests while executing the commands.
What is Cypress run?
Cypress Run helps in executing our cypress tests in Headless Browsers. It
helps in opening a New Browser Tab and in loading Cypress at the URL
Cypress which was installed from it. Cypress helps in detecting cypress.json,
it also runs cypress tests in the webpack monitor.
How can we access shadow DOM in Cypress?
Shadow DOM helps in allowing hidden DOM Trees which needs to be
attached to the elements in the regular DOM Tree. Shadow DOM can be
understood by the following command:
cy.get('#locator').shadow().find('.nb-btn').click()
How can we create custom commands in Cypress?
We can create custom commands by using the following command:
Cypress.Commands.add("login", (username, password) => {
cy.get("#username").type(username);
cy.get("#password").type(password);
cy.get("#login").click();
});
How do we press keyboard keys in Cypress?
We can press keyboard keys by using the following command:
cy.get('#locator').type('{shift}{alt}'));
How Cypress architecture is different from selenium?
Selenium relies on WebDriver to execute the commands that means
selenium executes remote command across the network. But in the cypress,
it directly operates inside the browser. So the browser executes the
commands which we run as script.
Explanation: Real world scenario,
Consider Selenium,
If I have element.click() in my test script, Once I execute this script
selenium sends this code to browser specific drivers like ChromeDriver,
Ghecko Driver etc. The browser specific drivers then interact with specific
browsers like Chrome, Firefox etc. and executes the click action.
Consider Cypress,
The same command element.click() Considering Cypress.
Once you execute code in Cypress, The cypress directly sends the code to
browser and click action gets executed.
So with the above example we can understand that the middle layer that
is webdriver which is present in the selenium but Cypress doesnโ€™t need any
middle layer.
Could you tell me about some differences between Cypress and
Selenium?
๏‚ท Selenium supports all major languages like C#, Java, Python,
JavaScript, Ruby etc.
๏‚ท Cypress Supports only JavaScript/Typescript languages
๏‚ท Selenium Commands are executed through web drivers
๏‚ท Cypress Commands Executed directly on the browser
๏‚ท Selenium Supports all major browsers chrome,Edge, Internet
Explorer, Safari, Firefox
๏‚ท Cypress supports only Chrome, Edge and Firefox
๏‚ท With Selenium Configuration of drivers and language biding should
be done by our own
๏‚ท With Cypress we get ready framework available we just need to
install.
๏‚ท Selenium Appium can we used to test native mobile applications
๏‚ท Cypress doesnโ€™t support any native mobile application testing
What is the disadvantage of using Cypress?
๏‚ท Cypress doesnโ€™t supports only Javascript/Typescript
๏‚ท Cypress doesnโ€™t supports all the browsers like Safari, Internet
Explorer is not supported
๏‚ท Cypress doesnโ€™t support multiple tabs
๏‚ท We cannot run cypress tests on multiple browsers at the same time.
๏‚ท Cypress doesnโ€™t support Iframe
Can I use Junit or TestNG in cypress?
Or
What is Testing Framework Cypress comes with?
We cannot use the Junit or TestNG in Cypress, Cypress comes with Mocha
and Chai assertion libraries.
How can I install cypress?
If you want to install cypress, we need to install Node first, once we install
node we can install cypress with command npm install cypress
Could you talk something about Cypress file and folder structures?
๏‚ท Cypress uses cypress.json file, if we want to specify any custom
configuration which is located in the root of our project.
๏‚ท The folder named cypress is located in the project root folder which
is main folder for cypress automation framework.
๏‚ท By default Cypress folder contains 4
subfolders namely fixtures, integration, plugins and support.
๏‚ท Fixtures folder can be used to store our external Json data files and
we can use these files in our tests using the command cy.fixture().
๏‚ท Integration folder mainly consists of our actual spec/test files
๏‚ท Plugins folder contains special files that executes in Node before
project is loaded, before the browser launches, and during your test
execution. This is very helpful when we want to have pre processers
and post processors. Files in this folder can be executed after all the
test execution is complete as well.
7. Example: Let us consider, If we want to generate HTML result after
all the test is completed. The HTML report generation or collating
those HTML reports can be done here in this file.
8. Support folder contains the special file index.js which will be run
before each and every test. Support folder can also be used to create
utility methods which will be helpful in through out our automation
framework. This file is the perfect place to put all your reusable
behavior such as Custom commands or global overrides that you want
to be applied to all of your spec files.
What is Cypress CLI?
Cypress CLI is unique feature in cypress it provides ability to run our
cypress tests in command line. This feature is helpful when we run our
cypress tests in pipelines. It provides many options and flags control the
cypress test behavior.
Example: use npm cypress run to run your tests in command line.
How can I run single specfile in command line?
We can run single spec file in command line using - - spec option and
specifying test name.
Example: npm cypress run - - spec=โ€myspec.tsโ€
Tell me at least 5 Cypress commands?
cy.visit(): cy.visit() is used to navigate to the specific website
Ex: cy.visit(โ€˜http://www.google.comโ€™);
cy.log(): cy.log is used for display cypress console logs during execution
Ex: cy.log(โ€˜test 123โ€™);
cy.get(): cy.get is used for getting dom element in cypress, once we get dom
element we can perform action on that like click, type etc.
Example: let myElement = cy.get(โ€˜#usernameโ€™)
cy.url(): cy.url() is used to Get the current URL of the page that is currently
active.
Example: Consider you have navigate to https://google.com using
cy.visit();, now you can use the cy.url() to get the url back.
How can I create suites in cypress?
We can create a describe() block the describe block acts as suite, inside that
each test can be created as single it() block.
Describe() is like a suite here.
List out some commands which I can use to interact with DOM
elements?
.click() : is used to click on the element
Example:
cy.get('#search').click()
.dblclick() : is used to double click on the element.
Example:
cy.get('input[name="btnK"]').dblclick();
.rightclick(): is used to right click on the element
Example:
cy.get('body').rightclick();
.type() : is used to type on element or text boxes
Example:
cy.get('input[name="texbox"]').type("This is to test");
.clear() : is used to clear the fields or text boxes.
Example:
cy.get('input[name="q"]').clear();
.check() : is used to Check checkbox(es) or radio(s).
Example:
cy.get('input[name="chkbox"]').check();
.uncheck() : is used to unCheck checkbox(es) or radio(s).
Example:
cy.get('input[name="chkbox"]').uncheck();
.select(): Select an <option> within a <select>
Example:
cy.get('select').select('user-1')
Consider a scenario, I have link on webpage and clicking this link opens
new window I need to verify some text in that window. How can I
verify?
Cypress by default doesnโ€™t support, working with new windows so we need
to follow different approach here.
Letโ€™s consider example:
<a href="http://google.com" target="_blank"> Take me to Google </a>
In the above code clicking on Take me to Google link opens the new
window the reason is we have attribute target="_blank". So now if we
remove attribute. target="_blank" then it will open in the same window.
That can be performed by below code
What are the selectors supported by Cypress?
By Default cypress supports only CSS selectors, However we can use third
party plugin to use Xpath selectors
Can I use XPath in Cypress?
Cypress doesnโ€™t support xpath by default, but if we install third party plugin
like cypress-xpath we can use xpath in your script.
Example:
We need to install cypress-xpath in our project first using
How can I read the value from Cypress Configuration file?
We can read the cypress.config values from cypress using Cypress.config();
Example:
If I have defined pageLoadTimeout in config file like blow.
Below code is in cypress.json
Cypress.docx

More Related Content

Similar to Cypress.docx

Selenium Automation Using Ruby
Selenium Automation Using RubySelenium Automation Using Ruby
Selenium Automation Using Ruby
Kumari Warsha Goel
ย 

Similar to Cypress.docx (20)

Selenium Automation Using Ruby
Selenium Automation Using RubySelenium Automation Using Ruby
Selenium Automation Using Ruby
ย 
Uploading files using selenium web driver
Uploading files using selenium web driverUploading files using selenium web driver
Uploading files using selenium web driver
ย 
Automated UI testing. Selenium. DrupalCamp Kyiv 2011
Automated UI testing. Selenium. DrupalCamp Kyiv 2011Automated UI testing. Selenium. DrupalCamp Kyiv 2011
Automated UI testing. Selenium. DrupalCamp Kyiv 2011
ย 
SaltConf14 - Ben Cane - Using SaltStack in High Availability Environments
SaltConf14 - Ben Cane - Using SaltStack in High Availability EnvironmentsSaltConf14 - Ben Cane - Using SaltStack in High Availability Environments
SaltConf14 - Ben Cane - Using SaltStack in High Availability Environments
ย 
Salt conf 2014 - Using SaltStack in high availability environments
Salt conf 2014 - Using SaltStack in high availability environmentsSalt conf 2014 - Using SaltStack in high availability environments
Salt conf 2014 - Using SaltStack in high availability environments
ย 
Knolx session
Knolx sessionKnolx session
Knolx session
ย 
CSS Regression Tests
CSS Regression TestsCSS Regression Tests
CSS Regression Tests
ย 
AD113 Speed Up Your Applications w/ Nginx and PageSpeed
AD113  Speed Up Your Applications w/ Nginx and PageSpeedAD113  Speed Up Your Applications w/ Nginx and PageSpeed
AD113 Speed Up Your Applications w/ Nginx and PageSpeed
ย 
Automated ui testing with selenium. drupal con london 2011
Automated ui testing with selenium. drupal con london 2011Automated ui testing with selenium. drupal con london 2011
Automated ui testing with selenium. drupal con london 2011
ย 
A Fabric/Puppet Build/Deploy System
A Fabric/Puppet Build/Deploy SystemA Fabric/Puppet Build/Deploy System
A Fabric/Puppet Build/Deploy System
ย 
MoT Athens meets Thessaloniki Software Testing & QA meetup
MoT Athens meets Thessaloniki Software Testing & QA meetupMoT Athens meets Thessaloniki Software Testing & QA meetup
MoT Athens meets Thessaloniki Software Testing & QA meetup
ย 
Glimpse of Loops Vs Set
Glimpse of Loops Vs SetGlimpse of Loops Vs Set
Glimpse of Loops Vs Set
ย 
Selenium Testing with TestingBot.com
Selenium Testing with TestingBot.comSelenium Testing with TestingBot.com
Selenium Testing with TestingBot.com
ย 
What's new in selenium 4
What's new in selenium 4What's new in selenium 4
What's new in selenium 4
ย 
Pyramid patterns
Pyramid patternsPyramid patterns
Pyramid patterns
ย 
Cypress Testing.pptx
Cypress Testing.pptxCypress Testing.pptx
Cypress Testing.pptx
ย 
Selenium Automation Testing Interview Questions And Answers
Selenium Automation Testing Interview Questions And AnswersSelenium Automation Testing Interview Questions And Answers
Selenium Automation Testing Interview Questions And Answers
ย 
Progressive Web App Testing With Cypress.io
Progressive Web App Testing With Cypress.ioProgressive Web App Testing With Cypress.io
Progressive Web App Testing With Cypress.io
ย 
Aegir Fresno Drupal User Group 1-21-10
Aegir Fresno Drupal User Group 1-21-10Aegir Fresno Drupal User Group 1-21-10
Aegir Fresno Drupal User Group 1-21-10
ย 
Setting Up a Cloud Server - Part 1 - Transcript.pdf
Setting Up a Cloud Server - Part 1 - Transcript.pdfSetting Up a Cloud Server - Part 1 - Transcript.pdf
Setting Up a Cloud Server - Part 1 - Transcript.pdf
ย 

Recently uploaded

CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female service
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female serviceCALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female service
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female service
anilsa9823
ย 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
ย 
CHEAP Call Girls in Pushp Vihar (-DELHI )๐Ÿ” 9953056974๐Ÿ”(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )๐Ÿ” 9953056974๐Ÿ”(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )๐Ÿ” 9953056974๐Ÿ”(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )๐Ÿ” 9953056974๐Ÿ”(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
ย 

Recently uploaded (20)

Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
ย 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlanโ€™s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlanโ€™s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlanโ€™s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlanโ€™s ...
ย 
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female service
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female serviceCALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female service
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female service
ย 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
ย 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
ย 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
ย 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
ย 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
ย 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
ย 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
ย 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
ย 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
ย 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
ย 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
ย 
CHEAP Call Girls in Pushp Vihar (-DELHI )๐Ÿ” 9953056974๐Ÿ”(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )๐Ÿ” 9953056974๐Ÿ”(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )๐Ÿ” 9953056974๐Ÿ”(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )๐Ÿ” 9953056974๐Ÿ”(=)/CALL GIRLS SERVICE
ย 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
ย 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
ย 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
ย 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
ย 
Shapes for Sharing between Graph Data Spacesย - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spacesย - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spacesย - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spacesย - and Epistemic Querying of RDF-...
ย 

Cypress.docx

  • 1. Om Q: Explain Cypress Architecture? Ans: Most testing tools (such as Selenium) work by operating outside of the browser and performing network commands. The Cypress engine, on the other hand, runs entirely within the browser. In other words, your test code is executed by the browser. It allows Cypress to listen in on browser activity and manipulate it in real time by manipulating the DOM and changing network requests and responses on the fly. In the case of Selenium, each browser has provided its own driver, which communicates with the browser instances to carry out the commands. On the contrary, in Cypress, all commands are executed within the browser. Canary, Chrome, Electron(Default), Chromium, Mozilla Firefox (beta support), and Microsoft Edge (Chromium-based) browsers are all supported by Cypress. Unit, functional, integration, and end-to-end testing are all possible with Cypress. It meets all of the requirements for a Test Pyramid. Q: What is Cy route? Ans: To manage the behaviour of network requests, use cy.route(). cy.server() and cy.route() have been deprecated in Cypress 6.0.0. Support for .server() and cy.route() will be moved to a plugin in a future release. What are the advantages of Cypress? ๏‚ท Cypress works with Single Page Applications and internal Ajax Calls. ๏‚ท Cypress can take snapshots of tests after executing each step.We don't need to have configuration with cypress.
  • 2. ๏‚ท Cypress can provide access to the developer tools so they can debug directly into the browser. ๏‚ท Cypress can run tests and also execute commands on the browser. ๏‚ท Cypress can execute commands easily and fast than Selenium based tools. What are the features of Cypress? ๏‚ท Time Travel - Cypress is used to take snapshots as our tests runs. ๏‚ท Debuggability - Cypress stops guessing why our tests are failing.It can debug tools such as Developer Tools. ๏‚ท Automatic Waiting - Cypress will add to our tests and wait for commands and assertions before moving on. ๏‚ท Screenshots and Videos - Cypress is used in viewing screenshots that are taken automatically on the failure of our entire test suite while running from CLI.
  • 3. Test Runner helps in testing in an interactive runner which helps by allowing us to see command and execute while viewing the application under the test. Test Status helps in showing us a summary of what tests Passed, Failed, or in Progress.
  • 4. URL Preview helps in showing us the URL of our test and also helps in tracking the URL Route. Viewport Sizing helps in setting our app viewport size for testing layouts. Command Log helps in showing us the command logs while executing the tests. App Preview helps in seeing the the tests while executing the commands. What is Cypress run? Cypress Run helps in executing our cypress tests in Headless Browsers. It helps in opening a New Browser Tab and in loading Cypress at the URL Cypress which was installed from it. Cypress helps in detecting cypress.json, it also runs cypress tests in the webpack monitor. How can we access shadow DOM in Cypress? Shadow DOM helps in allowing hidden DOM Trees which needs to be attached to the elements in the regular DOM Tree. Shadow DOM can be understood by the following command: cy.get('#locator').shadow().find('.nb-btn').click() How can we create custom commands in Cypress? We can create custom commands by using the following command: Cypress.Commands.add("login", (username, password) => { cy.get("#username").type(username); cy.get("#password").type(password); cy.get("#login").click(); }); How do we press keyboard keys in Cypress?
  • 5. We can press keyboard keys by using the following command: cy.get('#locator').type('{shift}{alt}')); How Cypress architecture is different from selenium? Selenium relies on WebDriver to execute the commands that means selenium executes remote command across the network. But in the cypress, it directly operates inside the browser. So the browser executes the commands which we run as script. Explanation: Real world scenario, Consider Selenium, If I have element.click() in my test script, Once I execute this script selenium sends this code to browser specific drivers like ChromeDriver, Ghecko Driver etc. The browser specific drivers then interact with specific browsers like Chrome, Firefox etc. and executes the click action. Consider Cypress, The same command element.click() Considering Cypress. Once you execute code in Cypress, The cypress directly sends the code to browser and click action gets executed. So with the above example we can understand that the middle layer that is webdriver which is present in the selenium but Cypress doesnโ€™t need any middle layer. Could you tell me about some differences between Cypress and Selenium?
  • 6. ๏‚ท Selenium supports all major languages like C#, Java, Python, JavaScript, Ruby etc. ๏‚ท Cypress Supports only JavaScript/Typescript languages ๏‚ท Selenium Commands are executed through web drivers ๏‚ท Cypress Commands Executed directly on the browser ๏‚ท Selenium Supports all major browsers chrome,Edge, Internet Explorer, Safari, Firefox ๏‚ท Cypress supports only Chrome, Edge and Firefox ๏‚ท With Selenium Configuration of drivers and language biding should be done by our own ๏‚ท With Cypress we get ready framework available we just need to install. ๏‚ท Selenium Appium can we used to test native mobile applications ๏‚ท Cypress doesnโ€™t support any native mobile application testing What is the disadvantage of using Cypress? ๏‚ท Cypress doesnโ€™t supports only Javascript/Typescript ๏‚ท Cypress doesnโ€™t supports all the browsers like Safari, Internet Explorer is not supported ๏‚ท Cypress doesnโ€™t support multiple tabs ๏‚ท We cannot run cypress tests on multiple browsers at the same time. ๏‚ท Cypress doesnโ€™t support Iframe Can I use Junit or TestNG in cypress? Or What is Testing Framework Cypress comes with? We cannot use the Junit or TestNG in Cypress, Cypress comes with Mocha and Chai assertion libraries. How can I install cypress? If you want to install cypress, we need to install Node first, once we install node we can install cypress with command npm install cypress
  • 7. Could you talk something about Cypress file and folder structures? ๏‚ท Cypress uses cypress.json file, if we want to specify any custom configuration which is located in the root of our project. ๏‚ท The folder named cypress is located in the project root folder which is main folder for cypress automation framework. ๏‚ท By default Cypress folder contains 4 subfolders namely fixtures, integration, plugins and support. ๏‚ท Fixtures folder can be used to store our external Json data files and we can use these files in our tests using the command cy.fixture(). ๏‚ท Integration folder mainly consists of our actual spec/test files ๏‚ท Plugins folder contains special files that executes in Node before project is loaded, before the browser launches, and during your test execution. This is very helpful when we want to have pre processers and post processors. Files in this folder can be executed after all the test execution is complete as well. 7. Example: Let us consider, If we want to generate HTML result after all the test is completed. The HTML report generation or collating those HTML reports can be done here in this file. 8. Support folder contains the special file index.js which will be run before each and every test. Support folder can also be used to create utility methods which will be helpful in through out our automation framework. This file is the perfect place to put all your reusable behavior such as Custom commands or global overrides that you want to be applied to all of your spec files. What is Cypress CLI? Cypress CLI is unique feature in cypress it provides ability to run our cypress tests in command line. This feature is helpful when we run our cypress tests in pipelines. It provides many options and flags control the cypress test behavior. Example: use npm cypress run to run your tests in command line.
  • 8. How can I run single specfile in command line? We can run single spec file in command line using - - spec option and specifying test name. Example: npm cypress run - - spec=โ€myspec.tsโ€ Tell me at least 5 Cypress commands? cy.visit(): cy.visit() is used to navigate to the specific website Ex: cy.visit(โ€˜http://www.google.comโ€™); cy.log(): cy.log is used for display cypress console logs during execution Ex: cy.log(โ€˜test 123โ€™); cy.get(): cy.get is used for getting dom element in cypress, once we get dom element we can perform action on that like click, type etc. Example: let myElement = cy.get(โ€˜#usernameโ€™) cy.url(): cy.url() is used to Get the current URL of the page that is currently active. Example: Consider you have navigate to https://google.com using cy.visit();, now you can use the cy.url() to get the url back. How can I create suites in cypress? We can create a describe() block the describe block acts as suite, inside that each test can be created as single it() block. Describe() is like a suite here. List out some commands which I can use to interact with DOM elements? .click() : is used to click on the element
  • 9. Example: cy.get('#search').click() .dblclick() : is used to double click on the element. Example: cy.get('input[name="btnK"]').dblclick(); .rightclick(): is used to right click on the element Example: cy.get('body').rightclick(); .type() : is used to type on element or text boxes Example: cy.get('input[name="texbox"]').type("This is to test"); .clear() : is used to clear the fields or text boxes. Example: cy.get('input[name="q"]').clear(); .check() : is used to Check checkbox(es) or radio(s). Example: cy.get('input[name="chkbox"]').check(); .uncheck() : is used to unCheck checkbox(es) or radio(s). Example:
  • 10. cy.get('input[name="chkbox"]').uncheck(); .select(): Select an <option> within a <select> Example: cy.get('select').select('user-1') Consider a scenario, I have link on webpage and clicking this link opens new window I need to verify some text in that window. How can I verify? Cypress by default doesnโ€™t support, working with new windows so we need to follow different approach here. Letโ€™s consider example: <a href="http://google.com" target="_blank"> Take me to Google </a> In the above code clicking on Take me to Google link opens the new window the reason is we have attribute target="_blank". So now if we remove attribute. target="_blank" then it will open in the same window. That can be performed by below code
  • 11. What are the selectors supported by Cypress? By Default cypress supports only CSS selectors, However we can use third party plugin to use Xpath selectors Can I use XPath in Cypress? Cypress doesnโ€™t support xpath by default, but if we install third party plugin like cypress-xpath we can use xpath in your script. Example: We need to install cypress-xpath in our project first using
  • 12. How can I read the value from Cypress Configuration file? We can read the cypress.config values from cypress using Cypress.config(); Example: If I have defined pageLoadTimeout in config file like blow. Below code is in cypress.json