问题
I have been trying to call one base feature file which has steps which are repetitive across most of my other scenarios in suite.
Since base/common feature file has around 50 odd steps(based on manual TC) and I had to verify every page/element hence it's becoming very long feature file.
To avoid confusion I had divided entire base file into small sections by giving the scenario steps after every 4-5 steps to avoid the chain and added "#" as a prefix since I wanted whole file to execute as a single scenario. Is this right methodology or if somebody has better solution please share,
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 |
All the above steps with user click on XXXXXX and YYYYYY screen is displayed
XXXXXX and YYYYYY are the inline parameters which are used in step definition file inside methods to verify the pages with actual output and click on XXXXXX links/buttons
All the steps of feature file 1 are present across different/same step definition file in the format stated below,
[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
In another step definition file for (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");
}
}
I was trying the solution given by @samholder in another post with link
but was unable to implement it correctly. Am I making some silly mistake??
If anybody could share the solution would come very handy to me..
回答1:
if you want to call your other steps you just need to call the steps. I'm not sure why this wouldn't work:
[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 will still use the regex to match the the steps.
Is there some specific problem with this that doesn't work?
来源:https://stackoverflow.com/questions/33984359/calling-entire-feature-fileor-only-when-steps-into-another-feature-file