· tutorials · 3 min read

Automizing Best Buy Tests with Automize - Enhancing Your Testing Strategy

Welcome back to our series on writing automation scripts with Automize! In this post, we’re going to dive deeper into enhancing our previous Best Buy automation script. This updated approach will ensure that our tests are robust and can adapt to changes on the website.

Welcome back to our series on writing automation scripts with Automize! In this post, we’re going to dive deeper into enhancing our previous Best Buy automation script. This updated approach will ensure that our tests are robust and can adapt to changes on the website.

This blog was generated from a tutorial video you can watch here

1. Review of the Initial Script

In our earlier sessions, we wrote an automation script that successfully navigated to the Best Buy website, searched for “wireless printers,” and printed out the results along with their prices. Although it worked well, we identified opportunities for improvement in our testing framework to make it more resilient against potential changes in the website’s structure.

2. Understanding the Pitfalls

One of the challenges we faced was that our original script relied heavily on specific attributes of the search field, like its ARA tag. If the development team modified the search bar (for instance, changing the labeling or structure), it could lead to failed tests.

Moreover, the original selectors we employed were limited; they did not verify the location of the search bar on the page. If the search field were moved to a different part of the website, our automation wouldn’t catch that either.

3. Building a More Robust Test

To begin fortifying our test, we’ll focus on modifying our selectors within Automize. Our goal here is to ensure that the tests remain valid even if underlying elements change. Here’s what we’ll do:

  • Refine the Selector: Instead of relying on fragile attributes, we’ll implement checks that confirm the search bar’s presence within the header section of the page, using a composite selector that combines the parent attributes and a name attribute.

  • Dynamic Assertions: We need to reinforce the setup by adding assertions after inputting the search term. With this, we can verify the search results by not just clicking the first entry but confirming its title and price.

    Here’s a snippet of how we can add these dynamic checks:

// Example of new selectors
const searchBar = document.querySelector('header .shop-search-bar input[name="search"]');
const firstResultTitle = document.querySelector('main #main-results li:first-child h4');
const firstResultPrice = document.querySelector('main #main-results li:first-child .customer-price');

4. Running the Enhanced Test

After implementing these changes, we run our updated automation script. We input “wireless printer” into the search field, observe the loaded results, and check that the title of the first result matches our expectations. Initially, it might fail if the product or prices have changed, but that’s where learning happens!

Output Example

Upon executing the script, we expect it to return specific results:

  • The first result title should match “HP Envy”
  • The price should reflect current data, e.g., $69.99

Handling Test Failures

As expected, if there’s a disparity in the product titles or prices, our test will fail, prompting us to revisit our selectors or expected values. This iterative process strengthens the resilience of our automation.

5. Conclusion

Through this session, we’ve learned how to refine our automation scripts for Best Buy by utilizing more advanced and robust selectors, enhancing our assertion process, and ultimately preparing our tests for future changes on the website. Stay tuned for upcoming tutorials where we’ll explore ways to mock network requests to maintain tests even when products change.

Happy automating, and don’t forget to subscribe to our channel for more insightful tutorials and tips on mastering automation with Au

Back to Blog