Project ยท 35 min
Project: test the shop
The task
This is the second project. You test the shop from the earlier lessons, from an empty file. The shop has a product list, a search box, a sort list, a cart with quantities, and totals with shipping. Orders over 50 dollars ship for free.
Do the steps by hand in the practice browser first, so that you know what the numbers should be. Then write a test, run it, and check your work.
What to use
You have the tools for a clean set of tests. Use them.
- A page object for the shop, with the steps
open,addToCart, andopenCart. - A
beforeEachhook that opens the shop and waits until the six products are there. - Assertions that wait. After an action that sends a request, check its result before the next step. Never use a fixed wait.
- Exact values, such as
toHaveText('$25.50'), so that a wrong total cannot pass.
Share the page object with the tests
A hook and a test do not share local variables. Make the page object in the hook and save it in a variable outside the hook, or ask for a fixture. The first way is shorter for a file of this size. The second way is better in a big project, because each test gets its own object, and you do not need a shared variable.
A last check
When all seven tasks pass, read your file once more as if you were a new colleague. Does each test name tell what the shop must do? Is the checking in the tests, and the clicking in the page object? A set of tests is a document that other people read.
Tasks
7 to do
Task 1, not checked yet. Count the products in the cart. Add
Blue Mug, and check that the cart count in the header is1. AddNotebook, and check that it is2.Task 2, not checked yet. Total the cart with shipping. Add
Blue MugandNotebook, and open the cart. Check that the cart has 2 rows, that the subtotal is$20.50, that the shipping is$5.00, and that the total is$25.50.Task 3, not checked yet. Ship for free over 50 dollars. Add the
Backpackand open the cart. Check that the shipping isFreeand that the total is$59.00.Task 4, not checked yet. Search without caring about case. Search for
LAMP. Check that there is one product card, and that its heading isDesk Lamp.Task 5, not checked yet. Sort by price. Choose
Price: low to highin the listSort by, and check that the first heading of level 2 isSticker Pack. ChoosePrice: high to low, and check that it isBackpack.Task 6, not checked yet. Remove a product. Add
Notebook, open the cart, and clickRemove. Check that the textYour cart is empty.is visible.Task 7, not checked yet. Use the quantity. Add
Blue Mugand open the cart. Change the quantity ofBlue Mugto3. Check that the subtotal is$36.00.
Task 1 of 7
Count the products in the cart. Add Blue Mug, and check that the cart count in the header is 1. Add Notebook, and check that it is 2.