Reputation:
I am new to creating tests in visual studio using selenium and C#. I have two files, one is search engine maing page and the other is a testing file. The files can be found here---https://www.automatetheplanet.com/page-object-pattern/
I always get this error; Below are screenshots of the problem.
Error CS0246: The type or namespace name 'WebDriverWait' could not be found?
What am I doing wrong??
below is the following code-
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
[TestClass]
public class SearchEngineTests
{
public IWebDriver Driver { get; set; }
public WebDriverWait Wait { get; set; }
[TestInitialize]
public void SetupTest()
{
this.Driver = new FirefoxDriver();
this.Wait = new WebDriverWait(this.Driver, TimeSpan.FromSeconds(30));
}
[TestCleanup]
public void TeardownTest()
{
this.Driver.Quit();
}
[TestMethod]
public void SearchTextInSearchEngine_First()
{
SearchEngineMainPage searchEngineMainPage = new SearchEngineMainPage(this.Driver);
searchEngineMainPage.Navigate();
searchEngineMainPage.Search("Automate The Planet");
searchEngineMainPage.ValidateResultsCount("264,000 RESULTS");
}
}
This is the second file-
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Support.PageObjects;
public class SearchEngineMainPage
{
private readonly IWebDriver driver;
private readonly string url = @"searchEngineUrl";
public SearchEngineMainPage(IWebDriver browser)
{
this.driver = browser;
PageFactory.InitElements(browser, this);
}
[FindsBy(How = How.Id, Using = "sb_form_q")]
public IWebElement SearchBox { get; set; }
[FindsBy(How = How.Id, Using = "sb_form_go")]
public IWebElement GoButton { get; set; }
[FindsBy(How = How.Id, Using = "b_tween")]
public IWebElement ResultsCountDiv { get; set; }
public void Navigate()
{
this.driver.Navigate().GoToUrl(this.url);
}
public void Search(string textToType)
{
this.SearchBox.Clear();
this.SearchBox.SendKeys(textToType);
this.GoButton.Click();
}
public void ValidateResultsCount(string expectedCount)
{
Assert.IsTrue(this.ResultsCountDiv.Text.Contains(expectedCount), "The results DIV doesn't contains the specified text.");
}
}
And also getting the below error
Error CS1729: 'SearchEngineMainPage' does not contain a constructor that takes 1 arguments (CS1729) (testingProgram)
Error CS0103: The name 'TimeSpan' does not exist in the current context (CS0103) (testingProgram)
Upvotes: 0
Views: 1404
Reputation: 2334
#1:WebDriverWait
is available in the Selenium.Support package. So, Please import the below package in SearchEngineTests
Test class.
using OpenQA.Selenium.Support.UI;
#2:TimeSpan
is available in the default System
namespace.so, please add the below namespace as well
using System
Regarding to add the required namespace, If you are seeing any red color underlined code in your program, then move the cursor towards that particular field. It will give the suggestion to add the relevant namespace
#3:
Regarding the SearchEngineMainPage
constructor error. Please add the constructor in SearchEngineMainPage class with agument as driver. It looks, already you are having the argument constructor. Whether you are still getting this error?
Upvotes: 2