SlideShare une entreprise Scribd logo
1  sur  28
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

Contenu connexe

Tendances

Tendances (20)

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

Similaire à Protractor: The Hacker way (NG-MY 2019)

Srikanth_PILLI_CV_latest
Srikanth_PILLI_CV_latestSrikanth_PILLI_CV_latest
Srikanth_PILLI_CV_latest
Srikanth Pilli
 
Flash security past_present_future_final_en
Flash security past_present_future_final_enFlash security past_present_future_final_en
Flash security past_present_future_final_en
Sunghun Kim
 

Similaire à Protractor: The Hacker way (NG-MY 2019) (20)

AV Evasion with the Veil Framework
AV Evasion with the Veil FrameworkAV Evasion with the Veil Framework
AV Evasion with the Veil Framework
 
C# Production Debugging Made Easy
 C# Production Debugging Made Easy C# Production Debugging Made Easy
C# Production Debugging Made Easy
 
tut0000021-hevery
tut0000021-heverytut0000021-hevery
tut0000021-hevery
 
tut0000021-hevery
tut0000021-heverytut0000021-hevery
tut0000021-hevery
 
The Hacking Games - A Road to Post Exploitation Meetup - 20240222.pptx
The Hacking Games - A Road to Post Exploitation Meetup - 20240222.pptxThe Hacking Games - A Road to Post Exploitation Meetup - 20240222.pptx
The Hacking Games - A Road to Post Exploitation Meetup - 20240222.pptx
 
Common Pitfalls of Functional Programming and How to Avoid Them: A Mobile Gam...
Common Pitfalls of Functional Programming and How to Avoid Them: A Mobile Gam...Common Pitfalls of Functional Programming and How to Avoid Them: A Mobile Gam...
Common Pitfalls of Functional Programming and How to Avoid Them: A Mobile Gam...
 
.Net Debugging Techniques
.Net Debugging Techniques.Net Debugging Techniques
.Net Debugging Techniques
 
.NET Debugging Tips and Techniques
.NET Debugging Tips and Techniques.NET Debugging Tips and Techniques
.NET Debugging Tips and Techniques
 
It's Time to Debloat the Cloud with Unikraft
It's Time to Debloat the Cloud with UnikraftIt's Time to Debloat the Cloud with Unikraft
It's Time to Debloat the Cloud with Unikraft
 
HKG15-407: EME implementation in Chromium: Linaro Clear Key
HKG15-407: EME implementation in Chromium: Linaro Clear Key HKG15-407: EME implementation in Chromium: Linaro Clear Key
HKG15-407: EME implementation in Chromium: Linaro Clear Key
 
Srikanth_PILLI_CV_latest
Srikanth_PILLI_CV_latestSrikanth_PILLI_CV_latest
Srikanth_PILLI_CV_latest
 
Captain Hook: Pirating AVs to Bypass Exploit Mitigations
Captain Hook: Pirating AVs to Bypass Exploit MitigationsCaptain Hook: Pirating AVs to Bypass Exploit Mitigations
Captain Hook: Pirating AVs to Bypass Exploit Mitigations
 
Piratng Avs to bypass exploit mitigation
Piratng Avs to bypass exploit mitigationPiratng Avs to bypass exploit mitigation
Piratng Avs to bypass exploit mitigation
 
Devoxx France: Développement JAVA avec un IDE dans le Cloud: Yes we can !
Devoxx France: Développement JAVA avec un IDE dans le Cloud: Yes we can !Devoxx France: Développement JAVA avec un IDE dans le Cloud: Yes we can !
Devoxx France: Développement JAVA avec un IDE dans le Cloud: Yes we can !
 
introduction-infra-as-a-code using terraform
introduction-infra-as-a-code using terraformintroduction-infra-as-a-code using terraform
introduction-infra-as-a-code using terraform
 
A complete guide to Node.js
A complete guide to Node.jsA complete guide to Node.js
A complete guide to Node.js
 
The Modern Developer Toolbox
The Modern Developer ToolboxThe Modern Developer Toolbox
The Modern Developer Toolbox
 
Flash security past_present_future_final_en
Flash security past_present_future_final_enFlash security past_present_future_final_en
Flash security past_present_future_final_en
 
Typhoon Managed Execution Toolkit
Typhoon Managed Execution ToolkitTyphoon Managed Execution Toolkit
Typhoon Managed Execution Toolkit
 
Real-World Docker: 10 Things We've Learned
Real-World Docker: 10 Things We've Learned  Real-World Docker: 10 Things We've Learned
Real-World Docker: 10 Things We've Learned
 

Plus de Will Huang

Plus de Will Huang (20)

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

Dernier

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Dernier (20)

Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
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, ...
 
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
 
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...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
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
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
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
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 

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