Reputation: 219
I'm getting confused with constants problems which I'm facing during trial of learning Selenium in C#.
First of all, each class which I'm creating inherits a class which sets a new driver (BaseClassTest):
public class BaseApplicationPage
{
protected IWebDriver Driver { get; set; }
public BaseApplicationPage(IWebDriver driver)
{
Driver = driver;
}
}
Next, one of my "main" class (HomePage) starts from inheriting elements from "BaseApplicationPage" and later creates constructor which (in most cases) has empty body. However in that case, inside the body there is a line which: creates a new "Slider" class.
internal class HomePage : BaseApplicationPage
{
public HomePage(IWebDriver driver) : base(driver)
{
Slider = new Slider(driver);
}
public Slider Slider { get; internal set; }
My questions:
Why in my case inside the body there is reference to slider class rather than leaving it empty and adding something like this:
public SliderSection Slider => new SliderSection(Driver);
Upvotes: 2
Views: 647
Reputation: 29362
Answer 1: Is it necessary to fill all new class with something like it (constructor + inheriting from BaseClass)? -- If you need driver object in any particular class like one you've defined(HomePage) , you need a constructor to initialise driver object. Then only you can use driver reference anywhere in that particular class.
Answer2 :
You can use both
public SliderSection Slider => new SliderSection(Driver);
and Slider = new Slider(driver);
provided here, Slider type must be defined in this class or it's base class.
Upvotes: 3