SlideShare ist ein Scribd-Unternehmen logo
1 von 46
THE BATTLE OF CYPRESS & PROTRACTOR
AGENDA
Installation
Onboarding to the framework
Configuration
API differences:
● actions
● assertions
● waiton’s
Parallelization
Debugging
Testing types (api/unit/e2e)
Project size
Performance
Multi platform
Reporting
WHO ARE YOU?
● https://valor-software.com/ngx-bootstrap/#/
● https://github.com/ludmilanesvitiy
● https://www.linkedin.com/in/ludmila-nesvitiy-58094ab7/
● https://valor-software.com/persons/ludmila-nesvitiy
● https://twitter.com/LudmilaNes
3+YRS
AUTOMATED
TESTING
10+N
YEARS IN IT
CURRENT
PROJECT
OPEN
SOURCE
NGX-BOOTSTRAP
Native Angular widgets for Bootstrap 3 & 4.
~600,000 npm downloads per month
Designed documentation view
Created custom UI elements:
https://github.com/ludmilanesvitiy/RunIT-TestProject
INSTALLATION
Protractor Cypress
Recommend to install locally in project
npm install cypress --save-dev
./node_modules/.bin/cypress open
Recommend to install globally to your machine
npm install -g protractor
webdriver-manager update
INSTALLATION
ONBOARDING TO THE FRAMEWORK
Protractor Cypress
Main basic goal - easy testing any app
./node_modules/.bin/cypress open
Main basic goal - easy testing Angular apps
ng new YourProjectName
ONBOARDING
ONBOARDING TO THE PROTRACTOR
ng new YourProjectName
ONBOARDING
ONBOARDING TO THE CYPRESS
npm install cypress --save-dev
ONBOARDING
./node_modules/.bin/cypress open
CONFIGURATION
Protractor Cypress
tsconfig.json //TODOtsconfig.e2e.json
cypress.json //TODOprotractor.conf.js
CONFIGURATION
CONFIGURATION
protractor.conf.js
CONFIGURATION
CONFIGURATION
cypress.json
{}
CONFIGURATION
CONFIGURATION
cypress.json
CONFIGURATION
COMPARISON TABLE
API DIFFERENCES
Protractor Cypress
Global browser cy
Navigate the page get() visit()
Trigger click event click() click()
Type in input smth sendKeys() type()
Clear input clear() clear()
Mouse actions, events actions() trigger()
Keyboard event sendKeys(protractor.Key.ESCAPE) type('{esc}', { force: true })
Reload current page refresh() reload()
COMPARISON TABLE
API DIFFERENCES
Protractor Cypress
Find element element(by.css(‘’)) / $ get(‘’)
Find elements array element.all(by.css(‘’)) / $$ get(‘’)
Take N web-element from array first(), last(), get(N) first(), last(), eq(N)
Assign element to const / create alias const a = $(‘’); get(‘’).as(‘const_a’);
Find element with text element(by.cssContainingText(‘’)) get(‘’).contains();
Take each element from array each() each()
Wait for an arbitrary period sleep(N) wait(N)
Get current URL browser.getCurrentUrl() cy.hash()
ASSERTIONS COMPARISON
API DIFFERENCES
Protractor Cypress
Element shown on the page expect(e.isDisplayed()).toBe(true); e.should(‘be.visible’);
Element selected expect(isSelected()).toBe(true); e.should(‘be.selected’);
Element text appropriate expect(e.getText()).toEqual(‘’); e.invoke(‘text’).should(...)
Element attribute appropriate expect(e.getAttribute(‘a’)).toEqual(‘’); e.should(‘have.attr’, ‘value’)
Element css appropriate expect(e.getCssValue(‘’)).toEqual(‘’); e.should(‘have.css’, ‘value’)
Elements array length appropriate expect(array.count()).toEqual(N) e.should(‘to.have.length, N)
ASSERTIONS COMPARISON
API DIFFERENCES
$(`input`).then(input => {
expect(input.getAttribute('value')).toContain(expectedTxt);
});
vs
cy.get(`input`).then(input => {
expect(input.val()).to.contains(expectedTxt);
});
cy.get(`input`).should(`have.val`, expectedTxt);
TEST ARCHITECTURE
API DIFFERENCES
BaseComponent
DatePickerPO SortablePO ...
Test1 Test2 TestN...
FILE STRUCTURE
API DIFFERENCES
support
- base.component.ts
- datepicker.po.ts
- …
- sortable.po.ts
integration
- Test 1
- Test 2
- …
- Test N
TEST STRUCTURE
Protractor Cypress
import { DatepickerPo } from '../support/datepicker.po';
describe('Datepicker demo page test suite', () => {
const datepicker = new DatepickerPo();
const basic = datepicker.exampleDemosArr.basic;
beforeEach(async () => await datepicker.navigateTo());
it('when user clicks on "Datepicker" input, container with 2 arrows:
"‹", "›" opened, no one date selected', async () => {
await datepicker.clickOnDatepickerInput(basic);
await datepicker.isSelectedDateExist('datepicker', false);
await datepicker.isDatepickerNavigationFullyActiveAndCorrect('date');
});
});
import { DatepickerPo } from '../support/datepicker.po';
describe('Datepicker demo page test suite', () => {
const datepicker = new DatepickerPo();
const basic = datepicker.exampleDemosArr.basic;
beforeEach(() => datepicker.navigateTo());
it('when user clicks on "Datepicker" input, container with 2 arrows:
"‹", "›" opened, no one date selected', () => {
datepicker.clickOnDatepickerInput(basic);
datepicker.isSelectedDateExist('datepicker', false);
datepicker.isDatepickerNavigationFullyActiveAndCorrect('date');
});
});
API DIFFERENCES
BASE PAGE OBJECT
API DIFFERENCES
Protractor Cypress
export abstract class BaseComponent {
abstract pageUrl: string;
async navigateTo() {
await browser.get(`${ this.pageUrl }`);
}
}
export abstract class BaseComponent {
abstract pageUrl: string;
navigateTo() {
cy.visit(`${ this.pageUrl }`);
}
}
BASE PAGE OBJECT
API DIFFERENCES
Protractor Cypress
async clickOnDemoMenu(subMenu: string) {
await element(by.cssContainingText(
'add-nav a', subMenu))
.click();
}
clickOnDemoMenu(subMenu: string) {
cy.get('add-nav')
.contains('a', subMenu)
.click();
}
BASE PAGE OBJECT
API DIFFERENCES
Protractor Cypress
async clearInputAndSendKeys(
baseSelector: string,
dataToSend: string,
inputIndex = 0) {
const input = $$(`${baseSelector} input`)
.get(inputIndex);
await input.clear();
await input.sendKeys(dataToSend);
}
clearInputAndSendKeys(
baseSelector: string,
dataToSend: string,
inputIndex = 0) {
cy.get(`${baseSelector} input`)
.eq(inputIndex)
.clear()
.type(dataToSend);
}
BASE PAGE OBJECT
API DIFFERENCES
Protractor Cypress
async clickEnterOnInput(
baseSelector: string,
inputIndex = 0) {
await browser
.actions({bridge: true})
.sendKeys(protractor.Key.ENTER)
.perform();
}
clickEnterOnInput(
baseSelector: string,
inputIndex = 0) {
cy.get(`${baseSelector} input`)
.eq(inputIndex)
.type('{enter}');
}
WAIT-ON’S
API DIFFERENCES
Protractor Cypress
ExpectedConditions
● not
● and
● or
● alertIsPresent
● elementToBeClickable
● textToBePresentInElement
● textToBePresentInElementValue
● titleContains
● titleIs
● urlContains
● urlIs
● presenceOf
● stalenessOf
● visibilityOf
● invisibilityOf
● elementToBeSelected
It’s all retry-
ability
WAIT-ON’S
API DIFFERENCES
Protractor Cypress
ExpectedConditions
● not
● and
● or
● alertIsPresent
● elementToBeClickable
● textToBePresentInElement
● textToBePresentInElementValue
● titleContains
● titleIs
● urlContains
● urlIs
● presenceOf
● stalenessOf
● visibilityOf
● invisibilityOf
● elementToBeSelected
1. Retry all, except .click()
2. Retry up to 4 sec (defaultCommandTimeout)
3. Wait for route
cy.route('routeName/*').as('routeAlias');
cy.wait(['@routeAlias'], 10000);
PARALLELIZATION
Protractor Cypress
cypress run --record --key=NNN --parallel
shardTestFiles: true,
maxInstances: N
PARALLELIZATION
TESTING TYPES
Protractor Cypress
e2ee2e
API tests:
https://github.com/cypress-io/cypress-example-api-testing
https://docs.cypress.io/api/commands/request.html
API tests:
https://www.npmjs.com/package/request
unit:
https://github.com/bahmutov/cypress-angular-unit-test
TESTING TYPES
PROJECT SIZE
PROJECT SIZE
PERFORMANCE
58 tests, absolutely identical logic (depend on available API)
Protractor, Chrome visible Cypress open
~~2 m 45 sec~~ 52 sec
Protractor, Chrome headless Cypress run
~~1 m 8 sec~~ 43 sec
PERFORMANCE
CPU LOADING - PROTRACTOR, CHROME
PERFORMANCE
CPU LOADING - CYPRESS OPEN
PERFORMANCE
MULTI PLATFORM
Protractor Cypress
Canary, Chrome, Chromium, ElectronChrome, Firefox, Safari, and IE
Full info:
https://docs.cypress.io/guides/core-concepts/launching-
browsers.html#
Full list:
http://www.protractortest.org/#/browser-support
MULTI PLATFORM
REPORTING
Protractor Cypress
mocha reporters: https://mochajs.org/#reporters
teamcity
junit
{
"reporter": "junit",
"reporterOptions": {
}
}
jasmine-spec-reporter
protractor-jasmine2-screenshot-reporter
protractor-html-reporter-2
protractor-beautiful-reporter
protractor-zephyr-reporter
jasmine-protractor-reporter
protractor-jasmine2-html-reporter
onPrepare: function () {
jasmine.getEnv().addReporter(...)
}
REPORTING
Dashboard
REPORTING - Protractor
REPORTING
REPORTING - Cypress
REPORTING
REPORTING - Cypress
REPORTING
DEBUGGING
Protractor Cypress
cypress open
.debug()
cy.pause()
https://docs.cypress.io/guides/guides/debugging.html
add to appropriate place:
debugger;
add appropriate breakpoints
node --inspect-brk ./node_modules/.bin/protractor
protractor/protractor.conf.js
go to browser and enter:
chrome://inspect/#devices
click on Open dedicated DevTools for Node
click on “Play” and investigate results
https://www.protractortest.org/#/debugging
DEBUGGING
DEBUGGING
STATISTICS
SUMMARY
Installation
Onboarding to the framework
Configuration
API differences
Parallelization
Debugging
Testing types (api/unit/e2e)
Project size
Performance
Multi platform
Reporting
USEFUL LINKS
● https://github.com/ludmilanesvitiy/RunIT-TestProject
● https://github.com/cypress-io/cypress-example-api-testing
● https://docs.cypress.io/api/commands/request.html
● https://github.com/bahmutov/cypress-angular-unit-test
● https://mochajs.org/#reporters
● https://docs.cypress.io/guides/guides/debugging.html
● https://docs.cypress.io/guides/core-concepts/launching-browsers.html#
● https://www.npmjs.com/package/request
● http://www.protractortest.org/#/browser-support
● https://www.protractortest.org/#/debugging
● https://valor-software.com/persons/ludmila-nesvitiy

Weitere ähnliche Inhalte

Was ist angesagt?

Developing A Real World Logistic Application With Oracle Application - UKOUG ...
Developing A Real World Logistic Application With Oracle Application - UKOUG ...Developing A Real World Logistic Application With Oracle Application - UKOUG ...
Developing A Real World Logistic Application With Oracle Application - UKOUG ...
Roel Hartman
 
Testing your javascript code with jasmine
Testing your javascript code with jasmineTesting your javascript code with jasmine
Testing your javascript code with jasmine
Rubyc Slides
 

Was ist angesagt? (20)

Angular.js Primer in Aalto University
Angular.js Primer in Aalto UniversityAngular.js Primer in Aalto University
Angular.js Primer in Aalto University
 
AngularJs Crash Course
AngularJs Crash CourseAngularJs Crash Course
AngularJs Crash Course
 
AngularJS Basics with Example
AngularJS Basics with ExampleAngularJS Basics with Example
AngularJS Basics with Example
 
Crossing platforms with JavaScript & React
Crossing platforms with JavaScript & React Crossing platforms with JavaScript & React
Crossing platforms with JavaScript & React
 
JavaScript Unit Testing with Jasmine
JavaScript Unit Testing with JasmineJavaScript Unit Testing with Jasmine
JavaScript Unit Testing with Jasmine
 
