QA Testing Tips: Are You Testing Assertions Properly?

Ghost Inspector is an automated web testing tool that helps QA testers and engineers to easily build, edit, and run low-code/no-code web tests. Start a free trial.
testing assertions

For QA testers, success boils down to delivering a seamless user experience. And though it may seem like a small step in the software testing process, assertions play an essential role in confirming the accuracy of expected outcomes, validating conditions, and fortifying the overall quality of your codebase. For QA testers running codeless tests, there are a few important fundamentals regarding testing assertions with Ghost Inspector.

Today, we’re going to give you a quick rundown on what assertions are, why they’re so important in Quality Assurance, and how you can properly test them using Ghost Inspector.

Table of Contents

Automate your browser testing strategy with Ghost Inspector

Our 14 day free trial gives you and your team full access. Create tests in minutes. No credit card required.

Ghost Inspector mascot Ghostie, a little white ghost symbol next to error pages and tabs

What are assertions in performance testing?

An assertion acts as a kind of confirmation, ensuring the user that predicted conditions or outcomes in a web application have been met. Assertions are like checkpoints for expected behavior, validating that the various components of a website—from the user interface to underlying functionalities—are performing as expected.

To give an example: an assertion might be the appearance of a success message after submitting a form or the confirmation of a product’s presence in your online shopping cart. In CI/CD pipelines, assertions allow for rapid and reliable validation of code changes, helping teams maintain software quality, even while releasing frequent updates. Whether executed throughout a test or at the initiation phase, assertions are an essential step during browser testing. 

What happens when you don’t use assertions?

When assertions are missing from the browser testing process, the consequences can be dire. Without them, your website might exhibit faulty behaviors, resulting in a degraded user experience and the potential loss of critical functionalities. Most importantly, a lack of assertions can lead to the increased likelihood of undetected bugs making their way into the production environment.

Without effective assertions, the automated testing process loses its ability to act as a reliable safety net. Issues that should be caught during testing might slip through undetected, only surfacing once the website is live. The consequences? A compromised user interface, diminished trust in the application, and the need for time-consuming and potentially costly post-launch bug fixes.

This is why it’s so important to know how to add assertions in automated browser testing. They confirm that your web application functions correctly under varied conditions, safeguarding against glitches and contributing to the overall reliability of your website. In the following sections, we’ll detail a few best practices for testing assertions during automated browser testing.

test assertions with Ghost Inspector

Testing assertions in manual testing vs. automated testing

In the shift from manual to automated testing, essential validation steps can sometimes be overlooked. For instance, when manually testing a form, a tester can visually confirm a success message. However, in automated testing, this visual check needs to be translated into a programmed assertion. Without such assertions, automated testing might miss key steps, potentially overlooking issues that impact user experience.

Consider a form that requires a valid email address for successful submission. If you enter an invalid email address during the test, the assertions will act as checkpoints, verifying that each step is validated before progressing further. In the absence of assertions, the steps might execute without interruption and provide a false sense of success.

This is where assertions come into play. They offer a concrete way to guarantee the expected result during critical test points. For instance, after submitting the form, an assertion can be used to verify the appearance of a success message. Without assertions, the test might progress, and a single missed flaw from that progression can amount to significant sales losses for the company. The beauty of assertions lies in their ability to halt a test, flag a failure, and prevent the test from passing with a broken functionality. 

Assertions also provide an extra layer of control over test flow. Testers have the power to dictate the sequence of actions and confirm the expected outcomes at each stage. This not only ensures accuracy but also mimics the intuitive flow that manual testers often use. 

Creating assertions for testing with Ghost Inspector

Assertions play a critical role in automated testing, irrespective of the testing framework used, whether it’s Selenium, Cypress, Puppeteer, or others. The test results may appear favorable, but the danger lies in not explicitly confirming expected outcomes. This can lead to undetected issues impacting the application’s functionality and user experience.

With Ghost Inspector, you might create a new test by manually recording the steps of filling out a form, submitting it, and receiving a success message. As a manual tester, the inclination might be to assume everything is working fine, given the visible success message. However, when transitioning to automated testing, an important step is often missed if assertions aren’t explicitly defined.

Ghost Inspector demo sample form with make assertions button clicked

Steps for Making Assertions with Ghost Inspector

1. When recording a test with the Ghost Inspector browser extension, click on the extension icon.

2. Click on the Make Assertions button to select elements on the page for confirmation.

3. Mouse over the element on the page you would like to assert and click on it.

4. You can make additional assertions before switching back to recording additional steps.

In Make Assertions mode, the mouse cursor switches to a crosshair cursor. As the user hovers over text, images, buttons and any other element on the page, the area the element occupies on the page is shown in a dotted-line border. 

Clicking on an element lets Ghost Inspector know to make an assertion. By default, Ghost Inspector asserts the presence of the element. The Ghost Inspector web test recorder can be switched to assert visibility instead of presence via its Settings.

Screenshot of Ghost Inspector back end with Element is visible highlighted on the menu

Here’s an example of what your Ghost Inspector assertion will look like on the backend:

The form has been successfully submitted assertion step

And here’s an example of what it may look like to your users:

demo sample form for testing

Note: Ghost Inspector provides a fallback option called screenshot comparison, which detects visual differences when issues arise. With this feature, Ghost Inspector can still catch problems and alert for a test failure if an assertion is needed but doesn’t exist. However, this option doesn’t substitute for the importance of having precise assertions.

Avoid getting carried away with assertions

While assertions are invaluable to the test automation process, a word of caution is warranted. It’s important to strike the right balance during test execution. Avoid the temptation to inundate your test script with a high number of assertions. Focus on the ones that directly relate to the functionality being tested and steer clear of unrelated checks. This will help prevent the testing process from being elongated and over-complicated. By integrating assertions thoughtfully into your tests, you can protect your web applications from problems before they arise, instilling confidence in the reliability of your software.

Conclusion

Assertions are the backbone of reliable browser testing. They offer a clear lens through which to verify an application’s behavior, confirming that each step aligns with expectations. They also contribute to maintaining consistency in the actions of a software application across different builds or versions. By doing thorough assertion testing, you enact a constant benchmark, ensuring that essential functionalities remain intact, even with software modifications and updates. 

Ghost Inspector makes it easy for QA testers to create assertions for automated tests without having to use any coding skills. If you’d like to give our no-code/low-code automated testing tools a try, you can sign up for a free 14-day trial here, no credit card required. 

Automate your browser testing strategy with Ghost Inspector

Our 14 day free trial gives you and your team full access. Create tests in minutes. No credit card required.