我是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;
答案 0 :(得分:0)
错误表示参数"\(\d{3}\)-\d{7}$"
的值为空。我认为这是因为打字错误或您可能忘记为browser
分配值。
将变量driver1
传递给driver1
时,请参阅下面的代码,而应该是SelectLeaseMenu
。
driver
所以你可以解决:
[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);
...