Rayrun
← Back to Discord Forum

Do you create elements for buttons/textFields etc?

Hey!

I was wondering and would like to get some input if you are creating in your frameworks elements like Button etc with methods that you are using in your tests later on? You can answer with your "why" if you use it or not. I am just curious if I should go the way of creating them.

example:

export class ButtonElement extends BaseElement {

    constructor(selector: string) {
        super(selector);
    }
}

export function getButtonElement(selector: string): ButtonElement {
    return new ButtonElement(selector);
}
readonly destroyButton: ButtonElement
this.destroyButton = getButtonElement(`${this.selector} button`)

This thread is trying to answer question "Should helper elements be created for basic UI elements like buttons and text fields, and when is it beneficial to do so?"

3 replies

My personal opinion is that you shouldn't bother with elements that have single functionality(like buttons), it just creates boilerplate. However it may benefit if you create such classes for dropdown, autocomplete, some expanding items, that have more than one interaction.

sashaknits
sashaknits

Yes, I use helper elements/classes if there are multiple functions required where it would be too complicated to have to repeat things in the code all the time. A dropdown or search input is a great example, as mentioned above. It's nice to abstract away from the tests/POM the mechanism of inputting a search term, selecting a result, getting the currently selected result etc.

I will also do it if the selector is quite complicated due to the structure of the DOM, again to abstract that away from the tests or the POM.

If it's a basic element where all the built-in Playwright actions will be sufficient and the selector is simple, then I just use a Locator and then call click, hover, etc

Can you share an example for dropdown if possible @oci1458 , @sashaknits ? it would be really helpful

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].