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