Angular - injection tokens & Custom libraries
Angular - injection tokens & Custom librariesAngular - injection tokens & Custom libraries
Angular - injection tokens & Custom libraries
 
Upgrading from Angular 1.x to Angular 2.x
Upgrading from Angular 1.x to Angular 2.xUpgrading from Angular 1.x to Angular 2.x
Upgrading from Angular 1.x to Angular 2.x
 
Developing A Real World Logistic Application With Oracle Application - UKOUG ...
Developing A Real World Logistic Application With Oracle Application - UKOUG ...Developing A Real World Logistic Application With Oracle Application - UKOUG ...
Developing A Real World Logistic Application With Oracle Application - UKOUG ...
 
Method and decorator
Method and decoratorMethod and decorator
Method and decorator
 
Angular js 2.0, ng poznań 20.11
Angular js 2.0, ng poznań 20.11Angular js 2.0, ng poznań 20.11
Angular js 2.0, ng poznań 20.11
 
Testing your javascript code with jasmine
Testing your javascript code with jasmineTesting your javascript code with jasmine
Testing your javascript code with jasmine
 
AngularJS Framework
AngularJS FrameworkAngularJS Framework
AngularJS Framework
 
Angular 2.0 - What to expect
Angular 2.0 - What to expectAngular 2.0 - What to expect
Angular 2.0 - What to expect
 
