[SCK SEAL Diary] Day 26 Give & Take Robotframework 101

Today, we’re not in SCK Dojo. SCK & SCK SEAL Team have a mission at TDEM (Toyota Daihatsu Engineering & Manufacturing co. ltd) to teach Robotframework class.

Today our attendee is 50 peoples!! but our staff have only 8 people (2 instructor and 6 assistant)

Robotframework is a tools for acceptance testing, It have a lot of librarys to use but today, we will focus in SeleniumLibrary

NOTE: if you confuse about between SeleniumLibrary and Selenium2Library which one is newer version. please use SeleniumLibrary because Selenium2Library now migrate and rename itself to be ‘SeleniumLibrary’

Today, Feature that the most important for every systems have to implemented, we will test it is “Login Feature”. you can clone/download this repo to do

Grade 1: Basic 101

we will start will simple and easy, in every robot file 4 part that be default is

  • Settings — for import libraries and files
  • Variables — define variables for use in this test case
  • Testcases — write down your test step to do acceptance test using keywords
  • Keywords — you can define own keywords for make testcases easy to read

If you cannot remember all keywords, you can find everything in seleniumlibrary document

// filename: login_p1.robot (p1 means grade 1 of school)
*** Settings ***
Library SeleniumLibrary
*** Variables ***
*** Testcases ***
Login Success
Open Browser http://localhost:7272/html chrome
Input Text username_field prathan
Input Text password_field sckshuhari
Click Button login_button
Wait Until Page Contains Welcome
Close Browser
Login Unsuccess with wrong username but correct password
[Documentation] ใส่ชื่อผู้ใช้ผิด
Open Browser http://localhost:7272/html chrome
Input Text username_field thawatchai
Input Text password_field sckshuhari
Click Button login_button
Wait Until Page Contains Error
Close Browser
*** Keywords ***

Grade 2: Remove duplicate

we can use variables to remove duplicated values and define own keywords that can pass variable to remove duplicated keywords

// filename: login_p2.robot 
*** Settings ***
Library SeleniumLibrary
Suite Setup Open Browser ${LOCAL_URL} ${BROWSER}
Test Setup Go To ${LOCAL_URL}
Suite Teardown Close Browser
*** Variables ***
${LOCAL_URL} http://localhost:7272/html
${BROWSER} chrome
*** Testcases ***
Login Success
กรอกข้อมูลในการ Login prathan sckshuhari
กดปุ่มเพื่อดำเนินการ Login
ตรวจสอบผลการ Login Welcome Page
Login Unsuccess with wrong username but correct password
[Documentation] ใส่ชื่อผู้ใช้ผิด
กรอกข้อมูลในการ Login thawatchai sckshuhari
กดปุ่มเพื่อดำเนินการ Login
ตรวจสอบผลการ Login Error Page
Login Unsuccess with correct username but wrong password
[Documentation] ใส่ชื่อผู้ใช้ผิด
กรอกข้อมูลในการ Login prathan sckshuharI
กดปุ่มเพื่อดำเนินการ Login
ตรวจสอบผลการ Login Error Page
*** Keywords ***
กรอกข้อมูลในการ Login
[Arguments] ${USERNAME} ${PASSWORD}
Input Text username_field ${USERNAME}
Input Text password_field ${PASSWORD}
กดปุ่มเพื่อดำเนินการ Login
Click Button login_button
ตรวจสอบผลการ Login
[Arguments] ${MESSAGE}
Wait Until Page Contains ${MESSAGE}

Grade 3: Use Test template

We can use Test Template for make test cases easier to read

