将整个要素文件(或仅在步骤时)调用到另一个要素文件中

时间:2015-11-29 15:19:00

标签: c# automation bdd specflow acceptance-testing

我一直试图调用一个基本功能文件,其中包含在套件中的大多数其他方案中重复的步骤。

由于基本/公共特征文件有大约50个奇数步骤(基于手册TC),我必须验证每个页面/元素,因此它成为非常长的特征文件。

为了避免混淆,我将整个基本文件分成了小部分,每4-5步之后给出一个场景步骤以避免链并添加"#"作为前缀,因为我希望整个文件作为单个场景执行。这是正确的方法还是有人有更好的解决方案请分享,

feature file 1
Scenario: Successful addition of an entry in list
Given User is on the login screen of app
When User enters valid Username and password
And user clicks on Log In 
Then My Recent Submissions screen is displayed
And Add new submission form button should be displayed

#Scenario: Viewing Material information
When User clicks on Add new submission form (+) button 
And a valid Material is searched using <visit> or <mrn>
And user clicks on Search
Then Search Result screen is displayed

#Scenario: Confirming the Material information and taking a photo
When User clicks Take Photo button
And user clicks on Use Photo
Then Image details screen is displayed

#Scenario: Selecting the facility name to reach New submission screen
When user clicks on Warehouse
And user clicks on Xyz Warehouse
Then New Submission screen is displayed

#Scenario: Confirm the Selected Facility to reach My Recent Submission Screen
When user clicks on Submit
Then Alert window pops up
When user selects Yes button on pop up screen
Then My Recent Submissions screen is displayed
And New Entry is added in list
 Examples:
| Username | password   | visit  | mrn    | Search | SearchByScanning |
| user1    | password_1 | 330045 |        | Yes    | No               |
| user1    | password_1 |        | 330045 | Yes    | No               |
| user1    | password_1 |        |        |        |Yes               |
| user1    | password_1 |        |        |        |Yes               |

以上所有步骤均由用户点击XXXXXX 和YYYYYY屏幕显示

XXXXXX和YYYYYY是在步骤定义文件中使用的内联参数,用于验证具有实际输出的页面并单击XXXXXX链接/按钮

要素文件1的所有步骤都以不同的/相同的步骤定义文件存在,格式如下:

[Then(@"(.*) screen is displayed")]
public void ThenApplicationShouldDisplayScreen(string expectedResult)
{
    actualResult = SearchResult.GetTitle ();
    Assert.AreEqual(expectedResult, actualResult);
}

feature file 2

Scenario: User verifies some other functionality
Given some other given statements
When user  does some otherxyz operations
Then user gets some anotherabc output

Scenario:
Given User has created submission successfully #This line would call some of the steps from feature file 1
Given some other given statements
When user  does some othermno operations
Then user gets some anotherpqr output

(feature fle 2)的另一个步骤定义文件

[Binding]
public class webConfigUpdation  : Warehouse.MM.Test.MyRecentSubmissionsSteps #This would inherit all the steps present in this file as stated in link given below
{        
    [Given("User has created submission sucessfully")]
    public void createSubmissionSuccessfully()
    {
         //All the other statements as per requirement that I can add over here using from feature file 1 which will in turn call step definitions mapped to each one of them
        Then(@"My Recent Submissions screen is displayed");
    }
 }

我正在尝试@samholder在另一篇帖子with link

中提供的解决方案

但无法正确实施。我犯了一些愚蠢的错误吗?

如果有人可以分享解决方案对我来说非常方便..

1 个答案:

答案 0 :(得分:0)

如果您想调用其他步骤,只需调用步骤即可。我不确定为什么这不起作用:

[Binding]
public class webConfigUpdation  : Steps
{        
    [Given("User has created submission sucessfully")]
    public void createSubmissionSuccessfully()
    {
         //just call all the steps you need here:
         When("user clicks on Warehouse");
         When("user clicks on Xyz Warehouse");
         Then("New Submission screen is displayed");
         When("user clicks on Submit");
         Then("Alert window pops up");
         When("user selects Yes button on pop up screen");
         Then("My Recent Submissions screen is displayed");
    }
 }

Specflow仍将使用正则表达式来匹配步骤。

这是否存在一些不起作用的具体问题?