我读到您可以使用pipe-separated格式进行Robot Framework测试,但在我的代码中:
*** Settings ***
| Documentation | A test suite with a single test for valid login.
| Library | Selenium2Library
| Resource | AdminResource.txt
*** Variables ***
| ${LOGIN URL} | http://local.econnect-admin.com/
| ${BROWSER} | ff
| ${Login button} | xpath=//body/div[2]/div/div[2]/div[2]/div/form/fieldset/div[3]/button
*** Test Cases ***
| Valid Login
|| Open Browser To Login Page
|| Input Text | a11y-username | username
|| Input Text | a11y-password | password
|| Click Log in
|| Welcome Page Should Be Open
*** Keywords ***
| Open Browser To Login Page
|| Open Browser | ${LOGIN URL} | ${BROWSER}
|| Maximize Browser Window
|| Wait Until Page Contains Element | ${Login button} | 5s
| Click Log in
|| Click Element | ${Login button}
| Welcome Page Should Be Open
|| Location Should Be | ${LOGIN URL}
|| Wait Until Page Contains | Accounts | 5s
|| Page Should Contain | Accounts
运行时,代码会出现各种错误:
[ ERROR ] Error in file 'C:\Python\AdminTests\test.txt': Setting variable '|${LOGIN URL} | http://local.econnect-admin.com/' failed: Invalid variable name '|${LOGIN URL} | http://local.econnect-admin.com/'.
[ ERROR ] Error in file 'C:\Python\AdminTests\test.txt': Setting variable '|${BROWSER} | ff' failed: Invalid variable name '|${BROWSER} | ff'.
[ ERROR ] Error in file 'C:\Python\AdminTests\test.txt': Setting variable '|${Login button} | xpath=//body/div[2]/div/div[2]/div[2]/div/form/fieldset/div[3]/button' failed: Invalid variable name '|${Login button} | xpath=//body/div[2]/div/div[2]/div[2]/div/form/fieldset/div[3]/button'.
它还告诉我,我的测试用例的每一行(包括测试用例的名称)都包含在关键字中。
我是否错误地格式化了我的测试脚本,还是我对管道分隔格式错误?
编辑 - 在另一个question中,使用此格式给出答案
提前致谢。
答案 0 :(得分:0)
管道之间必须有空格。考虑这一行:
|| Open Browser | ${LOGIN URL} | ${BROWSER}
您需要将其更改为:
| | Open Browser | ${LOGIN URL} | ${BROWSER}
来自用户指南:
管道和空格分隔线由强制性引导线识别 管道,但该行末端的管道是可选的。必有 管道两侧至少有一个空间(除了 开始和结束)但没有必要对齐管道以外的管道 如果它使数据更清晰。