Robot framework 을 사용한 web page 테스트
Prerequired
- 관련 파이썬 라이브러리 설치
# pip install --upgrade robotframework
# pip install --upgrade robotframework-selenium2library
- selenium 을 통해 webdriver 를 호출하기 위한 브라우저 모듈 설치
- chrome 링크 에서 다운로드
- unzip
- mv chromedriver %PATH
Robot test 실행
$ python -m robot.run {{실행파일}}
- 실행 결과 를 xml 파일로 남긴다
- output.xml
- log.html
- report.html
- 예시
MrSense:input mr.sense$ python -m robot.run input.robot
==============================================================================
Input
==============================================================================
Basic Test | PASS |
------------------------------------------------------------------------------
Input | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed
==============================================================================
Output: /Users/mr.sense/Dev/robotframework/sample.code/robotframework/input/output.xml
Log: /Users/mr.sense/Dev/robotframework/sample.code/robotframework/input/log.html
Report: /Users/mr.sense/Dev/robotframework/sample.code/robotframework/input/report.html
Input Tag 관련 테스트 파일
*** Settings ***
Library Selenium2Library
*** Test Cases ***
Basic Test
Open Html
Insert Text To Input Field
Insert File To Input Field
Click The button
*** Keywords ***
Open Html
Open Browser http://localhost:8000/input.html browser=chrome
Maximize Browser Window
Insert Text To Input Field
Input Text input-text hello world
Insert File To Input Field
Choose File input-file /Users/mr.sense/Dev/input.html
Click The button
Click Element input-button
Click Event 관련 테스트 파일
*** Settings ***
Library Selenium2Library
*** Test Cases ***
Basic Test
Open Html
Click The button
Click The Selectbox
Click The link
*** Keywords ***
Open Html
Open Browser http://localhost:8000/click.html browser=chrome
Maximize Browser Window
Click The button
Click Element btn-click
Click The Selectbox
Select From List by Value xpath=//select[@id="select-click"] third
Element Should Contain select-click third
Click The link
Click Link /a.html
Wait Until Page Contains HIHIHI 2s
Table 관련 테스트 파일 (id 없는 element 다루기)
*** Settings ***
Library Selenium2Library
*** Test Cases ***
Basic Test
Open Html
Get Table Row Count
Get Table Td text
*** Keywords ***
Open Html
Open Browser http://localhost:8000/table.html browser=chrome
Maximize Browser Window
Get Table Row Count
Assign Id To Element xpath=//table[@class="xtable"] my_table
${rowCount}= Get Matching Xpath Count .//table[@id="my_table"]/tbody/tr
shouldBeEqualAsIntegers 3 ${rowCount}
Get Table Td text
Assign Id To Element xpath=//table[@class="xtable"] my_table
${cellValue}= Get Table Cell my_table 2 2
shouldBeEqual 19 ${cellValue}
Prerequired
- 관련 파이썬 라이브러리 설치
# pip install --upgrade robotframework # pip install --upgrade robotframework-selenium2library
- selenium 을 통해 webdriver 를 호출하기 위한 브라우저 모듈 설치
- chrome 링크 에서 다운로드
- unzip
- mv chromedriver %PATH
Robot test 실행
$ python -m robot.run {{실행파일}}
- 실행 결과 를 xml 파일로 남긴다
- output.xml
- log.html
- report.html
- 예시
MrSense:input mr.sense$ python -m robot.run input.robot ============================================================================== Input ============================================================================== Basic Test | PASS | ------------------------------------------------------------------------------ Input | PASS | 1 critical test, 1 passed, 0 failed 1 test total, 1 passed, 0 failed ============================================================================== Output: /Users/mr.sense/Dev/robotframework/sample.code/robotframework/input/output.xml Log: /Users/mr.sense/Dev/robotframework/sample.code/robotframework/input/log.html Report: /Users/mr.sense/Dev/robotframework/sample.code/robotframework/input/report.html
Input Tag 관련 테스트 파일
*** Settings ***
Library Selenium2Library
*** Test Cases ***
Basic Test
Open Html
Insert Text To Input Field
Insert File To Input Field
Click The button
*** Keywords ***
Open Html
Open Browser http://localhost:8000/input.html browser=chrome
Maximize Browser Window
Insert Text To Input Field
Input Text input-text hello world
Insert File To Input Field
Choose File input-file /Users/mr.sense/Dev/input.html
Click The button
Click Element input-button
Click Event 관련 테스트 파일
*** Settings ***
Library Selenium2Library
*** Test Cases ***
Basic Test
Open Html
Click The button
Click The Selectbox
Click The link
*** Keywords ***
Open Html
Open Browser http://localhost:8000/click.html browser=chrome
Maximize Browser Window
Click The button
Click Element btn-click
Click The Selectbox
Select From List by Value xpath=//select[@id="select-click"] third
Element Should Contain select-click third
Click The link
Click Link /a.html
Wait Until Page Contains HIHIHI 2s
Table 관련 테스트 파일 (id 없는 element 다루기)
*** Settings ***
Library Selenium2Library
*** Test Cases ***
Basic Test
Open Html
Get Table Row Count
Get Table Td text
*** Keywords ***
Open Html
Open Browser http://localhost:8000/table.html browser=chrome
Maximize Browser Window
Get Table Row Count
Assign Id To Element xpath=//table[@class="xtable"] my_table
${rowCount}= Get Matching Xpath Count .//table[@id="my_table"]/tbody/tr
shouldBeEqualAsIntegers 3 ${rowCount}
Get Table Td text
Assign Id To Element xpath=//table[@class="xtable"] my_table
${cellValue}= Get Table Cell my_table 2 2
shouldBeEqual 19 ${cellValue}
'개발 > python' 카테고리의 다른 글
Django + Apache 연동하기 (0) | 2019.02.27 |
---|---|
headlness chrome 를 활용한 robotframework 사용하기 (0) | 2018.11.01 |
Robot framework + Seleium -- (1) (0) | 2018.09.09 |
python - opencv 를 이용한 이미지 처리 (0) | 2018.08.25 |
Python multiprocess vs multithread (0) | 2018.05.24 |