2

I have been practicing using POM design approach (with Data Driven & testNg framework) for Selenium;

I recently got to see a selenium automation developer using POM with neither @FindBy nor PageFactory in the script

What I didn't understand using 'By' in the selenium script as follows:

By element_name = By.id("String");

'By' is an abstract class (as mentioned in selenium -- java api documentation), and the methods such id, classname, name, xpath and etc are static methods;

Based on these facts, how is the abstract class and static methods are directly implemented?

Below is the code I am talking about.

public TrialLoginPage(WebDriver driver, Properties prop) {

     super(driver, prop);

    }

    By name = By.name("username");
    By password = By.name("password");
    By submit = By.xpath("//input[@type='submit']");

    public String getTitle() {

        String title = driver.getTitle();
        return title;
    }

    public WebElement setUserName() {

        WebElement element = driver.findElement(name);

        return element;
    }

    public WebElement setPassword() {

        WebElement element = driver.findElement(password);
        return element;
    }

    public WebElement setSubmit() {

        WebElement login = driver.findElement(submit);
        return login;
    }

    public String driverStatus() {

        String str = driver.toString();
        return str;
    }   
}
Ori Marko
  • 56,308
  • 23
  • 131
  • 233
Vijayrushi
  • 41
  • 3

1 Answers1

2

By is an abstract class, it can have methods with implementation, the only restriction for abstract is that it can't be instantiated, e.g. calling new By()

it may or may not include abstract methods. Abstract classes cannot be instantiated

You are calling name method which isn't abstract that returns By object:

public static By name(java.lang.String name)
Ori Marko
  • 56,308
  • 23
  • 131
  • 233