TechTalk.SpecFlow.BindingException: 为步骤找到不明确的步骤定义
TechTalk.SpecFlow.BindingException: Ambiguous step definitions found for step
我有 2 个功能使用相同的给定步骤并传递用户名 Given I navigate to the HomePage with the <user>
当我尝试 运行 测试时,我得到以下信息:
TechTalk.SpecFlow.BindingException: 'Ambiguous step definitions found for step 'Given I navigate to the SourceForge HomePage with the user1
功能 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 |
特征 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 |
我尝试创建一个基础 class,然后使用标签和虚拟并覆盖作为变通方法,但我不断收到相同的错误
基类:
public class FeatureBaseClass
{
[Given(@"I navigate to the HomePage with (.*)")]
public virtual void GivenINavigateToTheSourceForgeHomePageWith(string user)
{
string User = user;
}
测试:
[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);
}
谁能看出我错在哪里?或者谁能提出更好的解决方案?
“不明确的步骤定义”意味着您有 2 个或更多步骤具有相同的定义,因此 specflow 不知道您想要哪一个 运行。每个步骤都必须是唯一的。在您的情况下,您有 2 个相同的 Given 语句,如下所示:
[Given(@"I navigate to the HomePage with (.*)")]
在两个不同的类。删除其中一个,它应该 运行.
我有 2 个功能使用相同的给定步骤并传递用户名 Given I navigate to the HomePage with the <user>
当我尝试 运行 测试时,我得到以下信息:
TechTalk.SpecFlow.BindingException: 'Ambiguous step definitions found for step 'Given I navigate to the SourceForge HomePage with the user1
功能 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 |
特征 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 |
我尝试创建一个基础 class,然后使用标签和虚拟并覆盖作为变通方法,但我不断收到相同的错误
基类:
public class FeatureBaseClass
{
[Given(@"I navigate to the HomePage with (.*)")]
public virtual void GivenINavigateToTheSourceForgeHomePageWith(string user)
{
string User = user;
}
测试:
[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);
}
谁能看出我错在哪里?或者谁能提出更好的解决方案?
“不明确的步骤定义”意味着您有 2 个或更多步骤具有相同的定义,因此 specflow 不知道您想要哪一个 运行。每个步骤都必须是唯一的。在您的情况下,您有 2 个相同的 Given 语句,如下所示:
[Given(@"I navigate to the HomePage with (.*)")]
在两个不同的类。删除其中一个,它应该 运行.