我想自动化两个测试用例:
1)登录系统
Valid Login
Given browser is opened to login page
When user "demo" logs in with password "mode"
Then welcome page should be open
2)登录后执行任何操作
Change first name
[Setup] Log in
Given user is on account page
When user edits first-name field
Then new first name is displayed in first-name field
*** Keywords ***
Log in
Open browser to login page
Log in with username "demo" and password "mode"
Verify that welcome page is opened
对于第二个,我必须编写一个完全重复第一个测试用例步骤的关键字。
这在测试中发生了很多,所以我最终在我的项目中重复了两次重复步骤。是否有一个巧妙的技巧来避免这种代码重复,同时保持顶级测试用例看起来像Gherkin?
此问题是否有最佳做法?
答案 0 :(得分:0)
我将Gherkin风格的登录步骤移动到关键字,并编写了Valid Login
测试用例,但没有做任何事情。
让Test Setup
为你调用它或者在测试中明确地写它是我的首选。
一个很好的资源:How to write good test cases using Robot Framework
*** Settings ***
Test Setup Log in
*** Test Cases ***
Valid Login
No Operation
Change first name
Given user is on account page
When user edits first-name field
Then new first name is displayed in first-name field
*** Keywords ***
Log in
Given browser is opened to login page
When user "demo" logs in with password "mode"
Then welcome page should be open