0
我的问题是,当假设firstname是由驱动程序在FetchName方法中设置时,我收到一条错误消息,指出驱动程序为null。我可以通过某种方式传递活动的驱动程序实例,以便继续获取数据吗?我如何将参考传递给类之间的活动驱动程序
[TestFixture]
public class TestBase
{
protected IWebDriver driverChrome;
[SetUp]
public void Setup()
{
driverChrome = new ChromeDriver();
}
[TearDown]
public void CleanSite()
{
driverChrome.Quit();
}
}
类“测试”,我创建了所有的[测试]方法。
public void tests: Testbase
{
[Test]
public void testmethods()
{
string blabla = driverChrome.FindElement(By.id("dsd")).Text;
Reuse.FetchName(out string firstname, out string lastname);
Assert.isTrue(firstname.equals(lastname));
}
}
一个类“重用”,其中我有方法,[测试]方法将使用多次。
public class Reuse: Testbase
{
[Test]
public void FetchName(out string firstname, out string lastname)
{
firstname = driverChrome.FindElement(By.XPath("/html/body/div[2]/table/tbody[last()]/tr/td[2]/div")).Text;
lastname = driverChrome.FindElement(By.XPath("/html/body/div[2]/table/tbody[last()]/tr/td[2]/div")).Text;
}
}
你可以让你driverChrome为全局变量或写一个getter setter方法来获得驱动程序实例。 – Alok