【发布时间】:2017-06-21 15:26:46
【问题描述】:
我是 Selenium Webdriver(使用 C#)学习创建 POM 框架的新手。 低于错误 - 代码之前工作正常
消息:System.ArgumentException:定位器对象的 SearchContext 不能为空。
我已经创建了调用另一个类并且调用 pageobject 类的测试用例。
登录的初始步骤工作正常(相同的配置)
下次PageFactory.InitElement 会出错。
public class TC_Sanity
{
private static ExtentReports extent;
private static ExtentTest test;
private static ExtentHtmlReporter htmlReporter;
public IWebDriver driver;
public IWebDriver driver1;
[OneTimeSetUp]
public void report()
{
string CurDate = DateTime.Now.ToString("MMddyy_hhmm");
htmlReporter = new ExtentHtmlReporter(@"U:\Visual Studio 2015\Projects\VisualLeaseFramework\VisualLeaseFramework\Report\MyReport" + CurDate + ".html");
htmlReporter.Configuration().Theme = AventStack.ExtentReports.Reporter.Configuration.Theme.Dark;
htmlReporter.Configuration().DocumentTitle = "TC_Sanity";
htmlReporter.Configuration().ReportName = "KS-TC-Sanity";
htmlReporter.Configuration().JS = "$('.brand-logo').text('').append('<img src=U:\\VL-Team\\VLImage.png>')";
extent = new ExtentReports();
extent.AttachReporter(htmlReporter);
}
[Test]
public void Test_Sanity()
{
test = extent.CreateTest("TC_Sanity");
TestLogin login = new TestLogin(driver);
login.loginTest();
test.Info("Login Successful");
SelectLeaseMenu leasemenu = new SelectLeaseMenu(driver1);
leasemenu.leasemenuselect("New");
test.Info("New Lease Creation Option Selected");
login.logoutQuit();
test.Info("Logout and Quit Successful");
}
[TestFixture]
public class SelectLeaseMenu
{
private IWebDriver driver;
public SelectLeaseMenu(IWebDriver driver)
{
this.driver = driver;
}
[Test]
public void leasemenuselect(string menu)
{
if (menu == "New")
{
LandingPage landingpage = new LandingPage(driver);
Actions action = new Actions(driver);
IWebElement projMenu = landingpage.LeaseMenu;
action.MoveToElement(projMenu).Click().Build().Perform();
System.Console.WriteLine("Moved to Lease Menu");
Thread.Sleep(1000);
IWebElement newLease = driver.FindElement(By.LinkText("New"));
newLease.Click();
}
public class LandingPage
{
private IWebDriver driver;
public LandingPage(IWebDriver browser)
{
this.driver = browser;
PageFactory.InitElements(browser, this);
}
[FindsBy(How = How.XPath, Using = "html/body/form/div[3]/div/div[3]/div[1]/input[2]")]
[CacheLookup]
public IWebElement Searchbox;
【问题讨论】: