Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在SpecFlow和Selenium的功能设置中指定登录_Selenium_Bdd_Specflow - Fatal编程技术网

在SpecFlow和Selenium的功能设置中指定登录

在SpecFlow和Selenium的功能设置中指定登录,selenium,bdd,specflow,Selenium,Bdd,Specflow,我已经设置了SpecFlow来执行一些Selenium测试来测试一个网站。这一切都很好 我只是在考虑是否有空间对SpecFlow特性的结构进行一些优化 特定功能中的所有场景都应使用相同的登录。这是我目前使用[BeforeCasenario]钩子在StepDefinition中硬编码的东西,因为我不想用登录信息污染场景。这与测试无关 但同时,我想删除硬编码部分,并将其移动到我的功能中 我的问题分为两部分 我可以在功能描述中指定登录凭据吗。有点像一个给定的: Feature: As a user I

我已经设置了SpecFlow来执行一些Selenium测试来测试一个网站。这一切都很好

我只是在考虑是否有空间对SpecFlow特性的结构进行一些优化

特定功能中的所有场景都应使用相同的登录。这是我目前使用[BeforeCasenario]钩子在StepDefinition中硬编码的东西,因为我不想用登录信息污染场景。这与测试无关

但同时,我想删除硬编码部分,并将其移动到我的功能中

我的问题分为两部分

我可以在功能描述中指定登录凭据吗。有点像一个给定的:

Feature: As a user I want to be able to see my ongoing orders, and interact with them.
Given I am logged in with username abc and password xyz

Scenario: See list of ongoing order
Given I place an order
When I navigate to MyOrders page
Then I can see at least one order in the list
这是好的做法吗

我是说,在功能层面上,这样做有意义吗。这些场景不依赖于特定的顺序,如果我不需要登录每个场景,它们的执行速度会更快


感谢您的输入。

对于功能中所有场景通用的步骤,您可以使用背景:

    Feature: As a user I want to be able to see my ongoing orders, and interact with them.

    Background:
    Given I am logged in with username abc and password xyz

    Scenario: See list of ongoing order
    Given I place an order
    When I navigate to MyOrders page
    Then I can see at least one order in the list
过多地滥用后台步骤可能是一种不好的做法,因为它会在场景之间引入耦合

另一个解决方案是将登录部分直接放入I下订单步骤。 这将消除所有关于登录的杂音,因为这意味着您需要登录才能下订单

我还建议称之为“我下了订单”,而不是“我下了订单”。
给定步骤通常是先决条件,用于描述在使用Functionality之前发生的情况,当步骤

对于功能中所有场景通用的步骤,您可以使用背景:

    Feature: As a user I want to be able to see my ongoing orders, and interact with them.

    Background:
    Given I am logged in with username abc and password xyz

    Scenario: See list of ongoing order
    Given I place an order
    When I navigate to MyOrders page
    Then I can see at least one order in the list
过多地滥用后台步骤可能是一种不好的做法,因为它会在场景之间引入耦合

另一个解决方案是将登录部分直接放入I下订单步骤。 这将消除所有关于登录的杂音,因为这意味着您需要登录才能下订单

我还建议称之为“我下了订单”,而不是“我下了订单”。
给定的步骤通常是描述在使用Functionality之前发生的情况的先决条件,当我第一次阅读你的帖子时,我想到了步骤,这影响了我,使我认为我们应该尝试编写测试,以便它们坚持一个知识域。当您在列表中谈论特定用户、导航和订单时,很像他给出的示例,您的规范是跨域的。这种情况导致我几乎使您的规范变得不那么具体,也就是说,它不是关于导航和检查列表,您是否有订单

场景:请参阅正在进行的订单列表 假设我使用用户名abc和密码xyz登录 我下订单 那么应该至少有一个订单

我想给大家提供另一个示例链接,指向一篇我找不到的帖子,它讨论了团队通过实际定义一些示例用户而获得的好处,以及为他们的测试提供了什么价值。因此,在您的业务领域中,您可能有一个名为Jack的用户,他将在系统中下大订单,而另一个潜在客户Jill没有订单。以这种方式进行测试,例如

Given I am Jack
When I search for my orders
Then I will find 1

Given I am Jill
When I search for my orders
Then I will find 0
可以保证您只测试您的搜索功能,而不必担心安装是否到位

我还建议你们看一看世卫组织声称,更一般的广义定义不如非常具体的例子有价值。这是通过示例说明的:


