Skip to main content

Blog #7: Fun & Hands-On Guide to Testing Forms with Playwright šŸš€


Forms are like your appā€™s "conversation starters" with users. If input fields, radio buttons, or checkboxes break, itā€™s like your app suddenly forgets how to speak! Letā€™s learn how to test these elements interactively using Playwrightā€”no prior experience needed!


šŸ•¹ļø Quick Interactive Quiz!

(Answer as you read!)

Q: Whatā€™s the first thing you test for any form element?

A) Color
B) Visibility
C) Font size

Spoiler: The answer is at the end of this section!


šŸŽ® Letā€™s Play! Testing Input Fields

Imagine this: Youā€™re testing a login form. Letā€™s make sure the email field works.

Step-by-Step Demo

Hereā€™s a sneak peek at the some must-do tests for input fields:


Test Explanation:

  1. Visibility: We first check if the input field is visible. A hidden input field is like an invisible formā€”it canā€™t be used!

  2. Enabled State: Next, we ensure the email input field is enabled. A disabled field is a dead end for the userā€”itā€™s not clickable or editable.

  3. Initial Value: We then verify that the email input field is empty when the page loads. You wouldnā€™t want a pre-filled email like "testuser123@gmail.com" if thatā€™s not what the user intended!

  4. User Interaction: Now, we simulate the user typing in the email field. After typing, we confirm that the value entered matches exactly what the user typed, ensuring the input works as expected.

  5. Clear the Field: Lastly, we test the ability to clear the field. Once the user is done, they should be able to erase what theyā€™ve typed, and the field should become empty again.


šŸ’” Pro Tip:
Try breaking the test! Change 'testeruser123@gmail.com' to 
šŸ‘©ā€šŸ’» and see what happens.


šŸŽÆ Testing Radio Buttons (The ā€œChoose Oneā€ Game)

Imagine you're on a form where you need to choose your gender: Male or Female. Letā€™s ensure both radio buttons work perfectly.


Test Explanation:

  1. Visibility: The first test checks if the radio button is visible on the page. If the button is hidden, itā€™s like trying to make a selection on a ghost form!

  2. Enabled State: Here, we ensure the radio button is active and clickable. Disabled radio buttons are like locked doorsā€”canā€™t click them!

  3. Default Unselected State: By default, the female radio button should be unselected. This ensures that no oneā€™s choice is pre-filled (which would be a bit creepy, right?).

  4. User Interaction (Selecting the Radio Button): Next, we simulate the userā€™s action by selecting the female option. This mimics a real userā€™s interaction with the form.

  5. Verification Post-Selection: Once selected, we verify the buttonā€™s state to ensure the UI reflects the userā€™s choice.

  6. Alternative Check: A quick alternative to verify if the radio button is selected is using isChecked(). This returns true when the button is checked and false when it's not.

  7. Male Button Check: Finally, we ensure that the male radio button is still unselected after selecting the female option, confirming that only one choice can be selected.


šŸ¤– Testing Checkboxes (The ā€œSelect Allā€ Puzzle)

A form asks, ā€œWhich hobbies do you enjoy?ā€ šŸŽ®šŸŽøšŸ“š
Checkboxes are special because, unlike radio buttons (which only allow one option to be selected), you can select multiple options! This makes testing checkboxes a little differentā€”letā€™s see how we can test them with Playwright.

Letā€™s Dive In!

Weā€™ll test three checkboxes for hobbies: Gaming, Music, and Reading. Hereā€™s how we do it step-by-step!


Test Explanation:

  1. Locating Checkboxes: We identify the checkboxes using their CSS selectors and store them in an array (checkboxLocators).

  2. Checking Checkboxes: We loop through each checkbox and use .check() to select them.

  3. Unchecking Checkboxes: We loop again, checking if the checkbox is selected with .isChecked(), and uncheck it with .uncheck() if true.

Difference Between Checkboxes & Radio Buttons:
  • Checkboxes allow multiple selections, and each can be independently checked/unchecked.

  • Radio Buttons allow only one selection.

Pro Tip: Test visibility, enabled state, and checked stateā€”same as radio buttons!


šŸ“Š Cheatsheet: Your Testing Toolkit


Q: Whatā€™s the first thing you test for any form element?

āœ… A) Visibility! (You canā€™t interact with something you canā€™t see!)


šŸš€ Do You Have to Use All Assertions?

No, you don't need all assertions for every element. Use the ones that match the behaviour you're testing. 

Focus on what's important for each case, and keep it simple!


Comments

Popular posts from this blog

Software Testing Heuristics and mnemonics.

