Skip to content
Tutorials Center
My learning

Topics

Lesson 33 of 36 ยท Projects and Practice

Project: a login and checkout web suite

Plan and build a layered Robot Framework web suite for a shop: login, search and checkout scenarios, resources, tags, teardown and a runnable simulated shop.

In this project you design the test suite for a small web shop: login, product search, add to cart and checkout. You will plan scenarios first, split them into layers, write the Robot files, and then run a simulated version of the shop in Python so you can see the scenarios pass and fail.

The real shop, a browser and the robot command are not available on this site. The Robot files are therefore shown read-only, and the shop itself is a Python stand-in with the same rules a real shop would have. When you do this project on your own machine, replace the stand-in with a real application (or a public practice site) and the page keywords with SeleniumLibrary or Browser Library calls.

Step 1: decide what to test

Do not start with code. List the behaviors that matter, in order of risk:

Priority Scenario Tags
High A registered user can log in smoke, login
High Wrong password is rejected with a message negative, login
High A user can search and find a product smoke, search
High A user can add a product and pay smoke, checkout
Medium Cart total is right with two items regression, checkout
Medium Empty search shows "no results" negative, search
Low Logging out clears the cart regression

Seven scenarios, four of them tagged smoke, is a sensible first suite.

Project plan

List scenarios Risk first.
Design layers Tests, business, pages.
Write keywords Bottom up.
Run and tag Smoke on each commit.

Build one scenario end to end before writing the rest.

1 / 2

Step 2: layout

TEXT
shop-tests/
  tests/
    login.robot
    search.robot
    checkout.robot
  resources/
    business.resource
    pages/login_page.resource
    pages/search_page.resource
    pages/cart_page.resource
    variables.resource
  requirements.txt

Step 3: the page layer

TEXT
# resources/pages/login_page.resource
*** Settings ***
Library    Browser

*** Variables ***
${USER_FIELD}    id=username
${PASS_FIELD}    id=password
${LOGIN_BUTTON}  role=button[name="Log in"]

*** Keywords ***
Submit Credentials
    [Arguments]    ${user}    ${password}
    Fill Text    ${USER_FIELD}    ${user}
    Fill Secret  ${PASS_FIELD}    $password
    Click        ${LOGIN_BUTTON}

Login Error Should Be
    [Arguments]    ${message}
    Get Text    css=.error    ==    ${message}

Fill Secret (Browser Library) hides the value in the log; it takes the variable name with a $, not the value. The search and cart pages follow the same pattern.

Step 4: the business layer

TEXT
# resources/business.resource
*** Settings ***
Resource    pages/login_page.resource
Resource    pages/search_page.resource
Resource    pages/cart_page.resource
Resource    variables.resource

*** Keywords ***
Log In As
    [Arguments]    ${user}    ${password}
    New Page    ${BASE_URL}/login
    Submit Credentials    ${user}    ${password}

Add Product To Cart
    [Arguments]    ${title}
    Search For    ${title}
    Open First Result
    Click Add To Cart

Pay By Card
    Open Cart
    Click Checkout
    Submit Card    4242 4242 4242 4242    12/30    123

The card number is the common public test number used by payment sandboxes; never type a real card into a test.

Step 5: the tests

TEXT
# tests/checkout.robot
*** Settings ***
Resource         ../resources/business.resource
Test Setup       Log In As    ${USER}    ${PASSWORD}
Test Teardown    Close Browser
Test Tags        checkout

*** Test Cases ***
Customer Buys A Book
    [Tags]    smoke
    Given the cart is empty
    When the customer adds "Clean Code"
    And the customer pays by card
    Then the order is confirmed

Cart Total With Two Items
    [Tags]    regression
    Given the cart is empty
    When the customer adds "Clean Code"
    And the customer adds "Refactoring"
    Then the cart total is 79.80

Run the smoke group with robot --include smoke tests/ (see run options).

Step 6: a simulated shop

The shop below is a plain Python object with real rules: users, a catalog, a cart and a total. The scenario functions use the same words as the Robot tests. Run it, then break a rule on purpose and see which scenario catches it.

Python Stand-in: the shop and its scenarios

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

All seven scenarios pass. Try changing round(..., 2) to int(...) in total, or the catalog price, and watch the total scenario fail: that is a regression test doing its job.

Step 7: reporting and CI

Add the suite to CI as in CI with GitHub Actions: run --include smoke on every pull request, the full suite nightly, upload results/, and take a screenshot on failure in the test teardown.

Make it better

  • Add data-driven login rows (blank user, blank password, long password) with a template.
  • Create the user through an API in the setup instead of relying on a fixed account.
  • Tag known flaky tests and review them weekly.
  • Add a second browser to the CI matrix.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What should you do before writing any Robot code in a project?

    Planning scenarios first stops you writing tests that nobody needs.
  2. 2. Where do locators belong in this project?

    Page resources own the locators so a UI change is fixed in one place.
  3. 3. Which tag group runs on every pull request?

    Smoke tests are the fast essentials, suitable for every change.
  4. 4. Why use a public test card number?

    Payment sandboxes publish test numbers so real card data never enters test code or reports.

Summary

  • Plan scenarios by risk and tag them (smoke, regression, negative).
  • Build bottom up: page keywords, business keywords, then tests.
  • Use setup and teardown for login and cleanup; read tests in Given/When/Then.
  • The simulated shop shows how scenarios catch real rule changes.
  • Wire the suite into CI with smoke on every change and full runs nightly.

Next: Project: an API test suite