Another webdriver binding
UI automated testing framework powered by Node.js. Uses the Selenium WebDriver API. Uses the ChromeDriver API
Base: lazy elements, chrome driver dirrect connection, own standalone server, chrome and gecko driver installer
Install Node.js and install framework
$ npm i --SD awb
Drivers installation
$ awb standalone chrome gecko
Run driver selenium-standalone-server or chrome driver
$ awb start standalone #for standalone $ awb start chrome #for chromedriver $ awb start gecko #for geckdriver
or postinstall, will install gecko chrome drivers and selenium standalone server
"postinstall": "awb standalone gecko chrome"
Simple as a library
Use with mocha or other test runner
Api
Take a look awbBase example
const awb = const client $ = { const baseURL = 'https://www.google.com.ua/' //selectors const submitsearch = '[name="btnK"]' const inputsearch = '#lst-ib' const resultsearch = '#ires .g' //elements const submitSearch = //lazy element with expected condition const resultSearch = //lazy element with expected condition const inputSearch = // start driver and start driver await client await client // page activity await inputSearch await submitSearch const allTextInSelector = await resultSearch console //output: true // kill browser and stop driver await client await client}
More examples here ->
Element util examples here ->
Api
- Client
- localStorage
- sessionStorage
- alert
- waitForUrlIncludes
- dispatchEvent
- maximizeWindow
- wait
- getRect
- pressKeys
- doubleclick
- waitForTitleInclude
- startDriver
- stopDriver
- switchToFrame
- switchBack
- refresh
- back
- getSize
- forward
- goTo
- goToInNewTab
- closeCurrentTab
- getTitle
- executeScript
- executeScriptAsync
- switchToTab
- close
- getCurrentclientTab
- getclientTabs
- sleep
- getUrl
- takeScreenshot
- saveScreenshot
- Elements alias is $$
- Element alias is $
- element.css
- element.xpath
- element.id
- element.id
- sendKeys
- util
- waitTextContains
- getRect
- getComputedStyle
- clear
- location
- doubleClick
- locationView
- size
- getElementHTML
- getColor
- waitForElementPresent
- waitForElementVisible
- wait
- waitForClickable
- waitUntilDisappear
- getText
- waitForElement
- element
- elements
- getAttribute
- click
- rightClick
- isPresent
- toElement
- isDisplayed
- mouseDownAndMove
More about DesiredCapabilities
Client
/* * config example, optional, this example config is default config */ const defautlOpts = remote: false // if remote true startDriver() will not work, default false directConnect: false // if directConnect true directConnect() will run gecko or chrome driver without selenium standalone server, default false host: 'localhost' // host, default 'localhost' or '127.0.0.1' or '0.0.0.0' port: 4444 // port on what will be runned client driver slowTime: 200 // will delay 200 ms every request desiredCapabilities: javascriptEnabled: true acceptSslCerts: true platform: 'ANY' clientName: 'chrome' timeout: 5000 // time what will wait response from driver const awb = const client $ $$ = /* * awb() returns element, elements, client instance * if run awb without args, will be used default config from example */
goTo
const awb = const client = await client /* * args url * type string */
goToInNewTab
const awb = const client = await client await client // will open facebook in new browser tab /* * args url * type string */
wait
const awb = const client $ = await client await client /* * will wail 5000 ms until appear element with css selector #test */
Keys
const awb = const element client = const el = await el // for submit
getSize
const awb = const element client = const size = await client //{ height: 983, width: 1200 } for example /* * any args * return current window size {height: number, width: number} */
dispatchEvent
const awb = const element client = const div1 = // event listener mouseenter const div2 = // event listener mouseover const div3 = // event listener mouseleave await client await client await client await client // will dispatch event
doubleClick
const awb = const element client = await client // will click button element await client // will click by coordinates /* * args: ElementAWB or object {x: number, y: number} */
alert
const awb = const element client = const alert = clientalert //getter // return client alert api
presskeys
const awb = const client = await client // will press F1, F2, F3 keys /* * args: Keys */
accept
await alertaccept
sendKeys
const awb = const element client = const prompt = clientalert //getter await prompt //set test to prompt box await promptaccept // accept prompt box
dismiss
await alert
getText
const alertText = await alert/*return text from alert*/
maximizeWindow
const awb = const element client = await client // will maximize browser window
localStorage
const awb = const element client = const localStorage = clientlocalStorage //getter // return client localStorage api
get
const token = await localStorage/* args key = string return value*/
set
await localStorage/* args: key = string, value = string*/
clear
await localStorageclear /* clear all localStorage data */
getAll
const data = await localStorage /* return all localStorage data */
sessionStorage
const awb = const element client = const sessionStorage = clientsessionStorage //getter // return client sessionStorage api
pageSource
const awb = const element client = const source = await client // return current window page source
get
const token = await sessionStorage/* args key = string return value*/
set
await sessionStorage/* args: key = string, value = string*/
clear
await sessionStorageclear /* clear all sessionStorage data */
getAll
const data = await sessionStorage /* return all sessionStorage data */
startDriver
const awb = const element client = await client /* * it will start selenium process * if selenium standalone chromedriver geckdriver was install * /
stopDriver
await client /* * it will stop selenium process * if it was runned by previous command * /
closeCurrentTab
const awb = const element client = await client /* * will close current tab * if opened tabs length more than 1 * /
waitForUrlIncludes
const awb = const element client = await client /* * will wait 1000ms for url includes test * /
getRect
const awb = const element client = await client /* * will return object format { height: number, width: number, x: number, y: number } * /
waitForTitleInclude
const awb = const element client = await await client /* * will wait 1000ms for title includes test * /
switchToFrame
const awb = const element client = await client /* * arg element frame * /
switchBack
const awb = const element client = await client // do some action with elements with frame await client /* * return to initial context * /
refresh
const awb = const element client = await client /* * refresh client current page * /
back
const awb = const element client = await client /* * client histor go back * /
forward
const awb = const element client = await client /* * client histor go forward * /
getTitle
const awb = const element client = const currentTitle = await client /* * will return tab title * /
executeScript
const awb = const element client = const currentTitle = await client /* first arg is function or string function ,for example 'return arguments[0]' * if function return value it will be returned * /
executeScriptAsync
const awb = const element client = const currentTitle = await client /* first arg is function or string function ,for example 'return arguments[0]' * if function return value it will be returned * /
switchToTab
const awb = const element client = await client /* for example if was opened link with _blank * will switch to opened tab * /
close
const awb = const element client = await client /* for example if was focused tab from switchToTab example * this will close current tab and focus you to previous * /
getCurrentclientTab
const awb = const element client = const tabId = await client /* return selenium tab id * /
getclientTabs
const awb = const element client = const tabIdS = await client /* * return array with selenium tab ids */
sleep
const awb = const element client = await client /* args number timeout * will wait until timeout end */
getUrl
const awb = const element client = const currentUrl = await client /* return current tab url*/
takeScreenshot
const awb = const client = const screenshot = await client /* return string (base64 encoded image) */
saveScreenshot
const awb = const client = await client await client /* Saves screenshot in png format into `screenshots` folder. Optional parameters are passed as object (second parameter) and might have: path where to save screenshots (path of any nesting levels will be created automatically) format (jpeg) screenshot (by default screenshot will be taken with client.takescreenshot method but it is possible to pass any screenshot as a string) encoding*/
Element
ConstructorElement
const awb = const element client = const elementDiv = /* * args css selector for example '#id', '[name="name"]', '.class' */
element.css
const awb = const element client = const elementDiv = element //args css selector for example '#id', '[name="name"]', '.class' /* * args css selector for example '#id', '[name="name"]', '.class' */
element.xpath
const awb = const element client = const elementDiv = element /* * args xpath */
element.id
const awb = const element client = const elementDiv = elementid'uniq-id' /* * args element id */
sendKeys
const awb = const element client = const elementInput = await elementInput /* * args string or array string */
size
const awb = const element client = const elementInput = const width height = await elementInputsize /* * return element`s width and height */
getRect
const awb = const element client = const elementInput = const width height x y = await elementInput /* * return element`s width and height, and location x, y */
location
const awb = const element client = const elementInput = const y x = await elementInputlocation /* * return element`s start, x and y where element begins */
locationView
const awb = const element client = const elementInput = const x y = await elementInput /* * return element`s start, x and y where element begins in view port */
clear
const awb = const element client = const elementInput = await elementInputclear /* * clear value inside input */
waitTextContains
const awb = const element client = const elementInput = await elementInput /* * will wait until test does not include 'test' */
getElementHTML
const awb = const element client = const elementInput = const inputHTML = await elementInput /* * return outerHTML of current element , return string * <input value="a"/> for example */
getText
const awb = const element client = const elementDiv = const divText = await elementDiv /* * return all text inside element , return string */
getComputedStyle
const awb = const element client = const span = const textAnchorValue = await span /* * will return string with computed style value * /
getColor
const awb = const element client = const elementDiv = const divText = await elementDiv /* * return rgba color */
waitForElement
const awb = const element client = const elementDiv = /* * will wait for element mount to DOM node */
waitForElementPresent
const awb = const element client = const elementDiv = /* * will wait for element mount to DOM node */
wait
const awb = const element client = const elementDiv = /* * will wait for element mount to DOM node */
waitForClickable
const awb = const element client = const elementDiv = /* * will wait for element mount to DOM node */
waitForElementVisible
const awb = const element client = const elementDiv = /* * will wait for element visible in DOM 1000ms */
waitUntilDisappear
const awb = const element client = const elementDiv = await elementDiv await elementDiv // do other /* * will wait for element unmount from DOM 1000ms */
element
const awb = const element client = const elementSpan = /* * return element instanse */
elements
const awb = const element client = const elementsSpan = elements'span' /* * return Elements instance */
elements.css
const awb = const element client = const elementsSpan = elements'span' /* * return Elements instance */
getAttribute
const awb = const element client = const elementSpan = const style = await elementSpan /* * args strin , value name , for example 'value', 'href', 'style' etc * return string of attribute value */
click
const awb = const element client = const elementSpan = await elementSpan /* * triger click */
rightClick
const awb = const element client = const elementSpan = await elementSpan /* * triger click right mouse button */
doubleClick
const awb = const element client = const elementSpan = await elementSpan /* * triger doubleClick */
isPresent
const awb = const element client = const elementSpan = const present = await elementSpan /* * return true if element mounted to DOM * return false if element didn`t mount to DOM */
isDisplayed
const awb = const element client = const elementSpan = const display = await elementSpan /* * return true if visible and in view port * return false if doesn`t visible, for example display: none */
toElement
const awb = const element client = const elementSpan = await elementSpan /* * will scroll view port to element */
mouseDownAndMove
const awb = const element client = const elementSpan = await elementSpan /* * args object with x and y * will mouse down mouse move from x and y from arg */
Elements
Constructor elements
const awb = const element elements client = // by css selector const elementsSpan = // work the same as element.css /* * return array Element instaces */
elements.css
const awb = const element elements client = const elementDiv = // by css selector const elementsSpan = elements // will find element by css selector /* * return array Element instaces */
elements.xpath
const awb = const element elements client = // by css selector const elementsDiv = elements // will find element by xpath /* * return array Element instaces */
waitForElements
const awb = const element elements client = const elementDiv = /* * will wait for first element with selector mount to DOM node */
map
// by css selector const awb = const element elements client = const elementsSpan = const textArr = await elementsSpan /* * args async call back * return array */
forEach
const awb = const element elements client = //by css selector const elementsSpan = const textArr = await elementsSpan /* * args async call back * call async funcs with await * does not return * /
every
const awb = const element elements client = //by css selector const elementsSpan = const textArr = await elementsSpan // if someone element does not includes "test" method will return false /* * args async call back * call async funcs with await * return boolean * /
some
const awb = const element elements client = //by css selector const elementsSpan = const textArr = await elementsSpan /* * args async call back * call async funcs with await * return boolean * /
waitUntilDisappear
const awb = const elements client = const links = await links // will assert that every element with css selector disappear from page /* * will wait for elements unmount from DOM 1000m */
count
const awb = const element elements client = const elementsCount = await /* * return elements quantity, return number * /
filter
const awb = const element elements client = const elementsSpan = const textArr = await elementsSpan /* * args async call back * call async funcs with await * return new elements array * /
get
const awb = const element elements client = const elementsSpan = const elementWithText = elementsSpan await elementWithText /* * args index number * return Element instance * /
Improvement plan
- Run selenium server from a client instance method
- Add possibility find element by xpath (done)
- Develop error handler system
- Develop and improve enviroment installer for every OS
- Develop full util system support
- Fix proxy system for element util