2014-09-05 16 views
0

是否有无论如何我们可以多次运行相同的测试来验证功能。如何使用不同的用户角色多次运行相同的BDD功能

这是我的特点文件:

Feature: End to end tests 

    I want an End to End test pack 
    As Super user and Admin user 
    So that I can ensure that the integrated components of the application function as expected 

    Background: 
      Given I have the login Page 
      When I login to application 
      Then the list is displayed 

    @javascript 
    Scenario: To verify the functionality on the Dashboard   
      When I navigate to the Dashboard Page 
      Then the Dashboard Page is displayed 

我想运行此方案2个不同的用户。有没有办法使用多个用户/角色来运行相同的功能。

我有几个其他的特征文件,这需要使用,我需要在夜间运行

请参考下面的内容档案2级或3个不同的用户运行:

public function iLoginToApplication() { 
$page = $this->getSession()->getPage(); 
$page->find('css', '#username')->setValue("admin"); 
$page->find('css', '#password')->setValue("Password"); 
$signInButton->press(); 
} 
+0

有些人会考虑帮助,当你通过所有你的19个问题,并接受答案,补充了你13年的工作经验。社区花费你知道的时间... – 2014-09-06 21:39:32

+1

我完全理解并欣赏你来自哪里。我已经接受并评论了相关的人。你可以更具体的 – 2014-09-07 22:45:41

回答

1

是的,可以。直接在Feature: …之下的部分从功能角度来看几乎没有用处,并且用作文档。 AFIAK你可以删除它或写任何你想要的东西,你的测试将运行完全一样。

你在找什么是scenario outlines,他们的目的就是为了这个,尽管你需要更新一些你的场景,并且仍然手动指定Examples下的每个用户。

Feature: End to end tests 

    I want an End to End test pack 
    As Super user and Admin user 
    So that I can ensure that the integrated components of the application function as expected 

    Background: 
     Given I have the login Page 

    @javascript 
    Scenario Outline: To verify the functionality on the Dashboard   
     When I login to application as "<username>" with "<password>" 
     Then the list is displayed 
     When I navigate to the Dashboard Page 
     Then the Dashboard Page is displayed 

    Examples: 
     | username | password | 
     | super | qwerty | 
     | admin | qwerty | 

/** 
* @When /^I login to application$/ 
* @When /^I login to application as "(.+)" with "(.+)"$/ 
*/ 
public function iLoginToApplication($username = null, $password = null) { 
    $page = $this->getSession()->getPage(); 
    $page->find('css', '#username')->setValue(isset($username) ? $username : 'admin'); 
    $page->find('css', '#password')->setValue(isset($password) ? $password : 'Password'); 
    $signInButton->press(); 
} 

另一种方法是在全球范围内配置此之前运行的套房,例如,通过环境变量与用户名到PHP当您运行贝哈特,并用不同的配置运行一切几次。这将是上述解决方案的破绽,并不那么直观,所以你最好用Behat的方式来做。

+0

非常感谢答复。当我们的环境备份并运行时,我将尝试此解决方案 – 2014-09-09 14:55:00

+0

让我知道它是否能够完成这项工作。 – 2014-09-09 15:09:39

+0

嗨伊恩,我试图使用该解决方案。但问题是在我的上下文文件中使用它。我可以将此作为参数传递给我的上下文文件吗?请参考上述关于上下文的描述: – 2014-09-09 15:14:42

相关问题