Solid angular
Solid angularSolid angular
Solid angular
 
Exploring Angular 2 - Episode 2
Exploring Angular 2 - Episode 2Exploring Angular 2 - Episode 2
Exploring Angular 2 - Episode 2
 
How Angular2 Can Improve Your AngularJS Apps Today!
How Angular2 Can Improve Your AngularJS Apps Today!How Angular2 Can Improve Your AngularJS Apps Today!
How Angular2 Can Improve Your AngularJS Apps Today!
 
Angularjs Basics
Angularjs BasicsAngularjs Basics
Angularjs Basics
 
08 Queries
08 Queries08 Queries
08 Queries
 
An introduction to Angular2
An introduction to Angular2 An introduction to Angular2
An introduction to Angular2
 
ngMess: AngularJS Dependency Injection
ngMess: AngularJS Dependency InjectionngMess: AngularJS Dependency Injection
ngMess: AngularJS Dependency Injection
 

Ähnlich wie The battle of Protractor and Cypress - RunIT Conference 2019

Practical AngularJS
Practical AngularJSPractical AngularJS
Practical AngularJS
Wei Ru
 
前端MVC 豆瓣说
前端MVC 豆瓣说前端MVC 豆瓣说
前端MVC 豆瓣说
Ting Lv
 

Ähnlich wie The battle of Protractor and Cypress - RunIT Conference 2019 (20)

Tamir Dresher - What’s new in ASP.NET Core 6
Tamir Dresher - What’s new in ASP.NET Core 6Tamir Dresher - What’s new in ASP.NET Core 6
Tamir Dresher - What’s new in ASP.NET Core 6
 
Reduxing like a pro
Reduxing like a proReduxing like a pro
Reduxing like a pro
 
Serverless Angular, Material, Firebase and Google Cloud applications
Serverless Angular, Material, Firebase and Google Cloud applicationsServerless Angular, Material, Firebase and Google Cloud applications
Serverless Angular, Material, Firebase and Google Cloud applications
 
Automation in angular js
Automation in angular jsAutomation in angular js
Automation in angular js
 
Angular server side rendering - Strategies & Technics
Angular server side rendering - Strategies & Technics Angular server side rendering - Strategies & Technics
Angular server side rendering - Strategies & Technics
 
Maciej Treder "Server-side rendering with Angular—be faster and more SEO, CDN...
Maciej Treder "Server-side rendering with Angular—be faster and more SEO, CDN...Maciej Treder "Server-side rendering with Angular—be faster and more SEO, CDN...
Maciej Treder "Server-side rendering with Angular—be faster and more SEO, CDN...
 
