我想在多数"优雅"中传递多个参数给我的TEST CASE。在Robot Framework中可行的方式。许多框架中使用的场景大纲允许使用表中的值替换变量/关键字。表中的每一行都被视为一个场景。
Robot Framework中的场景大纲是否有任何等效内容?
例如,我们有这样的测试用例:
Given users email is ${email}
And users password is ${password}
When user is on login page
Then user can sign in
我们希望将多个电子邮件和密码作为数组传递给此测试用例,并且运行的次数与此数组中的行数一样多。如果不将测试用例转换为关键字以使用模板,我可以这样做吗?
答案 0 :(得分:2)
您无法将BDD式测试与数据驱动测试混合在一起。您最接近的可能是在BDD样式中编写关键字,然后在实际测试用例中使用该关键字。
例如,您可以执行以下操作:
*** Keywords ***
users email is
[Arguments] ${email}
set test variable ${current email} ${email}
users password is
[Arguments] ${password}
set test variable ${current password} ${password}
User is on login page
log pretend we are on the login page
User can sign in
should contain ${current password} !
... password for ${current email} doesn't contain '!' (${current password})
... values=False
User login template
[Arguments] ${email} ${password}
Given users email is ${email}
And users password is ${password}
When user is on login page
Then user can sign in
*** Test Cases ***
Scenario: user can sign in with valid credentials
[Template] User login template
# username # password
larry@example.com heymo!
moe@example.com wiseguy!
curly@example.com nyuknyuk!
答案 1 :(得分:0)
关于在Robot Framework中使用像Gherkin这样的数据表(这是一种优雅的解决方法),请参阅此优秀blog。
这是示例代码:
*** Settings ***
Force Tags OnlyThisOne
Resource BDD.robot
*** Test Case *** \ Closed Period Open Period Run Import On Old Manager Stops New Manager Starts
1 Example 1.11.2009 - 30.11.2009 1.12.2009 - 31.12.2009 11.11.2009 30.11.2009 1.12.2009
2 Example 1.11.2009 - 30.11.2009 1.12.2009 - 31.12.2009 1.11.2009 31.10.2009 1.11.2009
3 Example 1.11.2009 - 30.11.2009 1.12.2009 - 31.12.2009 1.12.2009 30.11.2009 1.12.2009
*** Keyword ***
Example
[Arguments] ${periodClosed} ${periodOpenAndModified} ${importDay} ${oldManagerValidUntil} ${newManagerValidFrom}
Given initialized criteria for bonus commercial
And a branch B with branch manager M_OLD and employee E1
And evaluation for E1 for period ${periodClosed} which is closed
And evaluation for E1 for period ${periodOpenAndModified} which is open and modified
When M_NEW becomes new manager of branch B
And import service is called on ${importDay}
Then the new branch manager of branch B is M_NEW valid from ${newManagerValidFrom}
And branch manager M_OLD manages employee E until ${oldManagerValidUntil}
And branch manager M_NEW manages employee E from ${newManagerValidFrom}
And Evaluations for E1 still have the same content
Given initialized criteria for bonus commercial
But M_NEW becomes new manager of branch B
But import service is called on ${importDay}
And M_OLD becomes new manager of branch C

BDD.robot
资源文件:
*** Settings ***
Documentation Library de.codecentric.fourtexx.robot.ModelKeyword
#*** Test Cases ***
#Branch, Manager and Worker
# Given a branch A with branch manager Boss and employee Worker
*** Keywords ***
the new branch manager of branch ${branch} is ${manager} valid from ${newManagerValidFrom}
assert branch manager valid from ${branch} ${manager} ${newManagerValidFrom}
initialized criteria for bonus commercial
No Operation
a branch ${branch} with branch manager ${manager} and employee ${employee}
No Operation
evaluation for ${employee} for period ${periodClosed} which is closed
No Operation
evaluation for ${employee} for period ${periodOpenAndModified} which is open and modified
No Operation
${manager} becomes new manager of branch ${branch}
No Operation
import service is called on ${importDay}
No Operation
branch manager ${manager} manages employee ${employee} until ${oldManagerValidUntil}
No Operation
branch manager ${manager} manages employee ${employee} from ${newManagerValidFrom}
No Operation
Evaluations for ${employee} still have the same content
No Operation
assert branch manager valid from
[Arguments] ${arg1} ${arg2} ${arg3}
Evaluate True

答案 2 :(得分:0)
*** Test Cases ***
Scenario: eating cucumbers
[Template] Scenario Outline: eating cucumbers
# Examples:
# start eat left
12 5 7
20 5 15
33 11 22
35 15 20
*** Keywords ***
Scenario Outline: eating cucumbers
[Arguments] ${start} ${eat} ${left}
Given there are ${start} cucumbers
When I eat ${eat} cucumbers
Then I should have ${left} cucumbers
字体:https://gist.github.com/Tset-Noitamotua/8f06bd490918a56b0485630016aef60b