SlideShare a Scribd company logo
Make the Protractor GREAT again!
Protractor: The Hacker Way
Duotify Inc.
CTO / Will 保哥
https://blog.miniasp.com
The definition of Hacker
2
A computer hacker is any skilled computer
expert that uses their technical knowledge
to overcome a problem.
“
”
Hacker - Wikipedia
Protractor: The problems
How we suffered by Protractor
Protractor: Getting started
• Install Angular CLI globally
- npm install -g @angular/cli
• Generate an Angular app
- ng new demo1 --routing --style css
- cd demo1
• Update WebDriver to match your browser version
- npx webdriver-manager update
• Run E2E scripts (Protractor) (DO NOT use ng e2e directly)
- npx protractor e2e/protractor.conf.js
4
A basic E2E test case
• DESCRIPTION
- Make sure Will Huang (保哥) are shown on the Speakers page
• STEPS
1. navigate to https://2019.ng-my.org/
2. click the SPEAKERS on the main menu
3. click the Will Huang (保哥) on the speakers list
4. validate the DOM contains Will Huang (保哥)
5
The code
6
Run the E2E scripts
7
npx protractor e2e/protractor.conf.js
Check for the stack trace
8
What's the problem?
• Error message
- Failed: No element found using locator: By(link text, Speakers)
• Line number of the error in the source code
- Find it on the stack trace. (debugging experience are so bad.)
• The problem should be this line
- element(by.linkText('Speakers'));
• Root cause
- by.linkText and some other Locator API are case-sensitive!
- It will find the element by what it rendered.
9
by.linkText is case-sensitive!
• Problem
- element(by.linkText('Speakers'));
• Solution
- element(by.linkText('SPEAKERS'));
• Is that make any sense?
- It looks buggy, but it doesn't. It because it's End-to-End testing!
- What you write is not what your expected!
10
Fix the first bug and run it again
• The error message becoming vague
• You can still get the line number in the stack trace.
11
What's the problem?
• Error message
- Expected '' to contain 'Will Huang (保哥)'.
• Line number of the error in the source code
- Find it on the stack trace
• The problem should be this line
- element(by.xpath('//main[@id="team"]/my-
modal/section/div/div/div/div/div'))
• Root cause
- The animation cause the Locator API unable to find DOM
at that moment! 12
Overcome animation issues
1. Wait for 2 seconds till animation stopped
await browser.sleep(2000); // Magic number
2. Use ExpectedConditions to wait for DOM show up
await browser.wait(
EC.textToBePresentInElement(elem4, text4),
5000);
13
Use browser.sleep
14
Use ExpectedConditions
15
Final result
16
Protractor Recorder
Write E2E scripts at rocket speeds
Protractor Recorder (Preview)
• Protractor Recorder is based on amazing Katalon Recorder
- It's free and open source.
• Features
- Tailored just for Protractor users
- Support TypeScript code generation
- Support async/await syntax ( SELENIUM_PROMISE_MANAGER: false )
- Support ExpectedConditions for better debugging experience
- Support non-Angular E2E testing
• Upstream PR is on the way
- Add protractor typescript template #23
Best practices
• by.linkText / by.buttonText are case-sensitive!
element(by.linkText('SPEAKERS')).click();
• Fixed window size for your E2E testing
browser.manage().window().setSize(1024, 768);
• DO NOT use ng e2e to run protractor in your daily job
ng e2e --dev-server-target= --webdriver-update=false
npx webdriver-manager update
npx protractor e2e/protractor.conf.js
19
Chrome Options
For your better E2E testing
protractor.conf.js
Useful chromeOptions
• Fixed window size
--start-maximized
--window-size=1024,768
• Leverage dual monitors
--window-position=2560,0
• Keep things dirty (when needed)
--user-data-dir=G:/Chrome
22
• Headless Chrome
--headless
• Miscellaneous
--proxy-server=localhost:8888
--ignore-certificate-errors
--disable-popup-blocking
--disable-gpu
--disable-infobars
Anti-robot detection
Hide the WebDriver footprints
Robot detection
24
How to hide the WebDriver footprints
• Fiddler: Customize Rule
static function OnBeforeResponse(oSession: Session) {
25
oSession.utilReplaceInResponse(
'<head>',
'<head>' +
' <script>' +
' const __base = navigator["__proto__"];' +
' delete __base.webdriver;' +
' navigator["__proto__"] = __base;' +
' Object.defineProperty(navigator, "languages", {' +
' get: function() { return ["en-US", "en"]; },' +
' });' +
' </script>')
Links
• Protractor Recorder
- https://github.com/doggy8088/protractor-recorder
• Katalon Recorder
- https://github.com/katalon-studio/katalon-recorder
• Protractor - end-to-end testing for Angular
- https://www.protractortest.org/
• Angular Taiwan
- https://angular.tw (Docs) | https://bit.ly/angulartw (Facebook)
26
The Will Will Web
網路世界的學習心得與技術分享
http://blog.miniasp.com/
Facebook
Will 保哥的技術交流中心
http://www.facebook.com/will.fans
Twitter
https://twitter.com/Will_Huang
Follow Me
THANK YOU!
2019
2019/11/2-3

More Related Content

PPTX
利用.NET Core 與 Azure Kubernetes Service (AKS) 建立高彈性 Microservices (Azure TechDay)
PDF
"Wix Serverless from inside", Mykola Borozdin
PDF
PDF
Kubernetes x PaaS – コンテナアプリケーションのNoOpsへの挑戦
PDF
Web Applications with Eclipse RT and Docker in the Cloud
PDF
CI/CD Using Ansible and Jenkins for Infrastructure
PPTX
.Net Core Fall update
PDF
利用.NET Core 與 Azure Kubernetes Service (AKS) 建立高彈性 Microservices (Azure TechDay)
"Wix Serverless from inside", Mykola Borozdin
Kubernetes x PaaS – コンテナアプリケーションのNoOpsへの挑戦
Web Applications with Eclipse RT and Docker in the Cloud
CI/CD Using Ansible and Jenkins for Infrastructure
.Net Core Fall update

What's hot (20)

PDF
Introduction to ansible
ODP
Jenkins 101: Continuos Integration with Jenkins
PPTX
Deploy Node.js application in Heroku using Eclipse
ODP
Nodejs Intro - Part2 Introduction to Web Applications
PPTX
Containerize development
PDF
Generating Visual Studio Code Extensions for Xtext DSLs
PDF
SUPER-scaling E-Commerce with Magento
PDF
Kubernetes上で動作する機械学習モジュールの配信&管理基盤Rekcurd について
PPTX
Docker &amp; azure
PDF
Sep Nasiri "Upwork PHP Architecture"
PPTX
WinOps 2017 - Docker on Windows, the Beginner's Guide
PDF
How to Use Mirroring and Caching to Optimize your Container Registry
PDF
Intro 2 docker
PDF
CodeIgniter For Project : Workshop 001 - Install Docker and CodeIgniter
PPT
Node.js Cloud deployment
PPTX
Docker on Windows - 101 to Production (half-day workshop)
PDF
twMVC#44 如何測試與保護你的 web application with playwright
PDF
Creating applications with Grails, Angular JS and Spring Security - G3 Summit...
PDF
Mastering Grails 3 Plugins - G3 Summit 2016
Introduction to ansible
Jenkins 101: Continuos Integration with Jenkins
Deploy Node.js application in Heroku using Eclipse
Nodejs Intro - Part2 Introduction to Web Applications
Containerize development
Generating Visual Studio Code Extensions for Xtext DSLs
SUPER-scaling E-Commerce with Magento
Kubernetes上で動作する機械学習モジュールの配信&管理基盤Rekcurd について
Docker &amp; azure
Sep Nasiri "Upwork PHP Architecture"
WinOps 2017 - Docker on Windows, the Beginner's Guide
How to Use Mirroring and Caching to Optimize your Container Registry
Intro 2 docker
CodeIgniter For Project : Workshop 001 - Install Docker and CodeIgniter
Node.js Cloud deployment
Docker on Windows - 101 to Production (half-day workshop)
twMVC#44 如何測試與保護你的 web application with playwright
Creating applications with Grails, Angular JS and Spring Security - G3 Summit...
Mastering Grails 3 Plugins - G3 Summit 2016

Similar to Protractor: The Hacker way (NG-MY 2019) (20)

PDF
Insights on Protractor testing
PPTX
An Introduction to AngularJS End to End Testing using Protractor
PDF
TestingAR XX - Protractor e2e Test Framework - Introduction what we have lear...
PDF
Carmen Popoviciu - Protractor styleguide | Codemotion Milan 2015
PPTX
Protractor training
PDF
Workshop - E2e tests with protractor
PDF
Protractor: Tips & Tricks
PPTX
Protractor Tutorial Quality in Agile 2015
PDF
Sharing (less) Pain of using Protractor & WebDriver
PDF
Sharing the pain using Protractor
PPTX
Better End-to-End Testing with Page Objects Model using Protractor
PPTX
Introduction to Protractor - Habilelabs
PPTX
Protractor framework architecture with example
PPTX
Protractor End To End Testing For AngularJS
PPTX
Angular UI Testing with Protractor
PPTX
Protractor overview
PDF
Сергей Больщиков "Protractor Tips & Tricks"
PPTX
QA Fes 2016. Александр Хотемской. Обзор ProtractorJS как фреймворка для брауз...
PPTX
ProtractorJS for automated testing of Angular 1.x/2.x applications
PPTX
Protractor
Insights on Protractor testing
An Introduction to AngularJS End to End Testing using Protractor
TestingAR XX - Protractor e2e Test Framework - Introduction what we have lear...
Carmen Popoviciu - Protractor styleguide | Codemotion Milan 2015
Protractor training
Workshop - E2e tests with protractor
Protractor: Tips & Tricks
Protractor Tutorial Quality in Agile 2015
Sharing (less) Pain of using Protractor & WebDriver
Sharing the pain using Protractor
Better End-to-End Testing with Page Objects Model using Protractor
Introduction to Protractor - Habilelabs
Protractor framework architecture with example
Protractor End To End Testing For AngularJS
Angular UI Testing with Protractor
Protractor overview
Сергей Больщиков "Protractor Tips & Tricks"
QA Fes 2016. Александр Хотемской. Обзор ProtractorJS как фреймворка для брауз...
ProtractorJS for automated testing of Angular 1.x/2.x applications
Protractor

More from Will Huang (20)

PPTX
深入理解 CVE-2022-24765 漏洞的攻擊與防護策略 (Git v2.35.2)
PPTX
從頭打造 C#、.NET 與 ASP.NET Core 開發環境
PPTX
ASP.NET Core 6.0 全新功能探索
PPTX
進擊的前端工程師:今天就用 JSON Server 自己打造 API 吧!
PPTX
你一定不能不知道的 Markdown 寫作技巧
PPTX
使用 .NET 5 實現美股期貨的量化交易策略 (.NET Conf 2020)
PPTX
實現 Angular, Docker 與 Kubernetes 持續部署 (NG+2020)
PPTX
Micro-frontends with Angular 10 (Modern Web 2020)
PPTX
從實戰經驗看到的 K8S 導入痛點
PPTX
RxJS 6 新手入門
PPTX
极速 Angular 开发:效能调校技巧 (ngChina 2019)
PPTX
你不可不知的 ASP.NET Core 3 全新功能探索 (.NET Conf 2019)
PPTX
邁向 Windows Server 應用程式現代化 (Windows Server Application Modernization)
PPTX
Angular 开发技巧 (2018 ngChina 开发者大会)
PPTX
Angular 7 全新功能探索 (Angular Taiwan 2018)
PPTX
AKS 與開發人員體驗 (Kubernetes 大講堂)
PPTX
使用 ASP.NET Blazor 開發 SPA 網頁應用程式 (.NET Conf 2018)
PPTX
全新 Windows Server 2019 容器技術 及邁向與 Kubernetes 整合之路 (Windows Server 高峰會)
PPTX
使用 C#/Razor 開發互動式 WebAssembly 網站 (Modern Web 2018)
PPTX
以敏捷架構打造美國軟體外包專案的經驗談
深入理解 CVE-2022-24765 漏洞的攻擊與防護策略 (Git v2.35.2)
從頭打造 C#、.NET 與 ASP.NET Core 開發環境
ASP.NET Core 6.0 全新功能探索
進擊的前端工程師:今天就用 JSON Server 自己打造 API 吧!
你一定不能不知道的 Markdown 寫作技巧
使用 .NET 5 實現美股期貨的量化交易策略 (.NET Conf 2020)
實現 Angular, Docker 與 Kubernetes 持續部署 (NG+2020)
Micro-frontends with Angular 10 (Modern Web 2020)
從實戰經驗看到的 K8S 導入痛點
RxJS 6 新手入門
极速 Angular 开发:效能调校技巧 (ngChina 2019)
你不可不知的 ASP.NET Core 3 全新功能探索 (.NET Conf 2019)
邁向 Windows Server 應用程式現代化 (Windows Server Application Modernization)
Angular 开发技巧 (2018 ngChina 开发者大会)
Angular 7 全新功能探索 (Angular Taiwan 2018)
AKS 與開發人員體驗 (Kubernetes 大講堂)
使用 ASP.NET Blazor 開發 SPA 網頁應用程式 (.NET Conf 2018)
全新 Windows Server 2019 容器技術 及邁向與 Kubernetes 整合之路 (Windows Server 高峰會)
使用 C#/Razor 開發互動式 WebAssembly 網站 (Modern Web 2018)
以敏捷架構打造美國軟體外包專案的經驗談

Recently uploaded (20)

PDF
Empathic Computing: Creating Shared Understanding
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Approach and Philosophy of On baking technology
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
Cloud computing and distributed systems.
PDF
cuic standard and advanced reporting.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Modernizing your data center with Dell and AMD
PDF
Machine learning based COVID-19 study performance prediction
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Unlocking AI with Model Context Protocol (MCP)
Empathic Computing: Creating Shared Understanding
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Reach Out and Touch Someone: Haptics and Empathic Computing
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Review of recent advances in non-invasive hemoglobin estimation
20250228 LYD VKU AI Blended-Learning.pptx
MYSQL Presentation for SQL database connectivity
Approach and Philosophy of On baking technology
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Cloud computing and distributed systems.
cuic standard and advanced reporting.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
The AUB Centre for AI in Media Proposal.docx
Network Security Unit 5.pdf for BCA BBA.
Chapter 3 Spatial Domain Image Processing.pdf
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Modernizing your data center with Dell and AMD
Machine learning based COVID-19 study performance prediction
NewMind AI Weekly Chronicles - August'25 Week I
Unlocking AI with Model Context Protocol (MCP)

Protractor: The Hacker way (NG-MY 2019)

  • 1. Make the Protractor GREAT again! Protractor: The Hacker Way Duotify Inc. CTO / Will 保哥 https://blog.miniasp.com
  • 2. The definition of Hacker 2 A computer hacker is any skilled computer expert that uses their technical knowledge to overcome a problem. “ ” Hacker - Wikipedia
  • 3. Protractor: The problems How we suffered by Protractor
  • 4. Protractor: Getting started • Install Angular CLI globally - npm install -g @angular/cli • Generate an Angular app - ng new demo1 --routing --style css - cd demo1 • Update WebDriver to match your browser version - npx webdriver-manager update • Run E2E scripts (Protractor) (DO NOT use ng e2e directly) - npx protractor e2e/protractor.conf.js 4
  • 5. A basic E2E test case • DESCRIPTION - Make sure Will Huang (保哥) are shown on the Speakers page • STEPS 1. navigate to https://2019.ng-my.org/ 2. click the SPEAKERS on the main menu 3. click the Will Huang (保哥) on the speakers list 4. validate the DOM contains Will Huang (保哥) 5
  • 7. Run the E2E scripts 7 npx protractor e2e/protractor.conf.js
  • 8. Check for the stack trace 8
  • 9. What's the problem? • Error message - Failed: No element found using locator: By(link text, Speakers) • Line number of the error in the source code - Find it on the stack trace. (debugging experience are so bad.) • The problem should be this line - element(by.linkText('Speakers')); • Root cause - by.linkText and some other Locator API are case-sensitive! - It will find the element by what it rendered. 9
  • 10. by.linkText is case-sensitive! • Problem - element(by.linkText('Speakers')); • Solution - element(by.linkText('SPEAKERS')); • Is that make any sense? - It looks buggy, but it doesn't. It because it's End-to-End testing! - What you write is not what your expected! 10
  • 11. Fix the first bug and run it again • The error message becoming vague • You can still get the line number in the stack trace. 11
  • 12. What's the problem? • Error message - Expected '' to contain 'Will Huang (保哥)'. • Line number of the error in the source code - Find it on the stack trace • The problem should be this line - element(by.xpath('//main[@id="team"]/my- modal/section/div/div/div/div/div')) • Root cause - The animation cause the Locator API unable to find DOM at that moment! 12
  • 13. Overcome animation issues 1. Wait for 2 seconds till animation stopped await browser.sleep(2000); // Magic number 2. Use ExpectedConditions to wait for DOM show up await browser.wait( EC.textToBePresentInElement(elem4, text4), 5000); 13
  • 17. Protractor Recorder Write E2E scripts at rocket speeds
  • 18. Protractor Recorder (Preview) • Protractor Recorder is based on amazing Katalon Recorder - It's free and open source. • Features - Tailored just for Protractor users - Support TypeScript code generation - Support async/await syntax ( SELENIUM_PROMISE_MANAGER: false ) - Support ExpectedConditions for better debugging experience - Support non-Angular E2E testing • Upstream PR is on the way - Add protractor typescript template #23
  • 19. Best practices • by.linkText / by.buttonText are case-sensitive! element(by.linkText('SPEAKERS')).click(); • Fixed window size for your E2E testing browser.manage().window().setSize(1024, 768); • DO NOT use ng e2e to run protractor in your daily job ng e2e --dev-server-target= --webdriver-update=false npx webdriver-manager update npx protractor e2e/protractor.conf.js 19
  • 20. Chrome Options For your better E2E testing
  • 22. Useful chromeOptions • Fixed window size --start-maximized --window-size=1024,768 • Leverage dual monitors --window-position=2560,0 • Keep things dirty (when needed) --user-data-dir=G:/Chrome 22 • Headless Chrome --headless • Miscellaneous --proxy-server=localhost:8888 --ignore-certificate-errors --disable-popup-blocking --disable-gpu --disable-infobars
  • 23. Anti-robot detection Hide the WebDriver footprints
  • 25. How to hide the WebDriver footprints • Fiddler: Customize Rule static function OnBeforeResponse(oSession: Session) { 25 oSession.utilReplaceInResponse( '<head>', '<head>' + ' <script>' + ' const __base = navigator["__proto__"];' + ' delete __base.webdriver;' + ' navigator["__proto__"] = __base;' + ' Object.defineProperty(navigator, "languages", {' + ' get: function() { return ["en-US", "en"]; },' + ' });' + ' </script>')
  • 26. Links • Protractor Recorder - https://github.com/doggy8088/protractor-recorder • Katalon Recorder - https://github.com/katalon-studio/katalon-recorder • Protractor - end-to-end testing for Angular - https://www.protractortest.org/ • Angular Taiwan - https://angular.tw (Docs) | https://bit.ly/angulartw (Facebook) 26
  • 27. The Will Will Web 網路世界的學習心得與技術分享 http://blog.miniasp.com/ Facebook Will 保哥的技術交流中心 http://www.facebook.com/will.fans Twitter https://twitter.com/Will_Huang Follow Me