Playwright for Beginners
Playwright Architecture
Architecture plays a crucial role; it is something that actually drives what your web automation driver can or cannot do.
Let us look at the chromium app architecture, we have in process automation and our process automation
Playwright Architecture is built on a solid, battle-tested foundation. None other than our own Chrome Dev Tools
Playwright enables reliable end-to-end testing for modern web apps.
Anything which runs in the browser you can test using playwright.
Playwright supports all modern rendering engines including Chromium, WebKit, and Firefox. (Experimental with electron).
Playwright has cross platform support, Windows, Linux, and macOS, locally or on CI, headless or headed. One API write you code once and works across all 3 dimensions.
Also it supports cross language.
Use the Playwright API in TypeScript, JavaScript, Python, .NET, Java. TypeScript/JavaScript where most feature is present.
Browser Context
- Playwright creates a browser context for each test.
- Browser context is equivalent to a brand new browser profile.
- This delivers full test isolation with zero overhead.
- Creating a new browser context only takes a handful of milliseconds.
Test Mobile Web
- Native mobile emulation of Google Chrome for Android and Mobile Safari
- Simulate browser behavior for a specific device such as user agent, screen size, viewport and if it has touch enabled.
Auto-wait Mechanism
- Playwright waits for elements to be actionable prior to performing actions.
- It also has a rich set of introspection events.
- The combination of the two eliminates the need for artificial timeouts – the primary cause of flaky tests.
Tracing
- Configure test retry strategy, capture execution trace, videos, screenshots to eliminate flakes.
- Playwright traces can be opened in Trace Viewer after Playwright script runs.
Trace Viewer
Capture all the information to investigate the test failure.
Playwright trace contains test execution screencast, live DOM snapshots, action explorer, test source, and many more.
Trace Viewer have Action Tab, Screenshots, Metadata, Snapshot, Call, Log, Errors, Console, Network, Source
Authentication
- Save the authentication state of the context and reuse it in all the tests.
- This bypasses repetitive log-in operations in each test, yet delivers full isolation of independent tests.
- Create a separate file and add it to .gitignore.
When to use
- When you can imagine all your tests running at the same time with the same account, without affecting each other.
When not to use
- Your tests modify server-side state. For example, one test checks the rendering of the settings page, while the other test is changing the setting, and you run tests in parallel. In this case, tests must use different accounts.
- Your authentication is browser-specific.
File Upload
- You can select input files for upload using the Locator.SetInputFilesAsync() method.
- It expects first argument to point to an input element with the type “file”.
- Multiple files can be passed in the array.
- Empty array clears the selected files.
File Download
- For every attachment downloaded by the page, Page.Download event is emitted.
- All these attachments are downloaded into a temporary folder.
- You can obtain the download url, file name and payload stream using the Download object from the event.
CodeGen
- Generate tests by recording your actions. Save them into any language.
Supporting/ Reference Links
- Andrey Lushnikov Talk on Applitools
- https://github.com/shoaibshaikh2046/PlaywrightDotnet
- https://github.com/microsoft/playwright
- https://playwright.dev/dotnet/
- https://bit.ly/shoaib_linkedIn
Demo of the Basics of Playwright
Thank You .. !!

