I'm sure this is a simple one but I have not been able to find the cause of this error let alone the solution.
I am using selenium page objects which has been running perfectly up until now when I have added a new page to my tests.
Here is my main code
class RunTest
{
static IWebDriver driver;
[Test]
public void Login()
{
var options = new ChromeOptions();
options.AddArguments("chrome.switches", "--disable-extensions --disable-extensions-file-access-check --disable-extensions-http-throttling --disable-infobars --enable-automation ");
options.AddUserProfilePreference("credentials_enable_service", false);
options.AddUserProfilePreference("profile.password_manager_enabled", false);
driver = new ChromeDriver(options);
driver.Url = ConfigurationManager.AppSettings["URL"];
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
var loginPage = new LoginPage(driver);
loginPage.LoginToApplication("Test1");
IWait<IWebDriver> wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
var element = wait.Until(ExpectedConditions.ElementIsVisible(By.XPath("//*[@id='content']/div/div/div/div/ul/li[4]/div[1]/div[2]/div/button[1]")));
var setenv = new SetEnvironment(driver);
setenv.SetEnvQA();
}
[Test]
public void AddBatchTest()
{
var AddBatch = new Batch(driver);
AddBatch.AddNewBatch("Test1");
}
[Test]
public void Test1()
{
var NewCli = new AddNewClient(driver);
NewCli.Addanewclient("Test1");
}
The Login and Test1 tests (Along with the others) run perfectly however the Batch test falls over with
System.ArgumentException : The SearchContext of the locator object cannot be null Parameter name: locator
The code in the batch class and AddNewClient class are identical so I cant see what the problem is
Batch:
namespace OnlineStore.PageObjects
{
class Batch
{
IWebDriver driver;
//Admin link in left hand otions
[FindsBy(How = How.XPath, Using = "//*[@id='ctl00_NavigationPanel_navigationpanel1_hlAdmin']")]
public IWebElement AdminScreen { get; set; }
//Add new batch link
[FindsBy(How = How.XPath, Using = "//*[@id='ctl00_MainBody_HyperLink38']")]
public IWebElement AddNewBatchLnk { get; set; }
[FindsBy(How = How.XPath, Using = "//*[@id='ctl00_MainBody_DatepickerReceived_txtDate']")]
public IWebElement DateReceived { get; set; }
[FindsBy(How = How.XPath, Using = "//*[@id='aspnetForm']/div[3]/div/div[2]/div[3]/table[3]/tbody/tr/td/table/tbody/tr[7]/td]")]
public IWebElement SelectToday { get; set; }
[FindsBy(How = How.XPath, Using = "//*[@id='ctl00_MainBody_txtTotal']")]
public IWebElement BatchTotal { get; set; }
[FindsBy(How = How.XPath, Using = "//*[@id='ctl00_MainBody_ucCurrency_ddlCurrency']")]
public IWebElement Currency { get; set; }
[FindsBy(How = How.XPath, Using = "//*[@id='ctl00_MainBody_cboAgency']")]
public IWebElement Provider { get; set; }
[FindsBy(How = How.XPath, Using = "//*[@id='ctl00_MainBody_txtNote']")]
public IWebElement BatchNotes { get; set; }
public Batch(IWebDriver driver)
{
this.driver = driver;
PageFactory.InitElements(driver, this);
}
public void AddNewBatch(string testName)
{
var userData = ExcelDataAccess.GetTestData(testName);
IWait<IWebDriver> wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30.00));
AdminScreen.Click();
wait.Until(ExpectedConditions.ElementIsVisible(By.XPath("//*[@id='ctl00_MainBody_HyperLink38']")));
AddNewBatchLnk.Click();
wait.Until(ExpectedConditions.ElementIsVisible(By.XPath("//*[@id='ctl00_MainBody_DatepickerReceived_txtDate']")));
DateReceived.SendKeys("22/05/2017");
//SelectToday.Click();
BatchTotal.SendKeys("1000");
Currency.SendKeys("USD");
Provider.SendKeys("Client");
BatchNotes.SendKeys("Some Batchg notes here please");
}
}
}
AddNewClient:
public AddNewClient(IWebDriver driver)
{
this.driver = driver;
PageFactory.InitElements(driver, this);
}
public void Addanewclient(string testName)
{
//Code here
}
Any ideas?
Update: I tried moving the AddBatchTest code into the Login code script and it ran fine but when I pushed it back out to its own test it errored again.
Full stack trace as requested in the comments.
Result StackTrace:
at OpenQA.Selenium.Support.PageObjects.PageFactory.InitElements(Object page, IElementLocator locator, IPageObjectMemberDecorator decorator)
at OpenQA.Selenium.Support.PageObjects.PageFactory.InitElements(ISearchContext driver, Object page)
at OnlineStore.PageObjects.Batch..ctor(IWebDriver driver) in C:\Users\andrew.logan-smith\documents\visual studio 2015\Projects\OnlineStore\OnlineStore\PageObjects\Batch.cs:line 54
at OnlineStore.TestCases.RunTest.AddBatchTest() in C:\Users\andrew.logan-smith\documents\visual studio 2015\Projects\OnlineStore\OnlineStore\TestCases\RunTest.cs:line 52
Result Message:
System.ArgumentException : The SearchContext of the locator object cannot be null
Parameter name: locator