I have 2 features that use the same Given step and pass a username Given I navigate to the HomePage with the <user>
When I try to run a test I get the following:
TechTalk.SpecFlow.BindingException: 'Ambiguous step definitions found for step 'Given I navigate to the SourceForge HomePage with the user1
Feature 1:
Feature: UploadProjectFileFeature
In order to to be to add project documentation
I want to be able to upload project file(s) to the correct project repository
@mytag
Scenario: Upload Project File(S) to the correct project repository
Given I navigate to the HomePage with the <user>
And I Log into the application with <username> and <password>
When I navigate to the <project> page and I upload File(s)
Then the file should upload successfully
Examples:
| user | username | password | project |
| user1 | username | Passtest.123 | TestAutomationP |
Feature 2:
Feature: UserLogin
In order to access my account
As a user of the website
I want to log into the website
@mytag1
Scenario: Successful Login with Correct user
Given I navigate to the HomePage with the <user>
And I Navigate to the LoginPage
When I Log into the application with <username> and <password>
And I Navigate to the Profile Page
Then <user> and <username> should be displayed correctly
Examples:
| user | username| password |
| user1| username| Passtest.123 |
I tried to create a base class and then use tags and virtual and override as a work around but I keep getting the same error
BaseClass:
public class FeatureBaseClass
{
[Given(@"I navigate to the HomePage with (.*)")]
public virtual void GivenINavigateToTheSourceForgeHomePageWith(string user)
{
string User = user;
}
Tests:
[Binding]
[Scope(Feature = "UserLogin")]
public class UserLogin : FeatureBaseClass
{
[Given(@"I navigate to the HomePage with (.*)")]
[Scope(Feature = "UserLogin", Scenario = "Successful Login with Correct user")]
public override void GivenINavigateToTheSourceForgeHomePageWith(string user)
{
Console.WriteLine("Launched Browser with " + user);
}
[Binding]
[Scope(Feature = "UploadProjectFileFeature")]
public class UploadProjectFile : FeatureBaseClass
{
[Given(@"I navigate to the HomePage with (.*)")]
[Scope(Feature = "UploadProjectFileFeature", Scenario = "Upload Project File(S) to the correct project repository")]
public override void GivenINavigateToTheSourceForgeHomePageWith(string user)
{
Console.WriteLine("Launched Browser with " + user);
}
Can anyone see where I am going wrong? or can anyone suggest a better solution?
"Ambiguous step definitions" means that you have 2 or more steps with the same definition and so specflow doesn't know which one you are wanting to run. Each step has to be unique. In your case you have 2 identical Given statements that look like this:
[Given(@"I navigate to the HomePage with (.*)")]
In two different classes. Remove one of them and it should run.