在 table 中找不到列名关键字
Could not find a column name keyword in the table
我已经用 BDD C# Cucumber 编写了我的第一个功能文件。我的代码构建成功。我通过右键单击场景名称并从下拉列表中选择 运行 选定测试来 运行 Test Explorer 中的功能。浏览器打开并导航到该网站。但是随后在测试资源管理器中显示以下错误:
Message: System.indexOutOfRangeException: Could not find a column named 'keyword' in the table.
table 看起来像这样:
| Keyword |
| PS4 |
我的特征文件如下:
Feature: PS4 Search
@mytag
Scenario: Verify the search Functionality of Search page
Given I navigate to the page "http://localhost:8080/company"
And I see the page is loaded
When I enter Search Keyword in the Search Text box
| Keyword |
| PS4 |
And I click on Search Button
Then Search items shows the items related to PS4
我的步骤代码如下:
using System;
using TechTalk.SpecFlow;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using NUnit.Framework;
namespace PS4SearchTest
{
[Binding]
public class PS4SearchSteps
{
IWebDriver driver;
[Given(@"I navigate to the page ""(.*)""")]
public void GivenINavigateToThePage(string p0)
{
driver = new FirefoxDriver();
driver.Navigate().GoToUrl("http://localhost:8080/company");
}
[Given(@"I see the page is loaded")]
public void GivenISeeThePageIsLoaded()
{
Assert.AreEqual("PS4", driver.Title);
}
[When(@"I enter Search Keyword in the Search Text box")]
public void WhenIEnterSearchKeywordInTheSearchTextBox(Table table)
{
string search_text = table.Rows[0]["keyword"].ToString();
driver.FindElement(By.Name("q")).SendKeys(search_text);
}
[When(@"I click on Search Button")]
public void WhenIClickOnSearchButton()
{
driver.FindElement(By.Name("BtnG")).Click();
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(5));
}
[Then(@"Search items shows the items related to PS4")]
public void ThenSearchItemsShowsTheItemsRelatedToSpecFlow()
{
Assert.AreEqual("PS4", driver.FindElement(By.XPath("//h3/a")).Text);
driver.Close();
}
}
}
为什么找不到参数PS4?我的 table 参数语法不正确吗?
错误显示
Could not find a column named 'keyword' in the table.
您的 table 有 Keyword
,但在您的代码中您正在寻找 keyword
。
要修复它,请更改
string search_text = table.Rows[0]["keyword"].ToString();
到
string search_text = table.Rows[0]["Keyword"].ToString();
我已经用 BDD C# Cucumber 编写了我的第一个功能文件。我的代码构建成功。我通过右键单击场景名称并从下拉列表中选择 运行 选定测试来 运行 Test Explorer 中的功能。浏览器打开并导航到该网站。但是随后在测试资源管理器中显示以下错误:
Message: System.indexOutOfRangeException: Could not find a column named 'keyword' in the table.
table 看起来像这样:
| Keyword |
| PS4 |
我的特征文件如下:
Feature: PS4 Search
@mytag
Scenario: Verify the search Functionality of Search page
Given I navigate to the page "http://localhost:8080/company"
And I see the page is loaded
When I enter Search Keyword in the Search Text box
| Keyword |
| PS4 |
And I click on Search Button
Then Search items shows the items related to PS4
我的步骤代码如下:
using System;
using TechTalk.SpecFlow;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using NUnit.Framework;
namespace PS4SearchTest
{
[Binding]
public class PS4SearchSteps
{
IWebDriver driver;
[Given(@"I navigate to the page ""(.*)""")]
public void GivenINavigateToThePage(string p0)
{
driver = new FirefoxDriver();
driver.Navigate().GoToUrl("http://localhost:8080/company");
}
[Given(@"I see the page is loaded")]
public void GivenISeeThePageIsLoaded()
{
Assert.AreEqual("PS4", driver.Title);
}
[When(@"I enter Search Keyword in the Search Text box")]
public void WhenIEnterSearchKeywordInTheSearchTextBox(Table table)
{
string search_text = table.Rows[0]["keyword"].ToString();
driver.FindElement(By.Name("q")).SendKeys(search_text);
}
[When(@"I click on Search Button")]
public void WhenIClickOnSearchButton()
{
driver.FindElement(By.Name("BtnG")).Click();
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(5));
}
[Then(@"Search items shows the items related to PS4")]
public void ThenSearchItemsShowsTheItemsRelatedToSpecFlow()
{
Assert.AreEqual("PS4", driver.FindElement(By.XPath("//h3/a")).Text);
driver.Close();
}
}
}
为什么找不到参数PS4?我的 table 参数语法不正确吗?
错误显示
Could not find a column named 'keyword' in the table.
您的 table 有 Keyword
,但在您的代码中您正在寻找 keyword
。
要修复它,请更改
string search_text = table.Rows[0]["keyword"].ToString();
到
string search_text = table.Rows[0]["Keyword"].ToString();