Skip to main content

Robot Framework Setup And Basics

Installation of RobotFramework

To get started with Robot Framework basically you need Python and pip installed.

If you have not set up your virtual environment:

# Create a virtual environment named 'venv'
python3 -m venv venv
# Activate the virtual environment
source venv/bin/activate
# Install dependencies from requirements.txt
pip install -r requirements.txt
apipkg==1.5
appium-python-client==2.7.0
attrs==20.3.0
certifi==2021.10.8
chardet==4.0.0
decorator==5.0.6
docutils==0.17
execnet==1.8.0
idna==2.10
importlib-metadata==3.10.0 ; python_version < '3.8'
iniconfig==1.1.1
kitchen==1.2.6
more-itertools==8.7.0
packaging==20.9
pluggy==0.13.1
py==1.10.0
pyparsing==2.4.7
pytest-forked==1.3.0
pytest-xdist==2.2.1
pytest==6.2.5
pyyaml==5.4.1
requests==2.25.1
robotframework-appiumlibrary==1.5.0.7
robotframework-pabot==1.11
robotframework-pythonlibcore==2.2.1
robotframework-seleniumlibrary==5.1.3
robotframework==4.0.1
saucebindings==1.0.0
sauceclient==1.0.0
selenium==4.4.3
six==1.15.0
toml==0.10.2
typing-extensions==3.7.4.3 ; python_version < '3.8'
urllib3==1.26.12
zipp==3.4.1
*** Settings ***
Library SeleniumLibrary

*** Variables ***
${WEBSITE} https://www.saucedemo.com/
${BROWSER} firefox
${DELAY} 0.2s
${ADD TO CART} //*[@id="add-to-cart-sauce-labs-bolt-t-shirt"]
${CART PATH} /html/body/div/div/div/div[1]/div[1]/div[3]/a
${SUBTOTAL PATH} //*[@class="summary_subtotal_label"]
${TAX PATH} //*[@class="summary_tax_label"]
${TOTAL PATH} //*[@class="summary_total_label"]

*** Keywords ***
Test Suite Setup
OpenBrowser ${WEBSITE} ${BROWSER}
MaximizeWindow
SetConfig SearchMode draw
SetConfig Delay ${DELAY}

Verify Correct Site
VerifyUrl https://www.saucedemo.com/

Enter Username
[Arguments] ${USERNAME}
TypeText Username ${USERNAME}

Enter Password
[Arguments] ${PASSWORD}
TypeText Password ${PASSWORD}

Click Button
[Arguments] ${BUTTON_NAME}
ClickText ${BUTTON_NAME}
Choose Product
[Arguments] ${PRODUCT}
ClickText ${PRODUCT}

Add to Cart
ClickElement ${ADD TO CART}

Open Cart
ClickElement ${CART PATH}

Verify Item in Cart
[Arguments] ${ITEM NAME}
VerifyText ${ITEM NAME}

Enter First Name
[Arguments] ${FIRST NAME}
TypeText First Name ${FIRST NAME}

Enter Last Name
[Arguments] ${LAST NAME}
TypeText Last Name ${LAST NAME}

Enter Postal Code
[Arguments] ${POSTAL}
TypeText Zip/Postal Code ${POSTAL}

Verify Total
${ITEM TOTAL} GetText ${SUBTOTAL PATH} from_end=5 float=True
${ITEM TAX} GetText ${TAX PATH} from_end=4 float=True
${TOTAL} GetText ${TOTAL PATH} from_end=5 float=True
${TOTAL} = Evaluate ${ITEM TOTAL} + ${ITEM TAX}

Verify Checkout Complete
VerifyText THANK YOU FOR YOUR ORDER
sauce-demo.robot
*** Settings ***
Resource resource.resource
Suite Setup Test Suite Setup
Suite Teardown CloseAllBrowsers

*** Test cases ***
Make sure we're on the right page
Verify Correct Site

Perform Login
Enter Username standard_user
Enter Password secret_sauce
Click Button LOGIN

Add Product to Cart
Choose Product Sauce Labs Bolt T-Shirt
Add to Cart

Check Cart
Open Cart
Verify Item in Cart Sauce Labs Bolt T-Shirt

Enter Information at Checkout
Click Button CHECKOUT
Enter First Name Bob
Enter Last Name Botter
Enter Postal Code 53125
Click Button CONTINUE

Check Total
Verify Total

Finish Checkout
Click Button FINISH
Verify Checkout Complete