1

@Thanks the_coder As he explained ; I have add some lines to my PageObject class. And then use them on the same class. Then call the login method from my test by creating an object reference.

But i was getting the following error.

java.lang.NullPointerException

Which was resolved by adding the following constructor to the Page object class

public POMLogin()
{
  PageFactory.initElements(jUnitLogintest.driver, this);
}

enter image description here

  • I saw this at the consol:INFO: Detected dialect: W3C JavaScript error: XXXX.com/clientscript/vbulletin_md5.js?v=387, line 1: SyntaxError: expected expression, got '<' JavaScript warning: XXXX.com/forum/combank/index.html, line 42: mutating the [[Prototype]] of an object will cause your code to run very slowly; instead create the object with the correct initial [[Prototype]] value using Object.create Picked up _JAVA_OPTIONS: -Xmx1024M – ChathuD Mar 16 '17 at 15:51
  • Oooh god. I miss this part.public POMLogin() { PageFactory.initElements(jUnitLogintest.driver, this); } – ChathuD Mar 16 '17 at 16:09
3

You need to create methods (actions to be done on the elements) in your page object like the following:

Page Object

class POMLogin
{
 // Web Elements

 public void login()
 {
   UsernameTxtBox.sendKeys("x");
   PasswordTxtBox.sendKeys("y");
   ButtonLgn.click();
 }
}

And use the page objects in your test class

Test Class:

# Pseudo code
import packagename.POMLogin;
public void TestClass
{
    @Test
    public void LoginCheck()
    {
      POMLogin pom = new POMLogin();
      pom.login();
     // Then perform your assert here
    }
}

The above code is just a pseudo code.

  • Thanks your answer makes me feel soo easy to implement this POM in java – ChathuD Mar 16 '17 at 16:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.