At ThinkCru building stable applications that are well tested is our #1 priority. At first pass, we do Quality Assurance (QA) testing manually to ensure we are initially meeting our client's requirements. However, at some point, as the application grows in complexity, manual testing is no longer sustainable. In order to scale up testing as new features are added we deploy automated end-to-end (e2e) testing for using both Selenium and Cypress frameworks.
The purpose of this post is to explore some of the key differences between the Selenium and Cypress frameworks. Bellow is just a brief comparison
|Supported Languages||Java, C#, Java Script, Python, Ruby, Onjective-C||Java Script|
|Browsers Supported||Chrome, IE, Safari Edge, Firefox, Opera||Chrome, Edge, Firefox Electron|
|Issues in GitHub||Open - 287, Closed - 6513||Open - 1295, Closed - 5196|
Selenium is driven by a variety of languages (Java, C#, Java Script, Python, Ruby, Objective-C) using an API that communicates with the
To work with browser you should get an array of your tabs and select one:
WebDriver driver = new ChromeDriver(); ArrayList<String> tabs = new ArrayList<String> (driver.getWindowHandles()); driver.switchTo().window(tabs.get(1));
Selenium purpose 3 methods to enter into iFrame:
driver.switchTo().frame(0); driver.switchTo().frame("frameName"); driver.switchTo().frame(webElement);
Now you are able to work with html elements into selected iFrame. Also you can enter into new iFrame if it's located into entered iFrame.
But there is only one way to get out from iFrame:
Cypress developers created a new architecture from the ground up. Whereas Selenium executes remote commands through the network, Cypress runs in the same run-loop as your application. Behind Cypress is a Node.js server process. Cypress and the Node.js process constantly communicate, synchronize, and perform tasks on behalf of each other. Having access to both parts (front and back) gives us the ability to respond to your application's events in real time, while at the same time work outside of the browser for tasks that require a higher privilege.
git clone email@example.com:thinkcru/selenium-test-project.git
4. By default
pom.xml file doesn't contain any dependencies. For our example we will need some dependencies (Selenium, WebDriverManager, TestNG). See more maven dependencies on https://mvnrepository.com/
5. Create a package and java class
6. For now you need to initialize WebDriver. There are two ways to do it: manually download WebDriver for a browser or use WebDriverManager (https://github.com/bonigarcia/webdrivermanager). To use WebDriverManager you need to add a dependency to pom.xml file.
7. The following code example is how to implement the
chromeDriver() to send an input with the amount of
100 into the text field. The driver will then
click() on the button associated with form submission. An assertion
assertTrue() will wait for the text to resolve the amount to
git clone firstname.lastname@example.org:thinkcru/cypress-io-test-project.git
package.json file to open Cypress. Now we can open Cypress by clicking
cypress:open to open Cypress. After the first launch test examples will be generated
7. Create a folder in
8. Create the example code and is quick and easy to implement the tests much like how a Unit Test is written. In about 4 lines of code we can use the
cy library to add the amount and invoke an expectation from what is returned in the browser.
Cypress and Selenium serve a similar purpose that is achieved in two different ways. A key difference is that Cypress ideal for introducing developers to test automation rather than just a replacement for Selenium. This is why Cypress is among the fastest-growing automation tools in the world. On the other hand, Selenium is a more general-purpose tool targeted at a broader audience.