This tutorial will encompass everything that a non-load testing expert will need to get started to write a script to test your Magento shop.
Step 1: User loads the landing page
This one is easy. All we need to do is rename the step, replace the url of the page we’re loading, and remove all the comments.
Download the entire script
You can find the complete script used in this scenario, as well as other useful examples, in our load-testing-playground repository.
Step 2: User searches for an item in the shop
For this step we’re going to use the search box in the top right of the homepage to search for shirts. We use the browser object’s
press methods to simulate typing in shirts and pressing return. After pressing return we are going to wait for the url to change to signify the page has changed.
If you save this step now, your browser should automatically re-run the test, visiting the homepage, typing into the search box, and visiting the results page.
This is a good time to talk about assertions in browser-level load testing. There can be so many moving parts in a web page. Sometimes pages will appear to load, but are obviously broken. For example, if our search results loaded, but had no results when we expected to find 5 shirts it would mean something is broken. We can use asserts to verify the page state. Add the following code to your step:
Now our test will fail if we don’t have the expected amount of items. You can make your assertions as simple or as complex as you want. What matters is the first value is a boolean
true for pass or
false for fail.
Finally, we’re going to click the first result to take us to the new page.
Step 3: User adds the item to the shopping cart
We’re on the page to purchase our shirt and we want to add it to the cart. To make things complicated, we have to choose a colour and a size before we can add it to the cart. In our shop these don’t load immediately so it’s a little more complicated than waiting for the page to load and click them.
- First, we make our locators for all the elements and wait until they’re visible.
- Second, we click the options for black and large.
- Finally, we click the button to add it to the cart.
For this step to be complete we should wait until we receive confirmation that the item was successfully added to the cart:
Step 4: User visits the cart
This is another slightly complex navigation. In our shop the cart link shows a popover of the cart state instead of taking you directly to the cart. In the end it means we have to click it to show the popover, and then click the view cart link inside the popover.
Once there, like the search page we should assert the page has the correct information. This time we’re going to check the total price is correct.
Step 5: User goes to checkout
The checkout process is always a long step because there is so much user interaction necessary. Fields have to be filled, shipping options chosen. On our
magento.loadtest.io demo site, you don’t have to enter payment info.
First, let’s go to the checkout page and fill out the form.
Then, once shipping has been selected we can move onto payment. Our demo doesn’t have real payment, so this is the best we can do with the demo site.
Download the entire script
Your site will have different payment requirements, but you can use the skills you learnt in this tutorial to write that part of the script. If you’d like to download our sample script, and many other examples, take a look at our [load-testing-playground][loadtestingplayground] repository.