使用关键字构件业务流程
关键字驱动设计,带来的好处是分析师和开发人员可以同时参与到用例的设计中,robotframework在testcases中可以实现业务流程,复用keywords,支持异常处理,除了用在ATDD、BDD等测试场景中,在开发驱动设计和业务流程实现方面有较好的实现效果。
#!/usr/bin/env robot
*** Settings ***
Library Browser
Suite Setup New Browser browser=${BROWSER} headless=${HEADLESS}
Test Setup New Context
Test Teardown Close Context
Suite Teardown Close Browser
*** Variables ***
${BROWSER} firefox
${HEADLESS} False
*** Test Cases ***
Login And Check Device
Login Jetlinks
Check Status
Change Value Once
*** Keywords ***
Login Jetlinks
Set Browser Timeout 60s
New Page https://www.smallworkshop.com/#/user/login wait_until=networkidle
${current_url}= Get Url
${is_login_page}= Evaluate "/user/login" in """${current_url}"""
IF ${is_login_page}
Fill Text id=form_item_username admin
Fill Text id=form_item_password admin
Click id=form_item_verifyCode
${promise}= Promise To Wait For Function element => element.value.length === 4 selector=id=form_item_verifyCode
Wait For ${promise}
Click "登录"
Sleep 2s
END
Check Status
Wait For Elements State text="后台管理平台" visible timeout=30s
Click "后台管理平台"
Wait For Elements State text="人员管理" visible timeout=30s
Click "人员管理"
Wait For Elements State text="角色" visible timeout=30s
Click "角色"
Wait For Elements State text="角色名称" visible timeout=30s
Click "角色名称"
Wait For Elements State .ant-select-item:has-text("ID") visible timeout=10s
Click .ant-select-item:has-text("ID")
Fill Text css=.ant-input 厨师
Click css=button[type=submit]
Wait For Load State networkidle timeout=30s
Click "饭店01"
Wait For Load State networkidle timeout=30s
Click "开业状态"
Wait For Load State networkidle timeout=30s
Change Value Once
Click button.ant-btn.ant-btn-link.custom-button>>nth=0
Sleep 10s