0

I added implicit wait in SetUp method of Test class and also in Constructor of page object. I need to apply wait for all Test methods. But it doesn't work. Can anyone help pls. I have used NUnit framework

Page Object:

    namespace ProjectName.PageObjects
    {
        class SearchPage
        {
            IWebDriver driver;

            public SearchPage(IWebDriver driver)
            {
                this.driver = driver;
                PageFactory.InitElements(driver, this);
                driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(40);
            }
            [FindsBy(How = How.XPath, Using = "//a[text()='Search']")]
            IWebElement search;

     public void SearchClick()
     {
           search.Click();
     }
    }
  }

Test class:

namespace ProjectName
{
    class SearchTestClass
    {
        IWebDriver driver;
        SearchPage search;

        [SetUp]
        public void SetUp()
        {            
                driver = new ChromeDriver();
                driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(40);
               //Go to URL
               //Login
        }

        [Test]
        public void SearchTest()
        {
            search.SearchClick();
        }
}
}
merinn
  • 35
  • 1
  • 6

1 Answers1

0

It would be better to have one common class where your can have the basic initialization stuffs as a method as below and call that method in all your Test classes before the Test method starts.

And derive the parent class BaseTest to all your Test Classes.

I have done some modification in your code as below.

public Class BaseTest {

IWebDriver driver;

 public static void Initialization() {
    driver = new ChromeDriver();
    driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(40);
    //Go to URL
    //Login

} }

Page Object:

namespace ProjectName.PageObjects { class SearchPage { IWebDriver driver;

        public SearchPage(IWebDriver driver)
        {
            this.driver = driver;
            PageFactory.InitElements(driver, this);

        }
        [FindsBy(How = How.XPath, Using = "//a[text()='Search']")]
        IWebElement search;

 public void SearchClick()
 {
       search.Click();
 }
}

}

Test class:

namespace ProjectName { class SearchTestClass {

    SearchPage search;

    [SetUp]
    public void SetUp()
    {            
           //Just call the Initialization method in every test class like here before the test methods starts execution
            Initialization();
    }

    [Test]
    public void SearchTest()
    {
        search.SearchClick();
    }

} }