Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nicer selectors for integration testing #21

Open
JonasGruenwald opened this issue Nov 26, 2024 · 0 comments
Open

Nicer selectors for integration testing #21

JonasGruenwald opened this issue Nov 26, 2024 · 0 comments
Assignees
Labels
discussion An open discussion, no action needed enhancement New feature or request

Comments

@JonasGruenwald
Copy link
Owner

JonasGruenwald commented Nov 26, 2024

I want to have some nicer, more "human-like" ways to select elements, similar to playwright's locators.
Here is an idea of expressing something like that with a builder pattern:

import chrobot/locator

/// Specify a button locator, then issue a command to it
pub fn wibble() -> Result(Wibble, Wobble) {
    locator.new()
    |> locator.role_button()
    |> locator.text("Submit")
    |> locator.click()
}
import chrobot/locator
import gleeunit/should

/// Use a locator to select an element and assert against an attribute
pub fn wibble() {
  locator.new()
  |> locator.role_button()
  |> locator.text("Submit")
  |> locator.timeout(1000)
  |> locator.get_attribute("data-lustre-on-click")
  |> should.be_ok
  |> should.equal("0-0-1")
}
import chrobot/locator

/// Use a locator to select an input and fill in text (focus+type)
pub fn wibble() {
  locator.new()
  |> locator.label("First Name")
  |> locator.fill("Lucy")
}

Locators would have built-in polling with a default timeout that can be specified as part of the builder with locator.timeout and will be set to a reasonable default otherwise.

In the example above, locator.click(), locator.get_attribute() and locator.fill() take in a locator and run a query against the browser with it, all functions before it are part of the locator builder.

@JonasGruenwald JonasGruenwald self-assigned this Nov 26, 2024
@JonasGruenwald JonasGruenwald added enhancement New feature or request discussion An open discussion, no action needed labels Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion An open discussion, no action needed enhancement New feature or request
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

1 participant