Page History
Table of Contents |
---|
Overview
Robot Framework is a tool used by teams adopting ATDD(Acceptance Test Driven Development).
Broadly speaking, it can be used to automate acceptance “test cases” (i.e. scripts) no matter the moment you decide to do so or the practices your team follows
Table of Contents |
---|
Overview
Robot Framework is a tool used by teams adopting ATDD(Acceptance Test Driven Development).Broadly speaking, it can be used to automate acceptance “test cases” (i.e. scripts) no matter the moment you decide to do so or the practices your team follows even though it's preferable to do it at start, involving the whole team in order to pursue shared understanding.
...
Code Block | ||||
---|---|---|---|---|
| ||||
*** Settings *** Documentation A test suite with a single test for valid login. ... ... This test has a workflow that is created using keywords in ... the imported resource file. Resource resource.robot *** Test Cases *** Valid Login [Tags] ROB-11 UI Open Browser To Login Page Input Username demo Input Password mode Submit Credentials Welcome Page Should Be Open [Teardown] Close Browser |
...
Code Block | ||||
---|---|---|---|---|
| ||||
*** Settings *** Library SeleniumLibrary plugins=${CURDIR}/MyPlugin.py Library Collections Suite Setup Open browser ${URL} ${BROWSER} Suite Teardown Close All Browsers *** Variables *** ${URL} http://blazedemo.com/ ${BROWSER} Chrome @{allowed_destinations} Buenos Aires Rome London Berlin New York Dublin Cairo *** Test Cases *** The search page presents valid options for searching [Tags] 1 Go To ${URL} Title Should Be BlazeDemo Element Should Be Visible css:input[type='submit'] Wait Until Element Is Enabled css:input[type='submit'] Wait Until Element Is Clickable input[type='submit'] ${values}= Get List Items xpath://select[@name='fromPort'] values=True Log ${values} ${allowed_departures}= Create List Paris Philadelphia Boston Portland San Diego Mexico City São Paolo Lists Should Be Equal ${allowed_departures} ${values} ${values}= Get List Items xpath://select[@name='toPort'] values=True Log ${values} Should Be Equal ${allowed_destinations} ${values} The user can search for flights The user can search for flights [Tags] search_flights Go to ${URL} Select From List By Value xpath://select[@name='fromPort'] Paris [Tags]Select From List by Value xpath://select[@name='toPort'] search_flightsLondon GoClick toButton ${URL}css:input[type='submit'] Select@{flights}= From ListGet ByWebElements Value xpathcss://selecttable[@nameclass='fromPorttable']>tbody tr Paris Should SelectNot FromBe ListEmpty by Value xpath://select[@name='toPort'] London Click Button css:input[type='submit'] @{flights}= Get WebElements css:table[class='table']>tbody tr Should Not Be Empty ${flights}${flights} |
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
from robot.api import logger
from SeleniumLibrary.base import LibraryComponent, keyword
from SeleniumLibrary.locators import ElementFinder
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support.expected_conditions import presence_of_element_located
from selenium.webdriver.support.expected_conditions import element_to_be_clickable
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
class MyPlugin(LibraryComponent):
def __init__(self, ctx):
LibraryComponent.__init__(self, ctx)
@keyword
def wait_until_element_is_clickable(self, selector):
"""Adding new keyword: Wait Until Element Is Clickable.""" | ||||||
Code Block | ||||||
| ||||||
from robot.api import logger from SeleniumLibrary.base import LibraryComponent, keyword from SeleniumLibrary.locators import ElementFinder from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support.expected_conditions import presence_of_element_located from selenium.webdriver.support.expected_conditions import element_to_be_clickable from selenium.webdriver.common.keys import Keys from selenium.webdriver.common.by import By class MyPlugin(LibraryComponent): def __init__(self, ctx): LibraryComponent.__init__(self, ctx) self.info('Wait Until Element Is Clickable') @keyword def wait_until_element_is_clickable(self, selector):wait = WebDriverWait(self.driver, 10) """Adding new keyword: Wait Until Element Is Clickable."""my_elem = self.element_finder.find("css:"+selector) self.info('Wait Until Element Is Clickable')print(my_elem) waitfirst_result = WebDriverWait(self.driver, 10) wait.until(element_to_be_clickable((By.CSS_SELECTOR, selector))) return my_elem = self.element_finder.find("css:"+selector) print(my_elem) first_result = wait.until(element_to_be_clickable((By.CSS_SELECTOR, selector))) return first_result |
Running the tests in parallel is possible using pabot.
Tests can be parallelized in different ways; we'll split them for running on a test basis.
We can also specify some variables; in this case, we'll use it to specify the "BROWSER" variable which is passed to the SeleniumLibrary.
Code Block | ||||
---|---|---|---|---|
| ||||
--variable BROWSER:Chrome |
No Format |
---|
pabot --argumentfile1 ffbrowser.txt --argumentfile2 chromebrowser.txt --argumentfile3 headlessffbrowser.txt --argumentfile4 safaribrowser.txt --testlevelsplit 0_basic/search_flights.robot |
Running these tests will produce a report per each "argumentfileX" parameter (i.e. per each browser). We can then submit those to Xray (e.g. using "curl" and the REST API), and assign it to distinct Test Executions where each one is in turn assigned to a specific Test Environment identifying the browser.
first_result
|
Running the tests in parallel is possible using pabot.
Tests can be parallelized in different ways; we'll split them for running on a test basis.
We can also specify some variables; in this case, we'll use it to specify the "BROWSER" variable which is passed to the SeleniumLibrary.
Code Block | ||||
---|---|---|---|---|
| ||||
--variable BROWSER:Chrome |
No Format |
---|
pabot --argumentfile1 ffbrowser.txt --argumentfile2 chromebrowser.txt --argumentfile3 headlessffbrowser.txt --argumentfile4 safaribrowser.txt --testlevelsplit 0_basic/search_flights.robot |
Running these tests will produce a report per each "argumentfileX" parameter (i.e. per each browser). We can then submit those to Xray (e.g. using "curl" and the REST API), and assign it to distinct Test Executions where each one is in turn assigned to a specific Test Environment identifying the browser.
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
#!/bin/bash
BROWSERS=(firefox chrome headlessff safari)
PROJECT=CALC
TESTPLAN=CALC-6424
i=1
for browser in ${BROWSERS[@]}; do
curl -H "Content-Type: multipart/form-data" -u admin:admin -F "file=@pabot_results/output$i.xml" "http://192.168.56.102/rest/raven/1.0/import/execution/robot?projectKey=$PROJECT&testPlanKey=$TESTPLAN&testEnvironments=$browser"
i=$((i+1))
done |
In Xray, at the Test Plan-level we can see the consolidated results and for each test case we may drill-down and see all the runs performed and in which enviroment/browser.
In this case, we have the total of 4 Test Executions (i.e. for safari, headlessff, chrome, firefox).
...
Tracking automation results
...