Salman Ali's Work | ContraWork by Salman AliSalman Ali
AI-Augmented SQA Engineer with over 4 years of experience.
š. šŖšµš®š šš š®š» šššš²šæšš¶š¼š»?
An assertion is the check you make after something happens. In a manual test you do a step, then you look at the screen and compare it with the expected result. If you click Save and the page still says the invoice is not saved, the test fails. The click is not the result.
Playwright Test writes that check with expect(). You give expect a locator, which is a description of an element, and then a matcher. A matcher is the condition you want to be true. toHaveText checks exact text. toBeVisible checks that an element is shown.
These locator checks are web-first assertions. A web-first assertion retries until the condition is true or time runs out. This project sets that limit to five seconds in playwright.config.ts.
You can reverse a matcher with not. expect(status).not.toHaveText('Invoice failed') fails when that wrong sentence is present. Use not when the result you need is the absence of a message.
š®. šŖšµš šš¼ šŖš² š”š²š²š± šš?
Pressing the button on a coffee machine is an action. Looking in the cup to see that coffee is there is the assertion. If you only press the button, you cannot tell a full cup from an empty one.
Clicking Save invoice asks the page to save. It does not prove the save worked. A test that ends on the click can pass while the status still says "Not saved". The expected result has to be its own check.
šÆ. ššŗš½š¹š²šŗš²š»šš®šš¶š¼š»
Start with the check alone. The matcher requires the words "Invoice saved".
getByRole('status') finds the message a person would read after saving. expect and toHaveText form the web-first check. Playwright keeps looking until the text matches or five seconds pass.
The practical test opens the local demo, confirms the starting message, clicks, and checks the new message. goto('/assertions') uses baseURL from the Playwright config.
goto opens the page. The first toHaveText records the start, "Not saved", so a later pass cannot come from text that was already there. click is only the action. The second toHaveText is the result of that action. The script does not also check that the text is not "Invoice failed". The exact success message already answers that question.
š°. šš
š½š²š°šš²š± š„š²ššš¹š
A passing run starts at "Not saved", clicks Save invoice, and ends with "Invoice saved". A failing run means one of those texts did not match before the five-second assertion timeout.
š±. š§š®šøš²š®šš®šš
⢠click performs an action. expect() checks the result.
⢠A matcher such as toHaveText states the expected result.
⢠Web-first assertions retry until they pass or the timeout ends.
⢠Use not when the result is the absence of a specific message.
šš»šš²šæšš¶š²š š¾šš²ššš¶š¼š»: What is the difference between clicking Save and asserting the status text?
šš»ššš²šæ: The click performs the action. The assertion checks the expected result. Without that check, a test can pass when the save changed nothing the user can see.
š². š„š²š³š²šæš²š»š°š²š
⢠https://playwright.dev/docs/test-assertions
⢠https://playwright.dev/docs/api/class-locatorassertions Boost your career as a QA engineer with personalized 1-on-1 guidance! Whether you are looking to master modern test automation, scale up your workflows with AI testing tools, or navigate job transitions, let's connect.
Book a session with me on Topmate (https://topmate.io/muhammad_salman_ali10/1131173) and get actionable insights to level up your software quality journey.
Link : https://topmate.io/muhammad_salman_ali10/1131173
#QAEngineer #SoftwareTesting #TestAutomation #CareerGuidance #TechMentorship #ContraCommunity AI-Augmented Test Development Workflow Enterprise CRM Automation | Selenium + Java + TestNG