In my early days at Runninghill, a challenge appeared: introduce automation testing to the team. With scant details from my senior, I grasped the gravity of the issue. The client’s testers, heavily reliant on manual methods, were missing key details, leading to major problems. Automation was the missing piece. Daunting? Yes. Especially for a green graduate like me. But it was clearly the path forward.
Automation testing has revolutionized the software development industry, offering an efficient and reliable way to verify application functionality. In this comprehensive blog post, I’ll guide you through my journey of getting started with Playwright, walking you step-by-step through the process and offering valuable insights to help you harness its full potential for automation testing.
Even if you’re familiar with regression testing, it’s worth diving deeper to understand its significance. At its core, regression testing is employed to ensure that any changes—be it modifications, updates, or improvements to the code—do not adversely affect the existing functionalities of an application.
This is crucial because any software, especially enterprise applications, continuously evolves. With each change, there’s a risk: what if the new code breaks an existing feature? What if it introduces new bugs? Regression testing is our safety net, ensuring that the software remains stable and efficient with every new iteration. In the Agile world, this safety net is paramount, ensuring that every change aligns with the system’s overall operations. Hence, before any modifications become part of the main development branch or get deployed to staging environments like SIT, UAT, and Production, they are rigorously tested.
Yet, despite its significance, regression testing is not without its challenges. These challenges have paved the way for automation tools like Playwright.
Repetitiveness: Every new code change requires us to run the same tests over and over. This repetition, especially in extensive applications, can significantly slow down the development pace.
Time-Intensive: Beyond the tests themselves, even the setup—particularly in intricate domains like insurance—can be lengthy and cumbersome.
Prone to Errors: With extensive manual testing comes the risk of human errors. A missed step or a misjudged result can lead to undetected defects.
Given these challenges, isn’t there a need for a more efficient, error-free approach? Enter: Automation Testing. If you’ve ever felt that regression testing is a drawn-out dance, automation testing might just be the rhythmic shortcut you’ve been yearning for!
Crafted by Microsoft, Playwright is a robust Node.js library that automates browser tasks across various platforms like Chromium, Firefox, and WebKit. Through its unified API, it empowers developers to devise, test, and validate web applications across a multitude of browsers and platforms. With its reputation for swiftness and dependability, it’s no wonder Playwright is quickly becoming the first choice for developers who prioritize consistency in their web applications.
When selecting a tool, my primary concerns were speed, efficiency, and reliability. Here’s why Playwright checked all those boxes:
Oh wow, you’re still here? My apologies for keeping you in suspense! Let’s not delay any further. Dive into the world of Playwright with me. A thrilling journey of installation and exploration is just a command away!
Now that you’re primed and ready, let’s dive straight into the installation process of Playwright. It’s simpler than you might think!
On your command line, positioned at the root of your project (I’d recommend running in Administrator mode), punch in the following:
OR
(You can choose your desired version)
Encounter any pesky dependency conflicts or mismatches? Give this a shot:
OR
You can also try:
OR
During installation, your terminal might prompt you to opt between TypeScript and JavaScript. TypeScript is the default selection. If you didn’t get this option, no worries! It just means TypeScript was chosen by default. For the upcoming prompts, hit ‘Enter’ for all three unless you have a specific configuration change in mind and you’re confident in your choices.
When crafting your own tests, ensure you adhere to the [filename].spec.ts naming protocol. While some tutorials suggest omitting the .spec (e.g., ffwSndFlow.ts), my experiments suggest otherwise.
Bring it back to life by uncommenting and updating:
If you aim to utilize a port that’s already active, e.g. localhost:4200, you can include the following property:
By incorporating this setting, your configuration object would be structured as follows:
Let’s get crack-a-lacking 🙂
Step 1: Create a file with a descriptive name that resonates with your team. For instance, using names like ffwSndFlow.spec.ts or ddTnrFlow.spec.ts might be apt. In our setup, terms like “ffwSnd” and “ddTnr” correspond to specific products within the application, making them instantly recognizable to team members.
Step 2: Serve your application using, for instance, ng serve if using angular or the command your application utilizes to serve.
Step 3: On your command line, unfurl the command:
With everything in order, your main screen should illuminate with…
Step 4: Next up ,time to specify the application specific URL. Simply replace the placeholder about:blank with your desired address, just as you would enter it into a browser’s address bar.
For example: http://localhost:4200/home?appCode=25&vdn=12345&entrySale=SND.
Step 5: Upon execution, you should notice the Playwright inspector tool activatedplaywright
NOTE:
With every interaction or click on the application, the Playwright inspector tool generates code. Exercise caution and diligence as you progress at this stage.
Step 6:
Navigate through your application, covering the extent you want the automation test to capture.
At this point, your Playwright inspector tool should be brimming with scripts, as shown below:
Step 4: Depending on your configurations in playwright.config, you’ll either see a browser session showcasing the automated test or feedback directly in your terminal. After tests complete, the terminal provides a command to view a comprehensive report of the test(s) undertaken.
Following completion, you can expect to see test results either presented within an active browser window or detailed in the terminal. The terminal will also suggest a command allowing you to review a comprehensive report of the test(s) executed.
For a deeper dive with more commands and further clarity, do explore Playwright’s official documentation: Playwright Documentation 🎭
WRITTEN BY
Katlego Mohoje