# Robot Frame Work Learning ## Install Path 1. Install **Python** 2. Install **Pycharm** 3. Pip install **robotframework, robotframework-seleniumlibrary, selenium** 4. Install **Chrome** and **Selenuim Web Driver**. 5. Install **Geckodriver** ## How to run it **You need create virtual environment to set up python package.** ``` python3 -m venv . ``` ``` robot [arguments] [filename] ex: robot testcase.robot ``` ## Robotframework Doc ### 1. Introduction It is a Python-based, extensible keyword-driven automation framework. #### Robotframework architecture ![](https://i.imgur.com/h62jW1C.png) **Test Data** we write test code ``` *** Settings *** Library SeleniumLibrary *** Variables *** ${url} https://google.com *** Test Cases *** LoginTest Open Browser ${url} Click Link //*[@id="gbw"]/div/div/div[1]/div[1]/a Close Browser *** Keywords *** ``` **TestLibrary** ``` Library SeleniumLibrary ``` ### 2.Test Data section Different sections in data | Section | Used for | | -------- | -------- | | Settings | 1. Importing test libraries, resource files and variable files.</br>2. Defining metadata for test suites and test cases. | | Variables | Defining variables that can be used elsewhere in the test data. | | Test Cases | Creating test cases from available keywords. | | Tasks | Creating tasks using available keywords. Single file can only contain either tests or tasks. | | Keywords | Creating user keywords from existing lower-level keywords. | | Comments | Additional comments or data. Ignored by Robot Framework.| ### 3.Varible type | Character | Meaning | Examples | | -------- | -------- | -------- | | \$ | Normal Variable | ${greeting} 'Hello World' | | \@ | Array Variable | @{books} [The-Lord-Of-Ring, Harry-Potter] | | \& | Object Variable | &{User} name=hunter age=18 | | \% | Enviroment Variable | %{[env-varible]} | | \# | Comment | # This is comment | | \= | Equal sign | name=hunter | | \| | Pipe format | [Pipe format](http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pipe-separated-format) | ### 4. Divide Row If you want defined task or variable in multiple rows. you can use "**...**" Single line: ``` ${Book} This book is talk to you, how to let you be better everyday. ``` Multiple rows: ``` ${Book} This book ... is talk to you, ... how to let you be better everyday ``` ### 5. Test case syntax **Test cases are constructed in test case tables from the available keywords.** Keywords can imported 1. test libaries 2. resource files 3. keyword table **Test cases can also have their own settings.** | Type | Explain | | -------- | -------- | | [Documentation] | Used for specifying a test case documentation. | | [Tags] | Used for tagging test cases. | | [Setup], [Teardown] | Specify test setup and teardown. | | [Template] | Specifies the template keyword to use. The test itself will contain only data to use as arguments to that keyword.| | [Timeout] | Used for setting a test case timeout. Timeouts are discussed in their own section. | ### 6. Using arguments **Positional arguments** It is important to have exactly the same number of arguments. ex: Copy File [source] [path] Can't only give source or path it will error. **note: If you want use some keyword. You need import library first.** ``` *** Settings *** Library OperatingSystem *** Test Cases *** Example Create File ${TEMPDIR}/empty.txt Create File ${TEMPDIR}/utf-8.txt Hyvä esimerkki Create File ${TEMPDIR}/iso-8859-1.txt Hyvä esimerkki ISO-8859-1 ``` ### 7. Base Syntax [**Documentation**] Here can add description for testcase own. [**Tags**] | Type | Use For | | -------- | -------- | | Force Tag | Force append every test case. | | Default Tag | If the test case doesn't have any tag, it will append on. | [**Test Setup**] You can set up something before the test. [**Test Teardown**] You can execute someting after the test. **Note** : "Test Setup" and "Test Teardown" defined on "Setting section" ``` *** Settings *** Test Setup Open Application App A Test Teardown Close Application ``` [**Setup**] You can set up something before the test-case. [**Teardown**] You can execute someting after the test-case. **Note** : "Setup" and "Teardown" defined on "Test-case" ``` *** Test Cases *** [Documentation] Setup and teardown specified using variables [Setup] ${SETUP} Do Something [Teardown] ${TEARDOWN} ``` [**Print Variable**] Here has two method to show the message on console. 1.**Use Log:** ``` Log [message] or ${variable} console=true ``` 2.**Use Log to Console:** ``` Log to Console [mseeage] or ${variable} ``` ### 8.For Loop If you want to repeat actions, For loop will be a good idea **Note** : You can't use **${variable}** it will be considered to a single Object ``` *** Test Cases *** Verify Animal Exist FOR ${animal} IN @{Animal_List} ${animal} END ``` **Advance Usage** You can use it with template ``` *** Test Cases *** Check String Loop [template] Print List FOR ${item} IN @{Item_List} ${item} END *** Keywords *** Print List [arguments] ${str} Log ${str} console=true ```