-
24-10-2019 - |
题
我正在尝试将数据驱动的测试与MSTest/Selenium一起使用。这是我的一些代码试图设置的示例:
[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 seleniumproject seleniumproject mavericktest.cs 32 33硒
该错误强调了两个语句的“ testContext.datarow”一部分。我真的一直在为此而苦苦挣扎,谢谢!
解决方案
尝试:
public TestContext TestContext { get; set; }
并尝试使用它:
this.TestContext.DataRow["SearchingString"].ToString();
不隶属于 StackOverflow