Software Testing Heuristics Heuristics are simply experience-based techniques for problem-solving, learning, and discovery. Where an exhaustive search is impractical, heuristic methods are used to speed up the process of finding a satisfactory solution. Examples of this method include using a rule of thumb, an educated guess, an intuitive judgment, or common sense. When you face a problem, you try some solutions that may work. For instance, if you suddenly find your mobile hang, what do you do? You may restart your mobile first. If that doesnā€™t work, then you may check & update the latest software and uninstall suspicious apps.if that also doesnā€™t work, then you reset your phone setting ( Factory reset). Most of us try a number of steps to solve our problems. These steps may not always work but we try them because we know that they may work. Following heuristics can apply to absolutely any kind of system with any kind of interface.  1.Abstract  Remove details in a model. S...

What is Agile?

                              Recently I did a presentation after almost 20 years at a Bootcamp showcase on Agile. As Agile celebrated its 20th anniversary this year I decided to talk on what Agile is? Below are the few drops from Agile's ocean which I managed to pour during my showcase. What is Agile Software Development? Agile is a time boxed, iterative approach to software delivery that builds software incrementally from the start of the project, instead of trying to deliver it all at once near the end. It works by breaking projects down into little bits of user functionality called user stories, prioritizing them, and then continuously delivering them in short time cycles called iterations.                In iterative development, feature code is designed, developed and tested in repeated cycles. With each iteration, additional features can...

A Beginner's Guide to Playwright Testing with JavaScript: 4- A Deep Dive into Playwright Assertions

  Ever spent hours debugging a test only to realize you forgot to check if a button was actually clickable? In web testing, the devil's in the detailsā€”and that's where assertions become your best friend. Let's explore how Playwright's assertion library can transform your testing strategy, using the popular The Internet testing playground. Why Assertions Matter Assertions are the backbone of any meaningful test. They're the checkpoints that scream, "This works!" or "Something's broken here!" Playwright's built-in expect library shines when testing real-world scenarios like authentication flows and dynamic content. Let's Start Testing: A Real-World Scenario We'll be testing key features of The Internet playground. Here's our foundation: Now let's add powerful assertions. Validating Content: Is What You See What You Get? 1. Page Titles: Your First Line of Defense Verify you're on the correct page immediately after na...

Day 15 Name five different online payment methods.

Most modern online payment services offer easy-to-use, fast and secure ways to pay Hereā€™s a list of some of the most popular online payment services: Digital Wallet ( E wallet) A digital wallet refers to software, an electronic device, or an online service that enables individuals or businesses to make transactions electronically. It stores the payment information of users for different payment modes on various websites.                           PayPal PayPal is one of the most dominant payment methods available today. over 20 million UK shoppers use PayPal each year in the UK and  7 million businesses worldwide use their platform to accept payments. PayPal is an eCommerce payment processing company that allows users to set up a PayPal account and pay a fee for each cash transaction. Many customers prefer to checkout with PayPal because itā€™s so simple and quick to use. Amazon Pay Amazon Pay is another ...

Risk Storming for Vending Machine

  In the 4th session of Testing Bootcamp Beth Marshall introduced us to a very interesting game of Risk Storming. It's a  collaborative and visual technique for identifying risk and planning the Test Strategy accordingly .You can  use a Test Sphere card deck from Ministry of Testing or go to https://riskstormingonline.com/   Risk Storming takes you through three phases to get the answers. Which quality aspects matter most for your product? What risks could impact these important aspects? How can you test to make sure those risks donā€™t happen?     Our task was to risk storming to test the Vending Machine . And here is my take on it.                               Quality Aspect Functionality  Does it accept and return both coin and cash correctly? BOUNDARY VALUE TESTING Does it drop the selected product correctly? INTEGRATION TESTING , BUSINESS SCENARIOS , PURPOSE Is the k...

What is Quality

  āœØ What is Quality? Quality means different things to different people. For some, the brand Apple šŸ is synonymous with quality. For others, itā€™s difficult to define quality, but surprisingly easy to recognize based on their experiences. A quality product or service is one that satisfies customer needs and meets (or even exceeds!) their expectations. When you receive quality, in whatever form, you're eager to get more. You want to return for another purchase, refer the product to friends, and talk about it publicly. Quality is what we should aim for to ensure returning customers and a strong brand as a company. According to IEEE , quality is defined as ā€œThe degree to which a component, system, or process meets specified requirements and/or user/customer needs and expectations.ā€ šŸ“ˆ šŸ‘„ Who is Responsible for Software Quality?   Everyone involved in a software projectā€”including the Product Owner , Scrum Master , Developer , Tester , and other stakeholders such as the Business ...

Day 7 Name five examples of an ecommerce platform?

  An ecommerce platform is a software application that allows online businesses to manage their website, marketing, sales and operations. Following are the examples of 5 best ecommerce platforms in 2020. Shopify (www.shopify.com) Woo Commerce (woocommerce.com) Big Commerce (www.bigcommerce.com) Magento (magento.com) Wix eCommerce (www.wix.c om/ecommerce/ )