webautomator
Web automation using rendered web context
Installation
webautomator
may be installed via npm with
npm install webautomator
You will need to also install and set-up selenium-webdriver.
Usage
The demo below is included in the example
directory. You may also find the tests to be helpful.
const Builder = ;const WebAutomator = ;; { const driver = ; const automator = driver; try await driver; await automator; await automator; await automator; await automator; await automator; await automator; finally await driver; };
node example/demo.js
Documentation
Getting Started
To get started you need to create a WebDriver
instance for WebAutomator
to use. See Using the Builder API - selenium-webdriver - npm for details.
With a WebDriver
instance ready you can no instantiate an instance of the WebAutomator
class which will use the underlying WebDriver
instance for all of its browser calls:
const Builder = ;const WebAutomator = ; const webDriver = ;const webAutomator = webDriver;
API
Elements are located by preceding text, by placeholder
attributes (input
and textarea
elements), and by title
attributes.
get
Get properties such as widget values and options from elements on the page.
Examples:
-
Get the options for a
select
element preceded by the text "Gender":const genderOptions = await webAutomatoroptions; -
Get the value of a text input element which is either preceded by the text "First Name" or has a
placeholder
attribute value of"First Name"
:const firstName = await webAutomatorvalue; -
Get the values for a compound date element which consists of a month select element, a day number input, and a year number input:
const month day year = await webAutomator;Note that in this case, the property names
month
,day
, andyear
are arbitrary. They could be nameda
,b
,c
if you wanted them to be named such. The...names
invalues(...names)
is simply a list of names to assign each value to.
set
Sets form widget values (input
, textarea
, select
).
Examples:
-
Set the value of a text input preceded by the text "Last Name" to
"Byers"
:await webAutomator; -
Set the values in a compound date element which consists of a month select element, a day number input, and a year number input:
await webAutomator;
click
Clicks elements on the page.
Examples:
-
Click a "Submit" button:
await webAutomator; -
Click a label associated with a radio input to toggle its
checked
attribute:await webAutomator;
can.spy
Determines if some text is displayed on the page.
Example:
if await webAutomatorcan // do something
can.not.spy
Determines if some text is not displayed on the page.
if await webAutomatorcannot // do something
after
Allows narrowing the scope of the searched context on the page to be explicitly after some text.
Example:
await webAutomator;
before
Allows narrowing the scope of the searched context on the page to be explicitly before some text.
Example:
await webAutomator;
between
Allows narrowing the scope of the searched context on the page to be explicitly between some texts.
Example:
await webAutomator;
getContent
(Experimental)
Gets an XML representation using markup derived from WAI-ARIA roles.
May be used in snapshot testing.
Example:
;
Example snapshot serialization
Parent Information First Name: Last Name: Gender: Male Female Child Information First Name: Last Name: Gender: Male Female Date of Birth: Shipping Information Ground 2-Day 1-Day Shipping Options Gift wrapped? Warranty? Returnable? Confirmation I confirm that these details are accurate.