// filename: login_p3.robot
*** Settings ***
Library SeleniumLibrary
Suite Setup Open Browser ${LOCAL_URL} ${BROWSER}
Test Setup Go To ${LOCAL_URL}
Suite Teardown Close Browser
Test Template Login Steps
*** Variables ***
${LOCAL_URL} http://localhost:7272/html
${BROWSER} chrome
*** Testcases ***
Login Success prathan sckshuhari Welcome Page
Login Unsuccess with wrong username but correct password thawatchai sckshuhari
Error Page Login Unsuccess with correct username but wrong password prathan sckshuharI Error Page
*** Keywords ***
Login Steps
[Arguments] ${USERNAME} ${PASSWORD} ${MESSAGE}
กรอกข้อมูลในการ Login ${USERNAME} ${PASSWORD}
กดปุ่มเพื่อดำเนินการ Login
ตรวจสอบผลการ Login ${MESSAGE}
กรอกข้อมูลในการ Login
[Arguments] ${USERNAME} ${PASSWORD}
Input Text username_field ${USERNAME}
Input Text password_field ${PASSWORD}
กดปุ่มเพื่อดำเนินการ Login
Click Button login_button
ตรวจสอบผลการ Login
[Arguments] ${MESSAGE}
Wait Until Page Contains ${MESSAGE}

when use this method it will see this file have only one test case but have multiple data, you have to choose which method do you use

// filename: login_p4.robot
*** Settings ***
Library SeleniumLibrary
Suite Setup Open Browser ${LOCAL_URL} ${BROWSER}
Suite Teardown Close Browser
*** Variables ***
${LOCAL_URL} http://localhost:7272/html
${BROWSER} chrome
*** Testcases ***
Login All
[Template] Login Steps
prathan sckshuhari Welcome Page
thawatchai sckshuhari Error Page
prathan sckshuharI Error Page
*** Keywords ***
Login Steps
[Arguments] ${USERNAME} ${PASSWORD} ${MESSAGE}
Go To ${LOCAL_URL}
กรอกข้อมูลในการ Login ${USERNAME} ${PASSWORD}
กดปุ่มเพื่อดำเนินการ Login
ตรวจสอบผลการ Login ${MESSAGE}
กรอกข้อมูลในการ Login
[Arguments] ${USERNAME} ${PASSWORD}
Input Text username_field ${USERNAME}
Input Text password_field ${PASSWORD}
กดปุ่มเพื่อดำเนินการ Login
Click Button login_button
ตรวจสอบผลการ Login
[Arguments] ${MESSAGE}
Wait Until Page Contains ${MESSAGE}

Grade 6: Use Resource for hiding technical keywords

You can separate test cases and keywords for make it easy to read not only for developer or tester but everyone can read this acceptance test

// filename: login_p6.robot
*** Settings ***
Library SeleniumLibrary
Suite Setup Open Browser ${LOCAL_URL} ${BROWSER}
Test Setup Go To ${LOCAL_URL}
Suite Teardown Close Browser
Test Template Login Steps
Resource resource_p.robot
*** Testcases ***
Login Success prathan sckshuhari Welcome Page
Login Unsuccess with wrong username but correct password thawatchai sckshuhari Error Page
Login Unsuccess with correct username but wrong password prathan sckshuharI Error Page
// filename: resource_p.robot
*** Keywords ***
Login Steps [Arguments] ${USERNAME} ${PASSWORD} ${MESSAGE} กรอกข้อมูลในการ Login ${USERNAME} ${PASSWORD} กดปุ่มเพื่อดำเนินการ Login ตรวจสอบผลการ Login ${MESSAGE} กรอกข้อมูลในการ Login [Arguments] ${USERNAME} ${PASSWORD} Input Text username_field ${USERNAME} Input Text password_field ${PASSWORD} กดปุ่มเพื่อดำเนินการ Login Click Button login_button ตรวจสอบผลการ Login [Arguments] ${MESSAGE} Wait Until Page Contains ${MESSAGE}

“writing acceptance test with robotframework” it’s not hard, everyone can do but the hardest things is if we use it that mean we have more code to maintain. things to do is educate development team to do this, not just assign someone to do it because when they quit, who will maintain ?

writing acceptance test is not tester’s duty but it should be everyone in development team’s duty

choose Right Tools to do Right Work, don’t stick with the tools.

see you soon….

Full-Stacked Developer. Let’s share to the world :)