c# - 为什么我会为步骤“鉴于我输入密码详细信息”找到不明确的步骤定义 c# specflow
问题描述
在 VS 2019 中使用 c# 是 specflow 的新手。已经实现了我的步骤并生成了一个步骤定义文件,如下所示。实在想不通 Given, When, Then。我发现并且对于大多数登录页面很常见的示例是,您通常会获得一个需要用户名和密码的登录页面。但是在我的情况下,它们位于两个单独的页面上,即首先使用用户名登录,然后通过密码作为第二页登录。出于某种原因,我认为这就是混乱所在,是我不明白我应该在我的代码中放置 2-3 个给定语句的位置,因此出现错误并且只能将 sendkeys() 发送到用户名并且无法单击登录按钮。
错误:为步骤“鉴于我输入密码详细信息”找到了不明确的步骤定义
此步骤无法执行,因为我的步骤不正确。
[Binding]
public sealed class HomeSteps
{
LoginPage loginPage = null;
[Given(@"I launch the application")]
public void GivenILaunchTheApplication()
{
IWebDriver webDriver = new ChromeDriver(@"C:\Users\Peter\Desktop\chromedriver_win32");
webDriver.Navigate().GoToUrl("https://mycompany.com/app/auth/login");
loginPage = new LoginPage(webDriver);
}
[Given(@"I enter the username details")]
public void GivenIEnterTheUserNameDetails(Table table)
{
dynamic data = table.CreateDynamicInstance();
loginPage.enterUsername((string)data.username);
}
[When(@"I click the login button")]
public void AndIClickTheLogin()
{
loginPage.ClickLoginButton();
}
[Then(@"I should see the login link")]
public void ThenIShouldSeeTheLoghinLink()
{
Assert.That(loginPage.IsMicrosoftPageExist(), Is.True);
}
[Given(@"I enter the password details")]
public void AndIEnterThePaswordDetails(Table table)
{
dynamic data = table.CreateDynamicInstance();
loginPage.enterPassword((string)data.password);
}
[When(@"I click the sign in button")]
public void WhenIClickTheSignInButton()
{
loginPage.ClickSignInButton();
}
[Then(@"I should see the login link")]
public void ThenIShouldSeeTheLoghinLink1()
{
Assert.That(loginPage.IsCompanyPageExist(),Is.True);
}
}
请帮忙??
场景是:
Scenario: Perform login to EA web site
Given I launch the application
And I enter the username details
| username |
| amyemail@email.com |
When I click the login button
When I shoukld see the microsoft logo
When I enter the password details
| password |
| ... |
When I click the sign in button
Then I should see the company page
解决方案
错误消息说明了一切:
为步骤“鉴于我输入密码详细信息”找到了不明确的步骤定义
SpecFlow 不支持同一步骤的多个步骤定义。[Given(@"I enter the password details")]
无论您有多少个步骤定义类,您的步骤定义文件中只能出现一次。
在您的步骤定义类中查找此定义存在的其他位置。选择一个,删除所有其他。
推荐阅读
- java - 带有反应式 mongodb 的 Spring Boot webflux。java.lang.NoSuchMethodException:com.acme.dao.model.Transit。
() - javascript - 如何预填充反应formik表单
- javascript - 如何让 jquery 忽略选择菜单中的选项
- aws-amplify - 使用 CDK 部署 Amplify 应用程序时,如何指定 monorepo 的分支文件夹?
- reactjs - 如何使用 react-pdf 从 PDF 文件中获取页数?
- arrays - 使用 SheetName() 数组从多个工作表中检索单元格以动态链接到每个工作表
- css - 材质 UI 纸张在小视口处未占据全宽
- asp.net-core - 管理对下载文件的访问并在 ASP.NET Core 中隐藏基本 URL
- sublimetext3 - 为什么当我触摸侧边栏外部时,Sublime 上的侧边栏会关闭,如何解决?
- android - 如何使用匕首解决 ViewModel 中的 coroutineScope 依赖关系