Skip to content

Instantly share code, notes, and snippets.

@titusfortner
Last active March 20, 2020 16:00
Show Gist options
  • Save titusfortner/f292cb8093f81f5fd57b3df2031fbe25 to your computer and use it in GitHub Desktop.
Save titusfortner/f292cb8093f81f5fd57b3df2031fbe25 to your computer and use it in GitHub Desktop.
Defining Elements in Page Objects
@TagName("form")
private Element form;
@Id("user_email") @Scope("form")
private TextField email;
@Id("user_password")
private TextField password;
@Data("test=submit")
private Button submit;
private Element form = browser.element(By.tagName("form"));
private TextField email = form.textField(By.id("user_email"));
private TextField password = browser.textField(By.id("user_password"));
private Button submit = browser.button(By.cssSelector("[data-test=submit]"));
@asolntsev
Copy link

Oh yes, I also ignore @Scope("form") annotation. Well, it's also easy:

private SelenideElement form = $("form");
private SelenideElement email = form.$("#user_email");
private SelenideElement password = form.$("#user_password");
private SelenideElement submit = form.$(by("data-test", "submit"));

@titusfortner
Copy link
Author

I'm somewhat amused that the Ruby dev is pushing for Typing and the Java dev is calling it not beneficial. :)

@asolntsev
Copy link

Yes, it's funny. :)

No, generally I love types. I only don't see any benefits of types in case of web elements.
They all have only two methods: click and sendKeys, that's why type doesn't matter for them.

@titusfortner
Copy link
Author

Yeah, except SelectLists, and IFrames and RadioGroups and Forms and Input Fields and Date Fields.

And it isn't just about actions, it is about state (selected vs not selected); it is about information (selected value), etc.

A lot of code in Watir is managing these differences. Are they essential to being able to write tests? No. Are they beneficial? In my experience, yes absolutely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment