在表中找不到列名关键字

本文关键字:关键字 找不到 | 更新日期: 2023-09-27 18:23:48

我已经用BDD C#Cucumber编写了我的第一个特性文件。我的代码构建成功。我在测试资源管理器中运行该功能,方法是右键单击场景名称并从下拉列表中选择run Selected Tests。浏览器打开并导航到网站。但随后在测试浏览器中显示以下错误:

Message: System.indexOutOfRangeException: Could not find a column named 'keyword' in the 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?我的参数表语法不正确吗?

在表中找不到列名关键字

错误显示

在表中找不到名为"keyword"的列。

您的表有Keyword,但在代码中您要查找keyword

要修复它,请更改

string search_text = table.Rows[0]["keyword"].ToString();

string search_text = table.Rows[0]["Keyword"].ToString();