Protractor framework – how to make stable e2e tests for Angular applications
Protractor framework – how to make stable e2e tests for Angular applicationsProtractor framework – how to make stable e2e tests for Angular applications
Protractor framework – how to make stable e2e tests for Angular applications
 
The use case of a scalable architecture
The use case of a scalable architectureThe use case of a scalable architecture
The use case of a scalable architecture
 
Angular 4 for Java Developers
Angular 4 for Java DevelopersAngular 4 for Java Developers
Angular 4 for Java Developers
 
Node.js: scalability tips - Azure Dev Community Vijayawada
Node.js: scalability tips - Azure Dev Community VijayawadaNode.js: scalability tips - Azure Dev Community Vijayawada
Node.js: scalability tips - Azure Dev Community Vijayawada
 
Wcf data services
Wcf data servicesWcf data services
Wcf data services
 
mobl
moblmobl
mobl
 
React native app with type script tutorial
React native app with type script tutorialReact native app with type script tutorial
React native app with type script tutorial
 
Restful Web Service
Restful Web ServiceRestful Web Service
Restful Web Service
 
Practical AngularJS
Practical AngularJSPractical AngularJS
Practical AngularJS
 
WordPress Realtime - WordCamp São Paulo 2015
WordPress Realtime - WordCamp São Paulo 2015WordPress Realtime - WordCamp São Paulo 2015
WordPress Realtime - WordCamp São Paulo 2015
 
Durable functions 2.0 (2019-10-10)
Durable functions 2.0 (2019-10-10)Durable functions 2.0 (2019-10-10)
Durable functions 2.0 (2019-10-10)
 
前端MVC 豆瓣说
前端MVC 豆瓣说前端MVC 豆瓣说
前端MVC 豆瓣说
 
Academy PRO: React native - building first scenes
Academy PRO: React native - building first scenesAcademy PRO: React native - building first scenes
Academy PRO: React native - building first scenes
 
Coding Ajax
Coding AjaxCoding Ajax
Coding Ajax
 

Kürzlich hochgeladen

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Kürzlich hochgeladen (20)

Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 

