https://mvc.tw 歡迎參加我們的每週四固定聚會 1 如何測試與保護你的 Web Application with Playwright 阿砮 Cheng-Ju Wu
https://mvc.tw 2 End-to-End Test ? 開始前…如果我是測試工程師
https://mvc.tw 3 End-to-End Test
https://mvc.tw End-to-End Test 4 脆弱性 Timeout 工人智慧 重複工作 Trace Log 環境問題 耗時 成本
https://mvc.tw End-to-End Test 5 ▪ 繁瑣又缺乏創造力 ▪ 時間成本 ▪ 開發維護成本 ▪ 執行慢 ▪ 測試覆蓋率低 ▪ 可靠性 如何改善 提升效率
https://mvc.tw 6 切入主題
https://mvc.tw Agenda ▪ What is Playwright ▪ Why choose Playwright ▪ How to use Playwright ▪ Use cases 7
https://mvc.tw 8 What is Playwright
https://mvc.tw What is Playwright 9 github.com/microsoft/playwright Playwright Playwright Test
https://mvc.tw Playwright is ▪ Bowser Automation Framework ▪ Node.js Library ▪ Open Source ▪ Puppeteer ▪ By Microsoft 10 github.com/microsoft/playwright
https://mvc.tw Playwright is ▪ Cross-platform ( Windows, Linux, macOS ) ▪ Cross-browser testing with single API ▪ Supports 3 browser engines ▪ Chromium:Google Chrome / Microsoft Edge / Opera ▪ Firefox ▪ WebKit:Apple Safari 11 playwright.dev github.com/microsoft/playwright
https://mvc.tw Playwright can't ▪ 與實際落差 ▪ 無法操作手機,只能開啟手機瀏覽器模擬模式 ▪ WebKit 與 Safari 差異 12 github.com/microsoft/playwright
https://mvc.tw Playwright is ▪ Cross-language ▪ TypeScript / JavaScript ▪ .NET ▪ Python ▪ Java 13 playwright.dev
https://mvc.tw Playwright JavaScript 14
https://mvc.tw Playwright Python 15
https://mvc.tw Playwright Java 16
https://mvc.tw Playwright .NET 17
https://mvc.tw Playwright is 18
https://mvc.tw 19 Playwright is
https://mvc.tw Playwright Test ▪ Test Runner ▪ Reporters ▪ Parallelism ▪ Test Retries ▪ … 20
https://mvc.tw 21 Playwright: Browser Contexts
https://mvc.tw 22 Playwright: Browser Contexts ▪ Not Restart a Browser ▪ 完整隔離的環境 ▪ 快速實例化 ▪ 較低的資源開銷
https://mvc.tw 23 Playwright: Browser Contexts
https://mvc.tw 24 Playwright: Auto-waiting ▪ 簡化測試程式,有助於聚焦實際任務 ▪ 不太需要手動寫下 wait 來確保前端收到回應 ▪ 提高測試可靠性 ▪ 因應現今網站,頻繁存取後端 API 的特性 ▪ 執行操作前對 Element 可操作性檢查
https://mvc.tw 25 Playwright: Auto-waiting
https://mvc.tw 26 Why choose Playwright
https://mvc.tw Why choose Playwright 27
https://mvc.tw 28 Playwright Selenium Browsers Chromium, Firefox, and WebKit Chrome, Firefox, IE, Edge, Opera, Safari, and more Language Java, Python, C# JavaScript, Typescript Java, Python, C# JavaScript, Ruby, Perl, PHP Installation Easy to Install Easy to Install Prerequisites NodeJS Java, Browser Drivers OS Supported Windows, Linux, and Mac OS Windows, Linux, Solaris, and Mac OS Open Source Open Source and Free Open Source and Free Architecture Headless Browser with event-driven architecture Layered Architecture based on JSON Wire Protocol Real Devices Support Does not support real devices but supports emulators Supports real device clouds and remote servers
https://mvc.tw IDE 29
https://mvc.tw 30 How to use Playwright
https://mvc.tw Playwright Install ▪ Node.js ▪ .NET 31
https://mvc.tw Playwright ▪ Download browsers 32
https://mvc.tw Playwright ▪ Record videos ▪ Screenshots 33
https://mvc.tw Playwright ▪ Code generator and debugger ▪ Intercept network 34
https://mvc.tw CSS Seletors Sample Code 35
https://mvc.tw 36 CSS Selectors w3schools CSS Selectors
https://mvc.tw Playwright ▪ Inspector ▪ Debugging Playwright scripts 37
https://mvc.tw 38 Demo
https://mvc.tw 是否發生過,一句話惹怒… 39 網站反應很慢 怎麼慢法 ? 大約回應多久
https://mvc.tw Playwright ▪ Trace Viewer ▪ Recording trace ▪ Viewing trace ▪ Action ▪ Screenshots ▪ Snapshots 40
https://mvc.tw 41 Demo
https://mvc.tw 42 Getting started with .NET
https://mvc.tw Getting started with .NET 43
https://mvc.tw 44 Demo Code
https://mvc.tw Getting started with .NET 45
https://mvc.tw 46 Use Cases
https://mvc.tw 47 Network – Abort Requests
https://mvc.tw 48 什麼情況下需要用到 Abort Requests
https://mvc.tw 49 Network – Abort Requests ▪ Ads-blocker
https://mvc.tw 50 Demo Code
https://mvc.tw Network Abort Requests Ads-blocker Sample Code 51
https://mvc.tw 52 Network – Abort Request ▪ 網站新手提示 novice-guide-demo From 黑暗執行緒
https://mvc.tw 53 Demo Code
https://mvc.tw Network Abort Requests 網站新手提示 Sample Code 54
https://mvc.tw 55 Authentication
https://mvc.tw Authentication 56 測試執行時間 總計執行時間 登入次數
https://mvc.tw Authentication 57
https://mvc.tw 58 Demo Code
https://mvc.tw 59 總結
https://mvc.tw 總結 End-to-End Test ( RD & QA ) ▪ 提升開發效率 => 透過現代化工具 ▪ 提升溝通效率 => 透過 Trace Log ▪ 提升測試效率 => 透過 Network Abort Requests ▪ 目標關注在真正需要測試的內容: Ads-blocker / 網站新手提示 ▪ 降低重複性過多的步驟: Authentication 60
https://mvc.tw 61 參考資料
https://mvc.tw 參考資料 ▪ Playwright.dev ▪ microsoft/playwright 62
Blog 是記錄知識的最佳平台 63 https://dotblogs.com.tw
64 SkillTree 為了確保內容與實務不會脫節,我們都是聘請企業顧問等級 並且目前依然在職場的業界講師,我們不把時間浪費在述說歷史與沿革, 我們並不是教您考取證照,而是教您如何上場殺敵,拳拳到肉的內容才 是您花錢想要聽到的,而這也剛好是我們擅長的。 https://skilltree.my
65 天瓏資訊圖書

twMVC#44 如何測試與保護你的 web application with playwright