运行 Visual Studio 单元测试项目中的 Gherkin 功能
Running Gherkin Feature in Visual Studio Unit Test Project
我正在尝试设置 运行 一个简单的测试场景,我在 chrome 中打开 google 并搜索 google 并单击第一个 link.我对这些工具的任何知识都为零。
我正在使用 SpecFlow、Gherkin 和 Selenium。
我目前已经创建了我的 .feature 文件和 steps.cs 文件:
SpecFlowFeature.feature:
Feature: SpecFlowFeature
In order to avoid silly mistakes
As a math idiot
I want to be told the sum of two numbers
Scenario Outline: Browese to Google page
Given I am on the Google home page
When I type <search> into textbox
Then I should see link for Google
Examples:
| Search |
| Google |
SpecFlowFeatureSteps.cs:
using System;
using TechTalk.SpecFlow;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
namespace UnitTestProject2
{
[Binding]
public class SpecFlowFeatureSteps
{
private IWebDriver driver;
[BeforeScenario]
public void InitScenario()
{
driver = new ChromeDriver();
}
[AfterScenario]
public void TearDownScenario()
{
driver.Dispose();
}
[Given(@"I am on the Google home page")]
public void GivenIAmOnTheGoogleHomePage()
{
driver.Navigate().GoToUrl("http://google.co.uk");
}
[When(@"I type (.*) into textbox")]
public void WhenITypeIntoTextbox(string p0)
{
driver.FindElement(By.Id("lst-ib")).SendKeys("google");
driver.FindElement(By.XPath("//*[@id='tsf']/div[2]/div[3]/center/input[1]")).Click();
}
[Then(@"I should see link for Google")]
public void ThenIShouldSeeLinkForGoogle()
{
driver.FindElement(By.LinkText("Googlelkj;lkhpbgpiugfytdturwxesugh;k'k#';")).Click();
}
}
}
每当我尝试在测试资源管理器中单击 'Run All' 时,它似乎都没有发现任何测试。
默认情况下,单元测试提供程序是 NUnit。我假设您正在使用 MSTest。
您需要将 app.config 文件中的默认适配器更改为
<unitTestProvider name="MsTest" />
我正在尝试设置 运行 一个简单的测试场景,我在 chrome 中打开 google 并搜索 google 并单击第一个 link.我对这些工具的任何知识都为零。
我正在使用 SpecFlow、Gherkin 和 Selenium。
我目前已经创建了我的 .feature 文件和 steps.cs 文件:
SpecFlowFeature.feature:
Feature: SpecFlowFeature
In order to avoid silly mistakes
As a math idiot
I want to be told the sum of two numbers
Scenario Outline: Browese to Google page
Given I am on the Google home page
When I type <search> into textbox
Then I should see link for Google
Examples:
| Search |
| Google |
SpecFlowFeatureSteps.cs:
using System;
using TechTalk.SpecFlow;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
namespace UnitTestProject2
{
[Binding]
public class SpecFlowFeatureSteps
{
private IWebDriver driver;
[BeforeScenario]
public void InitScenario()
{
driver = new ChromeDriver();
}
[AfterScenario]
public void TearDownScenario()
{
driver.Dispose();
}
[Given(@"I am on the Google home page")]
public void GivenIAmOnTheGoogleHomePage()
{
driver.Navigate().GoToUrl("http://google.co.uk");
}
[When(@"I type (.*) into textbox")]
public void WhenITypeIntoTextbox(string p0)
{
driver.FindElement(By.Id("lst-ib")).SendKeys("google");
driver.FindElement(By.XPath("//*[@id='tsf']/div[2]/div[3]/center/input[1]")).Click();
}
[Then(@"I should see link for Google")]
public void ThenIShouldSeeLinkForGoogle()
{
driver.FindElement(By.LinkText("Googlelkj;lkhpbgpiugfytdturwxesugh;k'k#';")).Click();
}
}
}
每当我尝试在测试资源管理器中单击 'Run All' 时,它似乎都没有发现任何测试。
默认情况下,单元测试提供程序是 NUnit。我假设您正在使用 MSTest。 您需要将 app.config 文件中的默认适配器更改为
<unitTestProvider name="MsTest" />