ALL CHANGES SHOUD BE TESTED また忘れたので、しばらく一番トップに
Learning Robot Framework : Data Driven Testing
Read Data from Excel (openpyxl)
import openpyxl workbook = openpyxl.load_workbook("./TestKeyword.xlsx") def fetch_number_of_rows(sheetname): sheet = workbook[sheetname] return sheet.max_row def fetch_cell_data(sheetname, rownum, cellnum): sheet = workbook[sheetname] cell = sheet.cell(rownum, cellnum) return cell.value print(fetch_number_of_rows("Sheet1")) print(fetch_cell_data("Sheet1", 1, 2))
Excel
Create User Defined Keywords
Run loop and Read data from keywords
${row} = Read Number of Rows Sheet1 FOR ${i} IN RANGE 1 ${row}+1 Log ${i} ${searchkeyword}= Read Excel Data of Cell Sheet1 ${i} 1 Log To Console ${searchkeyword} END
Learning Robot Framework : Test Case Recording
Install chrome plugin : robot corder
It seems similar with Selenium IDE.
Behavior check
Record
============================================================================== Testcases ============================================================================== Testcases.Test Script :: A test suite with a single test for 【楽天市場】ho... ============================================================================== 【楽天市場】hogehogeの通販 - デイリーランキング入賞商品一覧 test | PASS | ------------------------------------------------------------------------------ Testcases.Test Script :: A test suite with a single test for 【楽... | PASS | 1 test, 1 passed, 0 failed ============================================================================== Testcases | PASS | 1 test, 1 passed, 0 failed ============================================================================== Output: /Users/woohyeok.kim/Desktop/study/robotframework-basic/output.xml Log: /Users/woohyeok.kim/Desktop/study/robotframework-basic/log.html Report: /Users/woohyeok.kim/Desktop/study/robotframework-basic/report.html
Learning Robot Framework : Write Test in BDD Format
Given-When-Then
Given : Prerequisite When : Check this part Then : Confirm the result
Learning Robot Framework : Work on Excel File
Prerequisite
pip install openpyxl
How to use the lib
import openpyxl # Load workbook workbook = openpyxl.load_workbook("testdata.xlsx") print(workbook.sheetnames) print("Active sheet= " + workbook.active.title) sheet = workbook['Sheet1'] print(sheet.title)
Basically able to fetch any value
sheet = workbook['Sheet2'] print(sheet.title) print(sheet["A1"].value) cell = sheet.cell(1, 1) print(cell.value) print(cell.row) print(cell.column)
Fetch ALL data
rows = sheet.max_row columns = sheet.max_column print(rows) print(columns) # Way1 for i in range(1, rows + 1): for j in range(1, columns + 1): c = sheet.cell(i, j) print(c.value) # Way2 for row in sheet["A1":"B3"]: for cell in row: print(cell.value)
Write & Remove Data
import openpyxl # 여기는 load_workbook이 아니네? workbook = openpyxl.Workbook() print(workbook.active.title) sheet = workbook.active sheet.title = "Hello World" print(sheet.title) workbook.create_sheet(title="NewSheet") newSheet = workbook["NewSheet"] newSheet['A1'].value = "test value" sheet['A3'].value = "testuser3" # Remove sheet workbook.remove(newSheet) # Saving workbook.save("testdata.xlsx")
Learning Robot Framework : User Defined Keywords with Python
Without argument and return value
Flow to load
Robot file -> Resource File -> Python Script
python
import os def create_folder() : os.mkdir("test") print(str(os.path)) def create_sub_folder() : os.mkdir("test/test_sub")
Resource file
Create Directory at Runtime create_folder create_sub_folder Log To Console "Successful!!"
Robot file
Runtime Test Create Directory at Runtime
With argument and return value
Learning Robot Framework : Tags and Control Execution using Tags
Tags
Tags at test case level
Second Tag Test [Tags] Smoke Sanity Setup Tests Teardown Tests
->
Able to run tests filtering with the tags.
robot -i {tagname} {testsuite}
Default Tags
*** Settings *** Library SeleniumLibrary Default Tags DEFAULT // here
Forced Tags
Apply to all test cases
*** Settings *** Library SeleniumLibrary Default Tags DEFAULT Force Tags FORCED_TESTS // here
Execute with tags
- -i (include) {tagname}AND/OR/NOT{tagname}
- -e (exclude)
- -t particular test case
- -s particular test suite
Set Output Directory
robot -r reports/report.html -o reports/output.xml -l reports/log.html testcases/tags/tagtests.robot
then you can see like this
============================================================================== Tagtests ============================================================================== First Tag Test | PASS | ------------------------------------------------------------------------------ Second Tag Test | PASS | ------------------------------------------------------------------------------ Default Tag Test | PASS | ------------------------------------------------------------------------------ Tagtests | PASS | 3 tests, 3 passed, 0 failed ============================================================================== Output: /Users/woohyeok.kim/Desktop/study/robotframework-basic/reports/output.xml Log: /Users/woohyeok.kim/Desktop/study/robotframework-basic/reports/log.html Report: /Users/woohyeok.kim/Desktop/study/robotframework-basic/reports/report.html