Skip to content

Commit 4701cc1

Browse files
Updated documentation and fixed a bug
1 parent 2440a17 commit 4701cc1

File tree

3 files changed

+224
-3
lines changed

3 files changed

+224
-3
lines changed

README.md

Lines changed: 221 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,40 @@ Implemented in an unopinionated way providing an an easy to understand and use A
1515
- [Component Objects](#component-objects)
1616
- [Page Objects](#page-objects)
1717
- [Put It Together](#put-it-together)
18+
- [Details](#details)
19+
- [Component Objects](#component-objects-1)
20+
- [Import](#import)
21+
- [Constructor](#constructor)
22+
- [clear() => Promise<undefined>](#clear--promiseundefined)
23+
- [click() => Promise<undefined>](#click--promiseundefined)
24+
- [contextClick() => Promise<undefined>](#contextclick--promiseundefined)
25+
- [createComponent(props) => Component](#createcomponentprops--component)
26+
- [createComponents(props) => Promise<Array<Component>>](#createcomponentsprops--promisearraycomponent)
27+
- [doubleClick() => Promise<undefined>](#doubleclick--promiseundefined)
28+
- [dragAndDropTo(target) => Promise<undefined>](#draganddroptotarget--promiseundefined)
29+
- [getAttribute(attrName) => Promise<String|null>](#getattributeattrname--promisestringnull)
30+
- [getCssValue(property) => Promise<String|null>](#getcssvalueproperty--promisestringnull)
31+
- [getRect() => Promise<{height: Number, width: Number, x: Number, y: Number}>](#getrect--promiseheight-number-width-number-x-number-y-number)
32+
- [getTagName() => Promise<String>](#gettagname--promisestring)
33+
- [getText(raw = false) => Promise<String>](#gettextraw--false--promisestring)
34+
- [hoverClick() => Promise<undefined>](#hoverclick--promiseundefined)
35+
- [isDisplayed() => Promise<Boolean>](#isdisplayed--promiseboolean)
36+
- [isEnabled() => Promise<Boolean>](#isenabled--promiseboolean)
37+
- [isPresent() => Promise<Boolean>](#ispresent--promiseboolean)
38+
- [isSelected() => Promise<Boolean>](#isselected--promiseboolean)
39+
- [sendKeys(...args) => Promise<undefined>](#sendkeysargs--promiseundefined)
40+
- [submit() => Promise<undefined>](#submit--promiseundefined)
41+
- [takeScreenshot() => Promise<String>](#takescreenshot--promisestring)
42+
- [waitUntilIsDisplayed(timeout = 10000) => Promise<undefined>](#waituntilisdisplayedtimeout--10000--promiseundefined)
43+
- [waitUntilIsEnabled(timeout = 10000) => Promise<undefined>](#waituntilisenabledtimeout--10000--promiseundefined)
44+
- [waitUntilIsPresent(timeout = 10000) => Promise<undefined>](#waituntilispresenttimeout--10000--promiseundefined)
45+
- [waitUntilIsSelected(timeout = 10000) => Promise<undefined>](#waituntilisselectedtimeout--10000--promiseundefined)
46+
- [Page Objects](#page-objects-1)
47+
- [Import](#import-1)
48+
- [Constructor](#constructor-1)
49+
- [getTitle() => Promise<String>](#gettitle--promisestring)
50+
- [createComponent(props) => Component](#createcomponentprops--component-1)
51+
- [createComponents(props) => Promise<Array<Component>>](#createcomponentsprops--promisearraycomponent-1)
1852

1953
# Usage
2054

@@ -94,11 +128,197 @@ const LoginPage = Require('./login-page');
94128
try {
95129
const driver = await new Builder().forBrowser('chrome').build();
96130
const LoginPage = new LoginPage({ driver });
131+
await LoginPage.goTo();
97132
await LoginPage.LoginForm.login({ username: 'joe', password: 'abcd1234' });
98133
} catch(err) {
99134
console.error(err);
100135
} finally {
101136
await driver.quit();
102137
}
103138
})();
104-
```
139+
```
140+
141+
# Details
142+
143+
`seleniumgenic` has zero dependencies. It mearly takes in a given Selenium [WebDriver](https://www.selenium.dev/selenium/docs/api/javascript/module/selenium-webdriver/index_exports_WebDriver.html) instance and works with it's API. Since the suites of core Selenium packages are constantly updating and only work with the latest versions of browsers, it will be the aim to keep `seleniumgenic` always working with the latest versions of the [selenium-webdriver](https://www.selenium.dev/selenium/docs/api/javascript/index.html).
144+
145+
## Component Objects
146+
147+
Component Objects represent individual or groups of elements on a page. Like with the example above, components could be the individual INPUT elements, or represent a Login form that might be reused on multiple pages in an application.
148+
149+
### Import
150+
151+
```javascript
152+
const { Component } = require('seleniumgenic');
153+
```
154+
155+
### Constructor
156+
157+
Creates a Component instance. Takes a single `props` object as a parameter. Either a Selenium By or Selenium WebElement must be provided.
158+
159+
TIP: While Components can be created via the Constructor, it is highly recommended to make use of the `createComponent(s)` functions of Page and Component classes as they will take care of creating the Component instance with proper `driver` and `scope` properties as well as determining if the By or WebElement should be utilized.
160+
161+
**Props**
162+
- `driver`: The current Selenium WebDriver instance. Required.
163+
- `by`: The Selenium By that is used to locate the Component. If not provided, `webElement` must be provided.
164+
- `scope`: The scope in which to use the By to locate the Component. Must be a WebDriver or Component. Optional, will default to the `driver` if not provided.
165+
- `webElement`: The Selenium WebElement object that represents the Component. If not provided, `by` must be provided.
166+
167+
### clear() => Promise<undefined>
168+
169+
Clears the value if this Component represents an INPUT or TEXTAREA element.
170+
171+
### click() => Promise<undefined>
172+
173+
Clicks this Component.
174+
175+
### contextClick() => Promise<undefined>
176+
177+
Performs a contenxt/right click on this Component.
178+
179+
### createComponent(props) => Component
180+
181+
Convenience method for instantiating a Component within the scope of this Component.
182+
183+
**props**
184+
185+
- `by`: The Selenium By that is used to locate the Component. Required.
186+
- `componentClass`: The class/type of Component that the Component should be created as. Optional, will default to `Component` class.
187+
188+
### createComponents(props) => Promise<Array<Component>>
189+
190+
Creates an array of Components within the scope of this Component.
191+
192+
**props**
193+
194+
- `by`: The Selenium By that is used to locate the Components. Required.
195+
- `componentClass`: The class/type of Component that the Components should be created as. Optional, will default to `Component` class.
196+
197+
### doubleClick() => Promise<undefined>
198+
199+
Performs a double left-click on this Component.
200+
201+
### dragAndDropTo(target) => Promise<undefined>
202+
203+
Performs a drag-and-drop of this Component to another Component.
204+
205+
- `target`: The Component that this Component is to be dropped on.
206+
207+
### getAttribute(attrName) => Promise<String|null>
208+
209+
Gets the current value of the given attribute of this Component.
210+
211+
### getCssValue(property) => Promise<String|null>
212+
213+
Gets the value of a CSS style of this Component.
214+
215+
### getRect() => Promise<{height: Number, width: Number, x: Number, y: Number}>
216+
217+
Gets an object that describes this Component's location and size.
218+
219+
### getTagName() => Promise<String>
220+
221+
Gets the Components HTML tag name.
222+
223+
### getText(raw = false) => Promise<String>
224+
225+
Gets the text contained within this Component. The default is to get the text as it is visually displayed to the user. The 'raw' flag can be used to ge the text as it is provided to the HTML of the page.
226+
227+
- `raw`: Boolean, flag that indicates if the text shoudl be retrieved in its raw form.
228+
229+
### hoverClick() => Promise<undefined>
230+
231+
Performs the actions of hovering the mouse over the Component and then left-clicking it. Great for Components that are not displayed or able to be interacted with unless the Component is hovered over first.
232+
233+
### isDisplayed() => Promise<Boolean>
234+
235+
Gets a value indicating if the Component is currently displayed.
236+
237+
### isEnabled() => Promise<Boolean>
238+
239+
Gets a value indicating if the Component is currently enabled.
240+
241+
### isPresent() => Promise<Boolean>
242+
243+
Gets a value indicating if the Component is present (exists).
244+
245+
### isSelected() => Promise<Boolean>
246+
247+
Gets a value indicating if the Component is currently selected.
248+
249+
### sendKeys(...args) => Promise<undefined>
250+
251+
Types a key sequence on the DOM element that this Component represents. See [WebElement.sendKeys()](https://www.selenium.dev/selenium/docs/api/javascript/module/selenium-webdriver/index_exports_WebElement.html#sendKeys) for more details.
252+
253+
### submit() => Promise<undefined>
254+
255+
Submits the form that this Component is part of, or the form itself if this Component represents a FORM element.
256+
257+
### takeScreenshot() => Promise<String>
258+
259+
Takes a screenshot of visible area of this Component and returns the base-64 encoded PNG.
260+
261+
- `scroll`: Indicates if the Component should be scrolled into view to take the screenshot. Optional.
262+
263+
### waitUntilIsDisplayed(timeout = 10000) => Promise<undefined>
264+
265+
Waits until the Component is displayed.
266+
267+
- `timeout`: The max amout of time (ms) to wait for the condition to be true. Optional, default is 10000.
268+
269+
### waitUntilIsEnabled(timeout = 10000) => Promise<undefined>
270+
271+
Waits until the Component is enabled.
272+
273+
- `timeout`: The max amout of time (ms) to wait for the condition to be true. Optional, default is 10000.
274+
275+
### waitUntilIsPresent(timeout = 10000) => Promise<undefined>
276+
277+
Waits until the Component is present.
278+
279+
- `timeout`: The max amout of time (ms) to wait for the condition to be true. Optional, default is 10000.
280+
281+
### waitUntilIsSelected(timeout = 10000) => Promise<undefined>
282+
283+
Waits until the Component is selected.
284+
285+
- `timeout`: The max amout of time (ms) to wait for the condition to be true. Optional, default is 10000.
286+
287+
## Page Objects
288+
289+
Page Objects represent individual pages of a Web Application and represent collections of Components.
290+
291+
### Import
292+
293+
```javascript
294+
const { Page } = require('seleniumgenic');
295+
```
296+
297+
### Constructor
298+
299+
Creates a Page instance. Takes a single `props` object as a parameter.
300+
301+
**Props**
302+
- `driver`: The current Selenium WebDriver instance. Required.
303+
304+
### getTitle() => Promise<String>
305+
306+
Gets the current page title.
307+
308+
### createComponent(props) => Component
309+
310+
Convenience method for instantiating a Component within the scope of this Page.
311+
312+
**props**
313+
314+
- `by`: The Selenium By that is used to locate the Component. Required.
315+
- `componentClass`: The class/type of Component that the Component should be created as. Optional, will default to `Component` class.
316+
317+
### createComponents(props) => Promise<Array<Component>>
318+
319+
Creates an array of Components within the scope of this Page.
320+
321+
**props**
322+
323+
- `by`: The Selenium By that is used to locate the Components. Required.
324+
- `componentClass`: The class/type of Component that the Components should be created as. Optional, will default to `Component` class.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "seleniumgenic",
3-
"version": "1.0.0",
4-
"description": "Provides Page and Page Component classes and other utilies for working with Selenium",
3+
"version": "1.0.1",
4+
"description": "Utilities to improve projects that utilize selenium-webdriver",
55
"main": "index.js",
66
"repository": {
77
"type": "git",

src/component-object.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ class Component {
246246
* Types a key sequence on the DOM element that this Component represents.
247247
* @see {@link https://www.selenium.dev/selenium/docs/api/javascript/module/selenium-webdriver/index_exports_WebElement.html#sendKeys}
248248
* @param {...any} args The sequence of keys to type.
249+
* @returns {Promise<undefined>}
249250
*/
250251
sendKeys(...args) {
251252
return this.element.sendKeys(args);

0 commit comments

Comments
 (0)