Skip to content

Commit 71b7b76

Browse files
committed
Add docs
1 parent 2574514 commit 71b7b76

File tree

3 files changed

+66
-4
lines changed

3 files changed

+66
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# 1.0.0
2+
_Initial release_

README.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,69 @@
44

55
# <img src="https://raw.githubusercontent.com/SeleniumHQ/seleniumhq.github.io/690acbad7b4bf4656f116274809765db64e6ccf7/website_and_docs/static/images/logos/webdriver.svg" height=24 /> Elements for Selenium
66

7+
Define Selenium HTML elements as Java classes, similar to Selenium's ``@FindBy`` annotation.
8+
9+
Also contains a ton of other predefined utility, for example:
10+
* Automatically scrolling elements that perform operations into the view
11+
* Safe click: When an element is detected as stale a JavaScript click is executed instead
12+
* Option to globally wait until the page finished loading
13+
* Waiting for some time until the element is present (``waitUntil``)
14+
15+
Overall this improves:
16+
* Less [flaky](https://www.browserstack.com/test-reporting-and-analytics/features/test-reporting/what-is-flaky-test) tests
17+
* Abstraction of elements in an object oriented way
18+
19+
## Usage
20+
21+
1. Define the elements you want to access
22+
```java
23+
@FindBySelector(tagName = "body")
24+
abstract class BodyElement implements ImprovedWebElement {
25+
public MyElement myElement() {
26+
return waitForFirst(MyElement.class);
27+
}
28+
}
29+
30+
@FindBySelector(id = "abc")
31+
abstract class MyElement implements ImprovedWebElement {
32+
}
33+
```
34+
2. Utilize the predefined methods and classes to get/access the elements in a test
35+
```java
36+
class MyWebDriverTest implements CanFindElements {
37+
WebDriver webDriver;
38+
39+
@BeforeEach
40+
void beforeEach() {
41+
webDriver = createWebDriver();
42+
CustomizableRemoteWebElementInstaller.install(
43+
webDriver,
44+
() -> new ImprovedRemoteWebElement(
45+
"return document.readyState == 'complete';")
46+
);
47+
}
48+
49+
@Test
50+
void test() {
51+
MyElement myElement = waitForFirst(BodyElement.class).myElement();
52+
assertEquals("Hello world", myElement.getText());
53+
54+
// Or alternatively
55+
ElementInstantiatorInstance.instance().find(webDriver, BodyElement.class);
56+
}
57+
58+
@AfterEach
59+
void afterEach() {
60+
// Stop webDriver here...
61+
webDriver = null;
62+
}
63+
64+
@Override
65+
public WebDriver getWebDriver() {
66+
return webDriver;
67+
}
68+
}
69+
```
770

871
## Installation
972
[Installation guide for the latest release](https://github.com/xdev-software/selenium-elements/releases/latest#Installation)

selenium-elements/src/test/java/software/xdev/selenium/elements/SimpleContainerTest.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,7 @@ void simpleCheck(final Capabilities capabilities)
5353

5454
CustomizableRemoteWebElementInstaller.install(
5555
this.remoteWebDriver,
56-
() -> new ImprovedRemoteWebElement("if (document.readyState != 'complete') {"
57-
+ " return false;"
58-
+ "}"
59-
+ "return true;"));
56+
() -> new ImprovedRemoteWebElement("return document.readyState == 'complete';"));
6057

6158
this.remoteWebDriver.manage().window().maximize();
6259
this.remoteWebDriver.get(capabilities instanceof FirefoxOptions ? "about:support" : "chrome://version");

0 commit comments

Comments
 (0)