【发布时间】:2020-12-12 06:59:37
【问题描述】:
我有 2 个功能使用相同的 Given 步骤并传递用户名 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 |
我尝试创建一个基类,然后使用标签和虚拟并覆盖作为解决方法,但我一直收到同样的错误
基类:
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);
}
谁能看出我哪里出错了?或者任何人都可以提出更好的解决方案?
【问题讨论】:
-
是的,这是我提出解决方案的帖子。但无论出于何种原因未能成功复制
标签: c# automated-tests cucumber specflow gherkin