如何在小黄瓜c#中的场景步骤中获得背景步骤参数的值



C#

我有:

Background: I am on the My Account screen
Given That I am on the Login screen
When I type this phone +44776222141815 number
And I type this pin **** number
And Tap the Sign In button
Then The main menu screen should be displayed in less than 5 minutes
When I Tap the My Account option
Then The My Account screen should be displayed
When I Tap the Change PIN option
Then The application should show the Change PIN screen
Scenario Outline: Change PIN - Successful
When I provide the Change PIN details <oldpin>, <newpin> and <repeatnewpin>
And Tap the Submit Button
Then The transaction should be passed in less than 2 minutes

背景步骤在另一个功能/场景中定义,在这里可以借助标签访问。

在步骤定义中,我想获得前一步中提到的电话号码值,即场景大纲的最后一步中的+444776222141815,然后交易

有什么可以得到这个值吗?

是的,这是可能的。在步骤之间共享数据的常用方法是使用上下文注入:

要使用上下文注入,您必须使用

  1. 创建表示共享数据的POCO(简单的.NET类)
  2. 在每个需要它们的绑定类中将它们定义为构造函数参数
  3. 将构造函数参数保存到实例字段中,以便在步骤定义中使用它们

最新更新