The battle of Protractor and Cypress - RunIT Conference 2019

  • 1. THE BATTLE OF CYPRESS & PROTRACTOR
  • 2. AGENDA Installation Onboarding to the framework Configuration API differences: ● actions ● assertions ● waiton’s Parallelization Debugging Testing types (api/unit/e2e) Project size Performance Multi platform Reporting
  • 3. WHO ARE YOU? ● https://valor-software.com/ngx-bootstrap/#/ ● https://github.com/ludmilanesvitiy ● https://www.linkedin.com/in/ludmila-nesvitiy-58094ab7/ ● https://valor-software.com/persons/ludmila-nesvitiy ● https://twitter.com/LudmilaNes 3+YRS AUTOMATED TESTING 10+N YEARS IN IT CURRENT PROJECT OPEN SOURCE
  • 4. NGX-BOOTSTRAP Native Angular widgets for Bootstrap 3 & 4. ~600,000 npm downloads per month Designed documentation view Created custom UI elements: https://github.com/ludmilanesvitiy/RunIT-TestProject
  • 5. INSTALLATION Protractor Cypress Recommend to install locally in project npm install cypress --save-dev ./node_modules/.bin/cypress open Recommend to install globally to your machine npm install -g protractor webdriver-manager update INSTALLATION
  • 6. ONBOARDING TO THE FRAMEWORK Protractor Cypress Main basic goal - easy testing any app ./node_modules/.bin/cypress open Main basic goal - easy testing Angular apps ng new YourProjectName ONBOARDING
  • 7. ONBOARDING TO THE PROTRACTOR ng new YourProjectName ONBOARDING
  • 8.
  • 9. ONBOARDING TO THE CYPRESS npm install cypress --save-dev ONBOARDING
  • 11.
  • 12.
  • 17. COMPARISON TABLE API DIFFERENCES Protractor Cypress Global browser cy Navigate the page get() visit() Trigger click event click() click() Type in input smth sendKeys() type() Clear input clear() clear() Mouse actions, events actions() trigger() Keyboard event sendKeys(protractor.Key.ESCAPE) type('{esc}', { force: true }) Reload current page refresh() reload()
  • 18. COMPARISON TABLE API DIFFERENCES Protractor Cypress Find element element(by.css(‘’)) / $ get(‘’) Find elements array element.all(by.css(‘’)) / $$ get(‘’) Take N web-element from array first(), last(), get(N) first(), last(), eq(N) Assign element to const / create alias const a = $(‘’); get(‘’).as(‘const_a’); Find element with text element(by.cssContainingText(‘’)) get(‘’).contains(); Take each element from array each() each() Wait for an arbitrary period sleep(N) wait(N) Get current URL browser.getCurrentUrl() cy.hash()
  • 19. ASSERTIONS COMPARISON API DIFFERENCES Protractor Cypress Element shown on the page expect(e.isDisplayed()).toBe(true); e.should(‘be.visible’); Element selected expect(isSelected()).toBe(true); e.should(‘be.selected’); Element text appropriate expect(e.getText()).toEqual(‘’); e.invoke(‘text’).should(...) Element attribute appropriate expect(e.getAttribute(‘a’)).toEqual(‘’); e.should(‘have.attr’, ‘value’) Element css appropriate expect(e.getCssValue(‘’)).toEqual(‘’); e.should(‘have.css’, ‘value’) Elements array length appropriate expect(array.count()).toEqual(N) e.should(‘to.have.length, N)
  • 20. ASSERTIONS COMPARISON API DIFFERENCES $(`input`).then(input => { expect(input.getAttribute('value')).toContain(expectedTxt); }); vs cy.get(`input`).then(input => { expect(input.val()).to.contains(expectedTxt); }); cy.get(`input`).should(`have.val`, expectedTxt);
  • 22. FILE STRUCTURE API DIFFERENCES support - base.component.ts - datepicker.po.ts - … - sortable.po.ts integration - Test 1 - Test 2 - … - Test N
  • 23. TEST STRUCTURE Protractor Cypress import { DatepickerPo } from '../support/datepicker.po'; describe('Datepicker demo page test suite', () => { const datepicker = new DatepickerPo(); const basic = datepicker.exampleDemosArr.basic; beforeEach(async () => await datepicker.navigateTo()); it('when user clicks on "Datepicker" input, container with 2 arrows: "‹", "›" opened, no one date selected', async () => { await datepicker.clickOnDatepickerInput(basic); await datepicker.isSelectedDateExist('datepicker', false); await datepicker.isDatepickerNavigationFullyActiveAndCorrect('date'); }); }); import { DatepickerPo } from '../support/datepicker.po'; describe('Datepicker demo page test suite', () => { const datepicker = new DatepickerPo(); const basic = datepicker.exampleDemosArr.basic; beforeEach(() => datepicker.navigateTo()); it('when user clicks on "Datepicker" input, container with 2 arrows: "‹", "›" opened, no one date selected', () => { datepicker.clickOnDatepickerInput(basic); datepicker.isSelectedDateExist('datepicker', false); datepicker.isDatepickerNavigationFullyActiveAndCorrect('date'); }); }); API DIFFERENCES
  • 24. BASE PAGE OBJECT API DIFFERENCES Protractor Cypress export abstract class BaseComponent { abstract pageUrl: string; async navigateTo() { await browser.get(`${ this.pageUrl }`); } } export abstract class BaseComponent { abstract pageUrl: string; navigateTo() { cy.visit(`${ this.pageUrl }`); } }
  • 25. BASE PAGE OBJECT API DIFFERENCES Protractor Cypress async clickOnDemoMenu(subMenu: string) { await element(by.cssContainingText( 'add-nav a', subMenu)) .click(); } clickOnDemoMenu(subMenu: string) { cy.get('add-nav') .contains('a', subMenu) .click(); }
  • 26. BASE PAGE OBJECT API DIFFERENCES Protractor Cypress async clearInputAndSendKeys( baseSelector: string, dataToSend: string, inputIndex = 0) { const input = $$(`${baseSelector} input`) .get(inputIndex); await input.clear(); await input.sendKeys(dataToSend); } clearInputAndSendKeys( baseSelector: string, dataToSend: string, inputIndex = 0) { cy.get(`${baseSelector} input`) .eq(inputIndex) .clear() .type(dataToSend); }
  • 27. BASE PAGE OBJECT API DIFFERENCES Protractor Cypress async clickEnterOnInput( baseSelector: string, inputIndex = 0) { await browser .actions({bridge: true}) .sendKeys(protractor.Key.ENTER) .perform(); } clickEnterOnInput( baseSelector: string, inputIndex = 0) { cy.get(`${baseSelector} input`) .eq(inputIndex) .type('{enter}'); }
  • 28. WAIT-ON’S API DIFFERENCES Protractor Cypress ExpectedConditions ● not ● and ● or ● alertIsPresent ● elementToBeClickable ● textToBePresentInElement ● textToBePresentInElementValue ● titleContains ● titleIs ● urlContains ● urlIs ● presenceOf ● stalenessOf ● visibilityOf ● invisibilityOf ● elementToBeSelected It’s all retry- ability
  • 29. WAIT-ON’S API DIFFERENCES Protractor Cypress ExpectedConditions ● not ● and ● or ● alertIsPresent ● elementToBeClickable ● textToBePresentInElement ● textToBePresentInElementValue ● titleContains ● titleIs ● urlContains ● urlIs ● presenceOf ● stalenessOf ● visibilityOf ● invisibilityOf ● elementToBeSelected 1. Retry all, except .click() 2. Retry up to 4 sec (defaultCommandTimeout) 3. Wait for route cy.route('routeName/*').as('routeAlias'); cy.wait(['@routeAlias'], 10000);
  • 30. PARALLELIZATION Protractor Cypress cypress run --record --key=NNN --parallel shardTestFiles: true, maxInstances: N PARALLELIZATION
  • 31. TESTING TYPES Protractor Cypress e2ee2e API tests: https://github.com/cypress-io/cypress-example-api-testing https://docs.cypress.io/api/commands/request.html API tests: https://www.npmjs.com/package/request unit: https://github.com/bahmutov/cypress-angular-unit-test TESTING TYPES
  • 33. PERFORMANCE 58 tests, absolutely identical logic (depend on available API) Protractor, Chrome visible Cypress open ~~2 m 45 sec~~ 52 sec Protractor, Chrome headless Cypress run ~~1 m 8 sec~~ 43 sec PERFORMANCE
  • 34. CPU LOADING - PROTRACTOR, CHROME PERFORMANCE
  • 35. CPU LOADING - CYPRESS OPEN PERFORMANCE
  • 36. MULTI PLATFORM Protractor Cypress Canary, Chrome, Chromium, ElectronChrome, Firefox, Safari, and IE Full info: https://docs.cypress.io/guides/core-concepts/launching- browsers.html# Full list: http://www.protractortest.org/#/browser-support MULTI PLATFORM
  • 37. REPORTING Protractor Cypress mocha reporters: https://mochajs.org/#reporters teamcity junit { "reporter": "junit", "reporterOptions": { } } jasmine-spec-reporter protractor-jasmine2-screenshot-reporter protractor-html-reporter-2 protractor-beautiful-reporter protractor-zephyr-reporter jasmine-protractor-reporter protractor-jasmine2-html-reporter onPrepare: function () { jasmine.getEnv().addReporter(...) } REPORTING Dashboard
  • 41. DEBUGGING Protractor Cypress cypress open .debug() cy.pause() https://docs.cypress.io/guides/guides/debugging.html add to appropriate place: debugger; add appropriate breakpoints node --inspect-brk ./node_modules/.bin/protractor protractor/protractor.conf.js go to browser and enter: chrome://inspect/#devices click on Open dedicated DevTools for Node click on “Play” and investigate results https://www.protractortest.org/#/debugging DEBUGGING
  • 42.
  • 45. SUMMARY Installation Onboarding to the framework Configuration API differences Parallelization Debugging Testing types (api/unit/e2e) Project size Performance Multi platform Reporting
  • 46. USEFUL LINKS ● https://github.com/ludmilanesvitiy/RunIT-TestProject ● https://github.com/cypress-io/cypress-example-api-testing ● https://docs.cypress.io/api/commands/request.html ● https://github.com/bahmutov/cypress-angular-unit-test ● https://mochajs.org/#reporters ● https://docs.cypress.io/guides/guides/debugging.html ● https://docs.cypress.io/guides/core-concepts/launching-browsers.html# ● https://www.npmjs.com/package/request ● http://www.protractortest.org/#/browser-support ● https://www.protractortest.org/#/debugging ● https://valor-software.com/persons/ludmila-nesvitiy