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

Add Javascript helper methods #138

Closed
giulong opened this issue Apr 14, 2024 · 2 comments · Fixed by #159
Closed

Add Javascript helper methods #138

giulong opened this issue Apr 14, 2024 · 2 comments · Fixed by #159
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@giulong
Copy link
Owner

giulong commented Apr 14, 2024

Feature description

Though this should be generally avoided in a Selenium test, there are some scenarios where there is no option rather than delegating the execution to Javascript (e.g.: Safari not doing what it's expected to with regular Selenium methods). In this context, we would like to have Spectrum expose some helper methods to run basic actions in Javascript.

Describe why this should be added to Spectrum

Having helper methods in the framework would reduce the boilerplate code a user needs to write: instead of explicitly casting the driver to JavascriptExecutor and calling the executeScript method each time, we could have methods like the already present click that could be easily chained:

public Js click(final WebElement webElement) {
    driver.executeScript("arguments[0].click();", webElement);

    return this;
}

We'd like to add to the Js class few methods to ideally replicate every method exposed by the WebElement interface, such as:

  • find element(s)
  • send keys
  • clear
  • ...

This way, users could use them in their tests like:

js
    .findElement(By.tagName("button"))
    .click(button);

js
    .findElement(By.id("my-input-field"))
    .clear(inputField)
    .sendKeys(inputField, "text value");

Additional context

  • Provide the javadocs for each method
  • Add at least one call for each method, to demonstrate how they work, in the JavascriptIT test. If needed, new tests methods can be added to that class. In this case, the COMPLETED value of the ItVerifierTest should be modified accordingly.
@giulong giulong added enhancement New feature or request good first issue Good for newcomers labels Apr 14, 2024
@AndreaDotDev
Copy link
Contributor

Hi! I would be happy to help you out. May I work on this one?

@giulong
Copy link
Owner Author

giulong commented Apr 16, 2024

Sure! As a starting point, check out the Submitting Changes paragraph, and don't be afraid to ask if you have any doubt!

@giulong giulong linked a pull request May 12, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants