2017-06-28 36 views
0

我想在Robot Framework中以最“优雅”的方式将多个参数传递给我的TEST CASE。在许多框架中使用的场景大纲允许用表中的值替换变量/关键字。表中的每一行都被认为是一个场景。机器人框架中带有小黄瓜的场景大纲

机器人框架中的场景大纲是否有任何等价物?

例如,我们有测试案例是这样的:

Given users email is ${email} 
And users password is ${password} 
When user is on login page 
Then user can sign in 

我们希望能够通过多封电子邮件和密码,这个测试案例,例如一个数组,因为有这个阵列中的行运行多次。我可以在不将测试用例转换为关键字的情况下使用模板吗?

+0

测试用例不带参数的。您能否更清楚地说明“将参数传递给我的测试用例”是什么意思?你在问如何使用[测试模板](http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#test-templates)? –

+0

我添加了一个我的意思的例子,我希望现在很清楚。 :) – Ewa

回答

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 
    [email protected] heymo! 
    [email protected]  wiseguy! 
    [email protected] nyuknyuk! 
+0

好吧,我明白这是在机器人框架中做到这一点的方法。但请看这个例子:[link](https://github.com/cucumber/cucumber/wiki/Scenario-Outlines)它不是将数据驱动的测试与BDD混合?对我来说这是非常合理的解决方案,而这在机器人框架中似乎还不太清楚。但我是这个主题的初学者,我可能会误解。 ;) – Ewa

+0

@Ewa:该链接转到不同的测试框架。黄瓜和机器人是两个完全不同的东西。在每个测试框架中有许多事情你不能在其他测试框架中完成。机器人框架从未被设计为支持黄瓜语言 - 黄瓜语言。 –

+0

是的,我知道这些是不同的框架。我的问题是,如果我可以在Robot框架中做一些场景大纲。我想现在我知道这不是完全可能的。谢谢你的答案。 :) – Ewa

0

看到这个外观极好blog有关使用小黄瓜像机器人Framework数据表(它是一个优雅的解决方法)。

这是示例代码:

*** 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