8

我正在尝试使用 MSTest/Selenium 在 C# 中进行数据驱动测试。这是我尝试设置它的一些代码的示例:

[TestClass]
public class NewTest
{
    private ISelenium selenium;
    private StringBuilder verificationErrors;
    [DeploymentItem("GoogleTestData.xls")]
    [DataSource("System.Data.OleDb",
    "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=GoogleTestData.xls;Persist Security Info=False;Extended Properties='Excel 8.0'",
    "TestSearches$", DataAccessMethod.Sequential)]

    [TestMethod]
    public void GoogleTest()
    { 
        selenium = new DefaultSelenium("localhost", 4444, "*iehta", http://www.google.com);
        selenium.Start();
        verificationErrors = new StringBuilder();
        var searchingTerm = TestContext.DataRow["SearchingString"].ToString();
        var expectedResult = TestContext.DataRow["ExpectedTextResults"].ToString();

    ...

这是我的错误: 错误 3 非静态字段、方法或属性需要对象引用 'Microsoft.VisualStudio.TestTools.UnitTesting.TestContext.DataRow.get' E:\Projects\SeleniumProject\SeleniumProject\MaverickTest.cs 32 33 硒项目

该错误强调了两个语句的“TestContext.DataRow”部分。我真的一直在努力解决这个问题,谢谢!

4

1 回答 1

12

尝试:

public TestContext TestContext { get; set; }

并尝试像这样使用它:

this.TestContext.DataRow["SearchingString"].ToString();
于 2010-06-07T21:36:24.577 回答