【问题标题】:Specflow table seleniumSpecflow 表硒
【发布时间】:2015-02-06 06:27:30
【问题描述】:

如何在 Specflow 中参数化表格?这是我的功能文件 -

Feature: Login

    As a User,
    should land on ***** Login page
    Enter valid Username and password
    Home page displayed-Validate Logout link

Scenario: Successful login
    Given I am on **** Login page
    When I enter automation and autopassword
    Then the logout link should be displayed

    Scenario: Successful parameterized Login
    Given I am on **** Login page
    When I enter:
    | Username    | Password     |
    | automation  | autopassword |
    | misc        | misc123      |
    Then the Logout link should be displayed

这是我的疑问 - 我想使用第二行值测试登录 - misc & misc123。我怎么能用硒来称呼它? 考虑到登录后有更多的场景,我怎样才能使参数化部分成为一个完整的场景集?测试使用第一行运行一个完整的功能,然后在第二行执行测试登录。

【问题讨论】:

  • 如果您想一个一个地使用多个登录名,那么您可以进行密钥驱动程序设置,这意味着从 excel 中获取用户名的值,然后使用 selenium Web 驱动程序代码将其传递给网页。或者您可以创建数组并在其中存储值,然后将其传递给登录。
  • 我们如何在specflow上集成特征文件以从excel中获取价值?是否可以关键字驱动?
  • 请在此处查看所有详细信息:ontestautomation.com/…
  • 你好陈,如果可能的话你能批准我的回答吗?

标签: specflow


【解决方案1】:

不要使用 Table 元素,而是将其转换为 Scenario Outline。所以你的场景会变成。

Scenario Outline: Successful Login
Given I am on **** Login
When I enter <UserName> and <Password>
Then the logout link should be displayed

Examples: 
| UserName | Password |
| Foo      | Bar      |
| Bar      | Foo      |

这将贯穿每组示例。

【讨论】:

  • 我是 Specflow 的新手,所以我的问题的解决方案可能很简单。但是当我更新现有功能文件以包含场景大纲时,出现此错误 - #error 没有为场景大纲定义示例。在步骤定义中添加了此步骤 - [When(@"I enter (.*) and (. *)")] public void WhenIEnterAnd(string unname, string pwd) { LoginPage vlp = new LoginPage(WebBrowser.Current); vlp.Login(uname, pwd);
  • 谢谢 Muhammad - 我自己回答了我之前的问题。错过了关键字示例和场景。
  • 很高兴你能弄清楚
猜你喜欢
  • 1970-01-01
  • 2015-05-14
  • 1970-01-01
  • 2017-02-26
  • 1970-01-01
  • 2020-04-03
  • 2021-04-29
  • 2015-12-19
  • 2022-01-12
相关资源
最近更新 更多