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 and chrome driver installer
Install Node.js and install framework
$ npm i --SD awbDrivers installation
$ awb standalone chrome geckoRun driver selenium-standalone-server or chrome driver
$ awb start standalone #for standalone
$ awb start chrome #for chromedriver
$ awb start gecko #for geckdriveror 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
Base example
const { expect } = require('chai')
const awb = require('awb')
const { client, element } = awb()
describe('Google base example', () => {
let browser = null
const baseURL = 'https://www.google.com.ua/'
//selectors
const submitsearch = '[name="btnK"]'
const inputsearch = '#lst-ib'
const resultsearch = '#ires .g'
//elements
const submitSearch = element(submitsearch).waitForClicable(1000) //lazy element with expected condition
const resultSearch = element(resultsearch).waitForElement(1000) //lazy element with expected condition
const inputSearch = element(inputsearch)
before(async () => {
await client.startDriver()
await client.goTo(baseURL)
})
after(async () => {
await client.closeBrowser()
await client.stopDriver()
})
it('search git hub potapovDim', async () => {
await inputSearch.sendKeys('git hub potapovDim')
await submitSearch.click()
const allTextInSelector = await resultSearch.getText()
expect(allTextInSelector).to.includes('potapovDim')
})
})Api
More about DesiredCapabilities
Client
/*
* config example, optional, this example config is default config
*/
const defautlOpts = {
withStandalone: true, // if true will run selenium standalone server when call start startDriver(), default true
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 browser driver
desiredCapabilities: {
javascriptEnabled: true,
acceptSslCerts: true,
platform: 'ANY',
browserName: 'chrome'
},
timeout: 5000 // time what will wait response from driver
}
const awb = require('awb')
const {client, element, elements} = awb(config)
/*
* awb() returns element, elements, client instance
* if run awb without args, will be used default config from example
*/goTo
const awb = require('awb')
const {client: browser} = awb()
await browser.goTo('https://google.com')
/*
* args url
* type string
*/Keys
const awb = require('awb')
const {element, client: browser }= awb()
const el = element('.test.class')
await el.sendKeys('test name', browser.Keys.ENTER) // for submitlocalStorage
const awb = require('awb')
const {element, client: browser }= awb()
const localStorage = browser.localStorage //getter
// return browser localStorage api get
const token = await localStorage.get('token')
/*
args key = string
return value
*/set
await localStorage.get('token', 'test-token')
/*
args: key = string, value = string
*/ clear
await localStorage.clear()
/*
clear all localStorage data
*/getAll
const data = await localStorage.getAll()
/*
return all localStorage data
*/sessionStorage
const awb = require('awb')
const {element, client: browser }= awb()
const sessionStorage = browser.sessionStorage //getter
// return browser sessionStorage api get
const token = await sessionStorage.get('token')
/*
args key = string
return value
*/set
await sessionStorage.get('token', 'test-token')
/*
args: key = string, value = string
*/ clear
await sessionStorage.clear()
/*
clear all sessionStorage data
*/getAll
const data = await sessionStorage.getAll()
/*
return all sessionStorage data
*/startDriver
const awb = require('awb')
const {element, client: browser }= awb()
await browser.startDriver()
/*
* it will start selenium process
* if selenium standalone chromedriver geckdriver was install
* /stopDriver
await browser.stopDriver()
/*
* it will stop selenium process
* if it was runned by previous command
* /closeCurrentTab
const awb = require('awb')
const {element, client: browser }= awb()
await browser.closeCurrentTab()
/*
* will close current tab
* if opened tabs length more than 1
* /waitForUrlIncludes
const awb = require('awb')
const {element, client: browser }= awb()
await browser.waitForUrlIncludes('test', 1000)
/*
* will wait 1000ms for url includes test
* /switchToFrame
const awb = require('awb')
const {element, client: browser }= awb()
await browser.switchToFrame('#myFrame')
/*
* arg css selector (id , class or some atribute)
* / refresh
const awb = require('awb')
const {element, client: browser }= awb()
await browser.refresh()
/*
* refresh browser current page
* / back
const awb = require('awb')
const {element, client: browser }= awb()
await browser.back()
/*
* browser histor go back
* / forward
const awb = require('awb')
const {element, client: browser }= awb()
await browser.forward()
/*
* browser histor go forward
* / getTitle
const awb = require('awb')
const {element, client: browser }= awb()
const currentTitle = await browser.getTitle()
/*
* will return tab title
* /executeScript
const awb = require('awb')
const {element, client: browser }= awb()
const currentTitle = await browser.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
* /executeScriptAsync
const awb = require('awb')
const {element, client: browser }= awb()
const currentTitle = await browser.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
* /switchToTab
const awb = require('awb')
const {element, client: browser }= awb()
await browser.switchToTab(1)
/* for example if was opened link with _blank
* will switch to opened tab
* /closeBrowser
const awb = require('awb')
const {element, client: browser }= awb()
await browser.closeBrowser()
/* for example if was focused tab from switchToTab example
* this will close current tab and focus you to previous
* /getCurrentBrowserTab
const awb = require('awb')
const {element, client: browser }= awb()
const tabId = await browser.getCurrentBrowserTab()
/* return selenium tab id * /getBrowserTabs
const awb = require('awb')
const {element, client: browser }= awb()
const tabIdS = await browser.getBrowserTabs()
/*
* return array with selenium tab ids
*/sleep
const awb = require('awb')
const {element, client: browser }= awb()
await browser.sleep(1000)
/* args number timeout
* will wait until timeout end
*/getUrl
const awb = require('awb')
const {element, client: browser }= awb()
const currentUrl = await browser.getUrl()
/* return current tab url*/Element
ConstructorElement
const awb = require('awb')
const {element, client: browser }= awb()
const elementDiv = element('div')
/*
* args css selector for example '#id', '[name="name"]', '.class'
*/sendKeys
const awb = require('awb')
const {element, client: browser }= awb()
const elementInput = element('input')
await elementInput.sendKeys('test value')
/*
* args string or array string
*/size
const awb = require('awb')
const {element, client: browser }= awb()
const elementInput = element('input')
const {width, height} = await elementInput.size()
/*
* return element`s width and height
*/location
const awb = require('awb')
const {element, client: browser }= awb()
const elementInput = element('input')
const {y, x} = await elementInput.location()
/*
* return element`s start, x and y where element begins
*/location
const awb = require('awb')
const {element, client: browser }= awb()
const elementInput = element('input')
const {x, y} = await elementInput.locationView()
/*
* return element`s start, x and y where element begins in view port
*/clear
const awb = require('awb')
const {element, client: browser }= awb()
const elementInput = element('input')
await elementInput.clear()
/*
* clear value inside input
*/getElementHTML
const awb = require('awb')
const {element, client: browser }= awb()
const elementInput = element('input')
const inputHTML = await elementInput.getElementHTML()
/*
* return outerHTML of current element , return string
* <input value="a"/> for example
*/getText
const awb = require('awb')
const {element, client: browser }= awb()
const elementDiv = element('div')
const divText = await elementDiv.getText()
/*
* return all text inside element , return string
*/waitForElement
const awb = require('awb')
const {element, client: browser }= awb()
const elementDiv = element('div').waitForElement(1000)
/*
* will wait for element mount to DOM node
*/waitForElementPresent
const awb = require('awb')
const {element, client: browser }= awb()
const elementDiv = element('div').waitForElementPresent(1000)
/*
* will wait for element mount to DOM node
*/waitForClicable
const awb = require('awb')
const {element, client: browser }= awb()
const elementDiv = element('div').waitForClicable(1000)
/*
* will wait for element mount to DOM node
*/waitForElementVisible
const awb = require('awb')
const {element, client: browser }= awb()
const elementDiv = element('div').waitForElementVisible(1000)
/*
* will wait for element visible in DOM node
*/element
const awb = require('awb')
const {element, client: browser }= awb()
const elementSpan = element('div').element('span').element('a')
/*
* return element instanse
*/elements
const awb = require('awb')
const {element, client: browser }= awb()
const elementsSpan = element('div').elements('span')
/*
* return Elements instance
*/getAttribute
const awb = require('awb')
const {element, client: browser }= 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
*/click
const awb = require('awb')
const {element, client: browser }= awb()
const elementSpan = element('div').element('span')
await elementSpan.click()
/*
* triger click
*/isPresent
const awb = require('awb')
const {element, client: browser }= 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
*/isDisplayed
const awb = require('awb')
const {element, client: browser }= 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
*/toElement
const awb = require('awb')
const {element, client: browser }= awb()
const elementSpan = element('div').element('span')
await elementSpan.toElement()
/*
* will scroll view port to element
*/mouseDownAndMove
const awb = require('awb')
const {element, client: browser }= 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
*/Elements
Constructor elements
const awb = require('awb')
const {element, elements, client: browser }= awb()
const elementDiv = elements('div')
// by css selector
const elementsSpan = elements('span')
// by xpath
const elementsDiv = elements('xpath: /html/body/div[1]/div/div/div/div[1]/div[2]/div[2]/div/div')
/*
* args css selector for example '#id', '[name="name"]', '.class' or xpath format xpath: /html/body/div (for example)
* return array Element instaces
*/waitForElements
const awb = require('awb')
const {element, elements, client: browser }= awb()
const elementDiv = elements('div').waitForElements(1000)
/*
* will wait for first element with selector mount to DOM node
*/map
// by css selector
const awb = require('awb')
const {element, elements, client: browser }= awb()
const elementsSpan = elements('span')
const textArr = await elementsSpan.map(async (element) => {
return await element.getText()
})
/*
* args async call back
* return array
*/forEach
const awb = require('awb')
const {element, elements, client: browser }= 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
* /filter
const awb = require('awb')
const {element, elements, client: browser }= 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
* /get
const awb = require('awb')
const {element, elements, client: browser }= awb()
const elementsSpan = elements('span')
const elementWithText = await elementsSpan.get(0)
await elementWithText.getText()
/*
* 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