botbotbot 's blog

Robot Framework

Robot Framework(RF) - Github Repo

Robot Framework Template

*** Settings ***
Documentation     <document>
Library           <Library>
Library           <python pakcage>  WITH NAME  <ref name>
Resource          <file>

Suite Setup       <keyword>
Suite Teardown    <keyword>

Test Setup        <keyword>
Test Teardown     <keyword>

*** Test Cases ***
<test name>
  <command> or <keyword>

*** Keywords ***
<command>
  [Arguments]  ${variable}
  ${variable} =  <command>  ${variable}
  [Return]  ${variable}

Handling whitespace - Plain text format

  • 1 tab = 2 space
  • 1 space - between command
  • 2+ space - between command and argument (recommend 4 space)

  • Newlines, carriage returns, and tabs are converted to spaces.

Special characters need Escaping special characters

  • Newlines - \n
  • carriage returns - \r
  • tabs - \t
  • non-breaking spaces - \xA0

Continue line the previous line

# use ellipsis (...) to continue the previous line
Default Tags	a	b	c
...	          d	e	f

Test templates - keyword-driven test cases into data-driven tests

RF file formats:

  • HTML format
  • TSV format
  • Plain text format
  • reStructuredText format

support only .html, .xhtml, .htm, .tsv, .txt, .rst, or .rest file in dir

Test case styles:

  • Keyword-driven style
  • Data-driven style
  • Behavior-driven style ( Give When Then )

RF Variable

  • scalars - ${SCALAR}
  • lists - @{LIST}
  • environment variables - %{VARIABLE}

  • all capital letters with global variables - ${VAR}
  • small letters with local variables - ${my_var}

Number variables

${THRESHOLD}      ${65}     # 65 is integer
${THRESHOLD}      ${67.25}  # 67.25 is float
${THRESHOLD}      65        # 65 is string

Boolean and None/null variables

${true}   - python True
${false}  - python False
${None}   - python None

Selecting test cases

--test example*       #select test
--suite example-??    #select suite

Tagging test cases

*** Settings ***
Force Tags FunctionalTest
Default Tags ValidTest

*** Test Cases ***
invalid login
  [Tags]  InvalidTest
# Tag select

$ pybot -i InvalidTest login_tests.txt
$ pybot --include InvalidTest login_tests.html

$ pybot -e InvalidTest login_tests.txt
$ pybot --exclude InvalidTest login_tests.html

Test suites

init.txt - init test suite file

Assgin Variable via CLI

$ pybot --variable USERNAME:botbot --variable PASSWORD:ibot login_tests.html
$ pybot  -d /tmp --variable SERVER:"192.168.59.103" --variable BROWSER:chrome tests/acceptance/

For loops - Tutorial

:FOR    ${elem}   IN    @{list}
\    LOG     ${elem}

Selenium Driver

$ brew install chromedriver # chrome driver for osx
$ brew install phantomjs # GUI less driver for osx
$ apt-get install phatomjs # GUI less driver for ubuntu

Plugin:

  1. Vim plugins for development with Robot framework
  2. Pabot - A parallel executor for Robot Framework tests

Documents:

  1. Robot Framework Quick Start Guide
  2. RobotFramework Overview
  3. Robot Framework User Guide
  4. HowToWriteGoodTestCases

Demo:

  1. RobotDemo - Python Calculator
  2. Acceptance Test Driven Development with Robot Framework
  3. Robot Framework Demo
  4. Using Robot + Selenium for automatic browser testing

References:

  1. Robot Framework Keywords
  2. Write testable documentation with Robot Framework
  3. how can I return results in Robot Framework keyword?
  4. Creating user keywords
  5. Getting started with Robot Framework and plone.app.testing
  6. RobotFramework with the Selenium Library - Part2
  7. Robot Framework Tutorial – Overview
  8. Rule, Workflow and Technical Activity on Code Reviews
  9. ATDD by Robot Framework#1 - ATH
  10. How to import python modules
  11. python ImportError No module named
  12. Robot Framework สร้าง Image เอาไว้ทดสอบระบบ web ด้วย Docker