0

I defined the Object in a Class Called "Page Objects Login page" when I call them in the TestCase class I'm unable to load the object to use it in the test case

I want to be able to select the variables on the TC class, but when I call the PO class, I'm unable to see them.

How I want to call it: LoginOage.(here should display the defined objects?)

How I define the Object: public class LoginPage{

    private IWebDriver driver;

    [FindsBy(How = How.CssSelector, Using = "#contentLogin > div:nth-child(1) > form:nth-child(1) > div:nth-child(2) > button:nth-child(1)")]
    [CacheLookup]
    public IWebElement HP_Accountbtn {get; set;}

How I want to call it: LoginOage.HPAccountbtn

When I set Loginpsge.it doesn't display the objects. Is this the correct way to set up this?

Udara Abeythilake
  • 1,215
  • 1
  • 20
  • 31
bsullit
  • 101
  • 3
  • 11

1 Answers1

1

You can only access static fields without instantiating the class so my expectation is that you need to amend your code to look like:

LoginPage loginPage = new LoginPage()
IWebElement myElement = loginPage.HP_Accountbtn

Another option is to make your button static

public static IWebElement HP_Accountbtn {get; set;}

this way you will be able to access it as:

IWebElement myElement = LoginPage.HP_Accountbtn

Actually the main idea of the Page Object Model Design Pattern is to provide abstraction layer between test logic and the application under test DOM so I would rather recommend exposing a function which will allow to click the button

public class LoginPage {

    [FindsBy(How = How.CssSelector, Using = "#contentLogin > div:nth-child(1) > form:nth-child(1) > div:nth-child(2) > button:nth-child(1)")]
    [CacheLookup]
    private IWebElement HP_Accountbtn {get; set;}

    public void clickHPAccountBtn() {
        HP_Accountbtn.click();
    }

}
Dmitri T
  • 159,985
  • 5
  • 83
  • 133
  • Thanks for the information, I managed to call the object with your solution. But Now i received this error when executing the Testcases: System.NullReferenceException : Object reference not set to an instance of an object. – bsullit Jul 23 '19 at 13:37