A
A
Alexander Vasilenko2020-01-02 17:09:21
Java
Alexander Vasilenko, 2020-01-02 17:09:21

Is it good to make fields (WebElements) public in PageObject implementation?

The fact is that operations with some elements are really simple: click, enter a value, etc.
How bad/good practice is it to make PageObject fields public?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
1
1001001, 2020-01-02
@1001001

This is your personal kitchen, as you decide with your colleagues, do it. )
But I am of the opinion that in PageObject it is necessary to keep not fields but logic.
Here you have a button for throwing goods into the basket, you made a field in PO (By, or WebElement, or some other wrapper is not important). Now in several tests you use it

@Test
publuc void UserShoudBeAdblePay(){
  ...
  driver.findElement(pay).click();
}

And then the application develops and the button turns into a drop-down where you throw two items into the basket and buy right away, now you go and shovel the whole code by adding a click to open the drop-down.
And if you lay the logic in PO, then you will need to edit in 1 place
public void putInBasket() {
        driver.findElement(By.id("pay")).click();
    }

public void putInBasket() {
        driver.findElement(By.id("drop-down")).click();
        driver.findElement(By.id("pay")).click();
    }

Another thing is that you may not need PageObject, if you have UI tests that check something that cannot be checked by lower-level tests, there is a chance that the PO as a whole is redundant)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question