因此,为了回答您的问题,我认为拥有指定的用户是一件好事,但按照您目前的方式进行操作是一条非常复杂的路线

当我第一次读到你的帖子时,我想到了这一点,这影响了我的想法,我们应该试着编写我们的测试,以便它们能够坚持单一的知识领域。当您在列表中谈论特定用户、导航和订单时,很像他给出的示例,您的规范是跨域的。这种情况导致我几乎使您的规范变得不那么具体,也就是说,它不是关于导航和检查列表,您是否有订单

场景:请参阅正在进行的订单列表 假设我使用用户名abc和密码xyz登录 我下订单 那么应该至少有一个订单

我想给大家提供另一个示例链接,指向一篇我找不到的帖子,它讨论了团队通过实际定义一些示例用户而获得的好处,以及为他们的测试提供了什么价值。因此,在您的业务领域中,您可能有一个名为Jack的用户,他将在系统中下大订单,而另一个潜在客户Jill没有订单。以这种方式进行测试,例如

Given I am Jack
When I search for my orders
Then I will find 1

Given I am Jill
When I search for my orders
Then I will find 0
可以保证您只测试您的搜索功能,而不必担心安装是否到位

我还建议你看看谁声称 更一般的广义定义不如非常具体的例子有价值。这是通过示例说明的:


因此,为了回答您的问题,我认为拥有指定的用户是一件好事,但按照您目前的方式进行操作是一条非常复杂的路线

给出的场景示例与该功能完全不符

   Feature: As a user I want to be able to see my ongoing orders, and interact with them.

Background:
Given I am logged in as John Doe

Scenario: This is taking to long
And I have placed an order more than 29 days ago
When I navigate to MyOrders page
Then I can see my order in the list
and I am able to cancel it

Scenario: Track package
And I have been notified my order has been send
When I navigate to MyOrders page
Then I can see my order in the list
and I am able to navigate to the postman's site and see its status

Scenario: Review item
And I have received my package
When I navigate to MyOrders page
Then I can see my order in the list
and I am able to review the item

Scenario: Contact Seller
And I have placed an order two weeks ago
When I navigate to MyOrders page
Then I can see my order in the list
and I am able to ask the seller what is going on

正如你所看到的,那时和那时开始复制自己,你可能想考虑把这些隐藏起来。

所给出的场景例子完全不符合这个特性。

   Feature: As a user I want to be able to see my ongoing orders, and interact with them.

Background:
Given I am logged in as John Doe

Scenario: This is taking to long
And I have placed an order more than 29 days ago
When I navigate to MyOrders page
Then I can see my order in the list
and I am able to cancel it

Scenario: Track package
And I have been notified my order has been send
When I navigate to MyOrders page
Then I can see my order in the list
and I am able to navigate to the postman's site and see its status

Scenario: Review item
And I have received my package
When I navigate to MyOrders page
Then I can see my order in the list
and I am able to review the item

Scenario: Contact Seller
And I have placed an order two weeks ago
When I navigate to MyOrders page
Then I can see my order in the list
and I am able to ask the seller what is going on

<> P>正如你所看到的,那时和那时开始复制自己,你可能想考虑把那些隐藏起来。

谢谢AlSki,这正是我所想的,但不知道如何用语言来表达……正如你所知道的,我不知道如何将其应用到场景中。实际上,我们有大约12个不同的示例用户,其名称正如您所建议的。他们没有这样的登录,但他们是我们用来讨论不同场景的人。当你提到这一点时,这些碎片就就位了!当然这是我应该用的。我可能不得不发明更多的用户,以考虑我想要测试的所有不同场景。但这是有道理的!谢谢谢谢阿尔斯基,这正是我所想的,但我不知道如何用语言表达。。。正如你所知道的,我不知道如何将其应用到场景中。实际上,我们有大约12个不同的示例用户,其名称正如您所建议的。他们没有这样的登录,但他们是我们用来讨论不同场景的人。当你提到这一点时,这些碎片就就位了!当然这是我应该用的。我可能不得不发明更多的用户,以考虑我想要测试的所有不同场景。但这是有道理的!谢谢嗨,Sigo,谢谢你的回复!虽然从技术上讲这是我所要求的,但我选择将阿尔斯基的回答标记为正确,因为它描述了我应该做什么。它完全符合我的需要。嗨,西格,谢谢你的回复!虽然从技术上讲这是我所要求的,但我选择将阿尔斯基的回答标记为正确,因为它描述了我应该做什么。它完全符合我的需要。