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
Take a look awb Api
const awb = require('awb')
const { client, $ } = awb()
async function findInGoogle_potapovDim() {
const baseURL = 'https://www.google.com.ua/'
//selectors
const submitsearch = '[name="btnK"]'
const inputsearch = '#lst-ib'
const resultsearch = '#ires .g'
//elements
const submitSearch = $(submitsearch).waitForClickable(1000) //lazy element with expected condition
const resultSearch = $(resultsearch).waitForElement(1000) //lazy element with expected condition
const inputSearch = $(inputsearch)
// start driver and start driver
await client.startDriver()
await client.goTo(baseURL)
// page activity
await inputSearch.sendKeys('git hub potapovDim')
await submitSearch.click()
const allTextInSelector = await resultSearch.getText()
console.log(allTextInSelector.includes('potapovDim')) //output: true
// kill browser and stop driver
await client.close()
await client.stopDriver()
}
findInGoogle_potapovDim()
More examples here ->
Element util examples here ->
- 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
/*
* 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 = require('awb')
const {client, $, $$} = awb(config)
/*
* awb() returns element, elements, client instance
* if run awb without args, will be used default config from example
*/
const awb = require('awb')
const {client} = awb()
await client.goTo('https://google.com')
/*
* args url
* type string
*/
const awb = require('awb')
const {client} = awb()
await client.goTo('https://google.com')
await client.goToInNewTab('https://facebook.com')
// will open facebook in new browser tab
/*
* args url
* type string
*/
const awb = require('awb')
const {client, $} = awb()
await client.goTo('https://google.com')
await client.wait(5000, async () => $('#test').isDisplayed(), 'Test error message')
/*
* will wail 5000 ms until appear element with css selector #test
*/
const awb = require('awb')
const { element, client } = awb()
const el = element('.test.class')
await el.sendKeys('test name', client.Keys.ENTER) // for submit
const awb = require('awb')
const { element, client } = awb()
const size = await client.getSize() //{ height: 983, width: 1200 } for example
/*
* any args
* return current window size {height: number, width: number}
*/
const awb = require('awb')
const { element, client } = awb()
const div1 = $('.div___1') // event listener mouseenter
const div2 = $('.div___2') // event listener mouseover
const div3 = $('.div___3') // event listener mouseleave
await client.goTo(pathResolver(file))
await client.dispatchEvent(div1, client.eventsList.mouseEnter)
await client.dispatchEvent(div2, client.eventsList.mouseOver)
await client.dispatchEvent(div3, client.eventsList.mouseLeave)
// will dispatch event
const awb = require('awb')
const { element, client } = awb()
await client.doubleClick($('button')) // will click button element
await client.doubleClick({x: 100, y: 200}) // will click by coordinates
/*
* args: ElementAWB or object {x: number, y: number}
*/
const awb = require('awb')
const { element, client } = awb()
const alert = client.alert //getter
// return client alert api
const awb = require('awb')
const { client } = awb()
await client.presskeys(client.Keys.F1, client.Keys.F2, client.Keys.F3)
// will press F1, F2, F3 keys
/*
* args: Keys
*/
await alert.accept()
const awb = require('awb')
const { element, client } = awb()
const prompt = client.alert //getter
await prompt.sendKeys('test') //set test to prompt box
await prompt.accept() // accept prompt box
await alert.dismiss()
const alertText = await alert.getText()
/*
return text from alert
*/
const awb = require('awb')
const { element, client } = awb()
await client.maximizeWindow()
// will maximize browser window
const awb = require('awb')
const { element, client } = awb()
const localStorage = client.localStorage //getter
// return client localStorage api
const token = await localStorage.get('token')
/*
args key = string
return value
*/
await localStorage.set('token', 'test-token')
/*
args: key = string, value = string
*/
await localStorage.clear()
/*
clear all localStorage data
*/
const data = await localStorage.getAll()
/*
return all localStorage data
*/
const awb = require('awb')
const { element, client } = awb()
const sessionStorage = client.sessionStorage //getter
// return client sessionStorage api
const awb = require('awb')
const { element, client } = awb()
const source = await client.pageSource()
// return current window page source
const token = await sessionStorage.get('token')
/*
args key = string
return value
*/
await sessionStorage.get('token', 'test-token')
/*
args: key = string, value = string
*/
await sessionStorage.clear()
/*
clear all sessionStorage data
*/
const data = await sessionStorage.getAll()
/*
return all sessionStorage data
*/
const awb = require('awb')
const { element, client } = awb()
await client.startDriver()
/*
* it will start selenium process
* if selenium standalone chromedriver geckdriver was install
* /
await client.stopDriver()
/*
* it will stop selenium process
* if it was runned by previous command
* /
const awb = require('awb')
const { element, client } = awb()
await client.closeCurrentTab()
/*
* will close current tab
* if opened tabs length more than 1
* /
const awb = require('awb')
const { element, client } = awb()
await client.waitForUrlIncludes('test', 1000)
/*
* will wait 1000ms for url includes test
* /
const awb = require('awb')
const { element, client } = awb()
await client.getRect()
/*
* will return object format { height: number, width: number, x: number, y: number }
* /
const awb = require('awb')
const { element, client } = awb()
await
await client.waitForTitleInclude('New title', 1000)
/*
* will wait 1000ms for title includes test
* /
const awb = require('awb')
const { element, client } = awb()
await client.switchToFrame(element('#myFrame'))
/*
* arg element frame
* /
const awb = require('awb')
const { element, client } = awb()
await client.switchToFrame('#myFrame')
// do some action with elements with frame
await client.switchBack()
/*
* return to initial context
* /
const awb = require('awb')
const { element, client } = awb()
await client.refresh()
/*
* refresh client current page
* /
const awb = require('awb')
const { element, client } = awb()
await client.back()
/*
* client histor go back
* /
const awb = require('awb')
const { element, client } = awb()
await client.forward()
/*
* client histor go forward
* /
const awb = require('awb')
const { element, client } = awb()
const currentTitle = await client.getTitle()
/*
* will return tab title
* /
const awb = require('awb')
const { element, client } = awb()
const currentTitle = await client.executeScript(function () {
const [cssSelector] = arguments
return document.querySelector(cssSelector).innerHTML
}, 'body')
/* first arg is function or string function ,for example 'return arguments[0]'
* if function return value it will be returned
* /
const awb = require('awb')
const { element, client } = awb()
const currentTitle = await client.executeScriptAsync(function () {
const [callback] = arguments
fetch('http://localhost:8085/bar', {
node: 'no-cors'
}).then(resp => resp.json()).then(callback)
})
/* first arg is function or string function ,for example 'return arguments[0]'
* if function return value it will be returned
* /
const awb = require('awb')
const { element, client } = awb()
await client.switchToTab(1)
/* for example if was opened link with _blank
* will switch to opened tab
* /
const awb = require('awb')
const { element, client } = awb()
await client.close()
/* for example if was focused tab from switchToTab example
* this will close current tab and focus you to previous
* /
const awb = require('awb')
const { element, client } = awb()
const tabId = await client.getCurrentclientTab()
/* return selenium tab id * /
const awb = require('awb')
const { element, client } = awb()
const tabIdS = await client.getclientTabs()
/*
* return array with selenium tab ids
*/
const awb = require('awb')
const { element, client } = awb()
await client.sleep(1000)
/* args number timeout
* will wait until timeout end
*/
const awb = require('awb')
const { element, client } = awb()
const currentUrl = await client.getUrl()
/* return current tab url*/
const awb = require('awb')
const { client } = awb()
const screenshot = await client.takeScreenshot()
/* return string (base64 encoded image) */
const awb = require('awb')
const { client } = awb()
await client.saveScreenshot('someName')
await client.saveScreenshot('someName', {
path: '/dev/null',
format: 'jpeg',
screenshot: 'encoded string',
encoding: 'customEncoding',
})
/* 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*/
const awb = require('awb')
const { element, client } = awb()
const elementDiv = element('div')
/*
* args css selector for example '#id', '[name="name"]', '.class'
*/
const awb = require('awb')
const { element, client } = awb()
const elementDiv = element.css('div') //args css selector for example '#id', '[name="name"]', '.class'
/*
* args css selector for example '#id', '[name="name"]', '.class'
*/
const awb = require('awb')
const { element, client } = awb()
const elementDiv = element.xpath('/html/body/div')
/*
* args xpath
*/
const awb = require('awb')
const { element, client } = awb()
const elementDiv = element.id('uniq-id')
/*
* args element id
*/
const awb = require('awb')
const { element, client } = awb()
const elementInput = element('input')
await elementInput.sendKeys('test value')
/*
* args string or array string
*/
const awb = require('awb')
const { element, client } = awb()
const elementInput = element('input')
const {width, height} = await elementInput.size()
/*
* return element`s width and height
*/
const awb = require('awb')
const { element, client } = awb()
const elementInput = element('input')
const {width, height, x, y } = await elementInput.getRect()
/*
* return element`s width and height, and location x, y
*/
const awb = require('awb')
const { element, client } = awb()
const elementInput = element('input')
const {y, x} = await elementInput.location()
/*
* return element`s start, x and y where element begins
*/
const awb = require('awb')
const { element, client } = awb()
const elementInput = element('input')
const {x, y} = await elementInput.locationView()
/*
* return element`s start, x and y where element begins in view port
*/
const awb = require('awb')
const { element, client } = awb()
const elementInput = element('input')
await elementInput.clear()
/*
* clear value inside input
*/
const awb = require('awb')
const { element, client } = awb()
const elementInput = element('button').waitTextContains('test', 2500)
await elementInput.click()
/*
* will wait until test does not include 'test'
*/
const awb = require('awb')
const { element, client } = awb()
const elementInput = element('input')
const inputHTML = await elementInput.getElementHTML()
/*
* return outerHTML of current element , return string
* <input value="a"/> for example
*/
const awb = require('awb')
const { element, client } = awb()
const elementDiv = element('div')
const divText = await elementDiv.getText()
/*
* return all text inside element , return string
*/
const awb = require('awb')
const { element, client } = awb()
const span = element('span')
const textAnchorValue = await span.getComputedStyle(span.computedStyleList.textAnchor)
/*
* will return string with computed style value
* /
const awb = require('awb')
const { element, client } = awb()
const elementDiv = element('div')
const divText = await elementDiv.getColor()
/*
* return rgba color
*/
const awb = require('awb')
const { element, client } = awb()
const elementDiv = element('div').waitForElement(1000)
/*
* will wait for element mount to DOM node
*/
const awb = require('awb')
const { element, client } = awb()
const elementDiv = element('div').waitForElementPresent(1000)
/*
* will wait for element mount to DOM node
*/
const awb = require('awb')
const { element, client } = awb()
const elementDiv = element('div').wait(1000, async (el) => await el.getText() ==='test')
/*
* will wait for element mount to DOM node
*/
const awb = require('awb')
const { element, client } = awb()
const elementDiv = element('div').waitForClickable(1000)
/*
* will wait for element mount to DOM node
*/
const awb = require('awb')
const { element, client } = awb()
const elementDiv = element('div').waitForElementVisible(1000)
/*
* will wait for element visible in DOM 1000ms
*/
const awb = require('awb')
const { element, client } = awb()
const elementDiv = element('div').waitForElementVisible(1000)
await elementDiv.click()
await elementDiv.waitUntilDisappear(10000)
// do other
/*
* will wait for element unmount from DOM 1000ms
*/
const awb = require('awb')
const { element, client } = awb()
const elementSpan = element('div').element('span').element('a')
/*
* return element instanse
*/
const awb = require('awb')
const { element, client } = awb()
const elementsSpan = element('div').elements('span')
/*
* return Elements instance
*/
const awb = require('awb')
const { element, client } = awb()
const elementsSpan = element('div').elements('span')
/*
* return Elements instance
*/
const awb = require('awb')
const { element, client } = awb()
const elementSpan = element('div').element('span')
const style = await elementSpan.getAttribute('style')
/*
* args strin , value name , for example 'value', 'href', 'style' etc
* return string of attribute value
*/
const awb = require('awb')
const { element, client } = awb()
const elementSpan = element('div').element('span')
await elementSpan.click()
/*
* triger click
*/
const awb = require('awb')
const { element, client } = awb()
const elementSpan = element('div').element('span')
await elementSpan.rightClick()
/*
* triger click right mouse button
*/
const awb = require('awb')
const { element, client } = awb()
const elementSpan = element('div').element('span')
await elementSpan.doubleClick()
/*
* triger doubleClick
*/
const awb = require('awb')
const { element, client } = awb()
const elementSpan = element('div').element('span')
const present = await elementSpan.isPresent()
/*
* return true if element mounted to DOM
* return false if element didn`t mount to DOM
*/
const awb = require('awb')
const { element, client } = awb()
const elementSpan = element('div').element('span')
const display = await elementSpan.isDisplayed()
/*
* return true if visible and in view port
* return false if doesn`t visible, for example display: none
*/
const awb = require('awb')
const { element, client } = awb()
const elementSpan = element('div').element('span')
await elementSpan.toElement()
/*
* will scroll view port to element
*/
const awb = require('awb')
const { element, client } = awb()
const elementSpan = element('div').element('span')
await elementSpan.mouseDownAndMove({x: 100, y: 0})
/*
* args object with x and y
* will mouse down mouse move from x and y from arg
*/
const awb = require('awb')
const { element, elements, client } = awb()
// by css selector
const elementsSpan = elements('span')// work the same as element.css
/*
* return array Element instaces
*/
const awb = require('awb')
const { element, elements, client } = awb()
const elementDiv = elements('div')
// by css selector
const elementsSpan = elements.css('span') // will find element by css selector
/*
* return array Element instaces
*/
const awb = require('awb')
const { element, elements, client } = awb()
// by css selector
const elementsDiv = elements.xpath('/html/body/div') // will find element by xpath
/*
* return array Element instaces
*/
const awb = require('awb')
const { element, elements, client } = awb()
const elementDiv = elements('div').waitForElements(1000)
/*
* will wait for first element with selector mount to DOM node
*/
// by css selector
const awb = require('awb')
const { element, elements, client } = awb()
const elementsSpan = elements('span')
const textArr = await elementsSpan.map(async (element) => {
return await element.getText()
})
/*
* args async call back
* return array
*/
const awb = require('awb')
const { element, elements, client } = awb()
//by css selector
const elementsSpan = elements('span')
const textArr = await elementsSpan.forEach(async (element) => {
const html = await element.getElementHTML()
expect(html).to.includes('dropitem')
expect(html).to.includes('draggable="true"')
})
/*
* args async call back
* call async funcs with await
* does not return
* /
const awb = require('awb')
const { element, elements, client } = awb()
//by css selector
const elementsSpan = elements('span')
const textArr = await elementsSpan.every(async (element) => {
return (await element.getText()).includes('test') // if every element test includes "test" method will return true
}) // if someone element does not includes "test" method will return false
/*
* args async call back
* call async funcs with await
* return boolean
* /
const awb = require('awb')
const { element, elements, client } = awb()
//by css selector
const elementsSpan = elements('span')
const textArr = await elementsSpan.some(async (element) => {
return (await element.getText()).includes('test') // if someone element includes "test" method will return false
})
/*
* args async call back
* call async funcs with await
* return boolean
* /
const awb = require('awb')
const { elements, client } = awb()
const links = element('a')
await links.waitUntilDisappear(10000) // will assert that every element with css selector disappear from page
/*
* will wait for elements unmount from DOM 1000m
*/
const awb = require('awb')
const { element, elements, client } = awb()
const elementsCount = await elements('span').count()
/*
* return elements quantity, return number
* /
const awb = require('awb')
const { element, elements, client } = awb()
const elementsSpan = elements('span')
const textArr = await elementsSpan.filter(async (element) => {
const html = await element.getElementHTML()
return html.includes('class="test"')
})
/*
* args async call back
* call async funcs with await
* return new elements array
* /
const awb = require('awb')
const { element, elements, client } = awb()
const elementsSpan = elements('span')
const elementWithText = elementsSpan.get(3)
await elementWithText.getText()
/*
* args index number
* return Element instance
* /
- 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