Skip to content

Simple-Automation-Testing/awb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Another webdriver binding

UI automated testing framework powered by Node.js. Uses the Selenium WebDriver API. Uses the ChromeDriver API

Contributing guide here

Base: lazy elements, chrome driver dirrect connection, own standalone server, chrome and gecko driver installer

npm downloads Build Status 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

Base example

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 ->

Api

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 = require('awb')
  const {client, $, $$} = 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} = awb()
  await client.goTo('https://google.com')
  /*
   * args url
   * type string
   */

goToInNewTab

  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
   */

wait

  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
   */

Keys

  const awb = require('awb')
  const { element, client } = awb()
  const el = element('.test.class')
  await el.sendKeys('test name', client.Keys.ENTER) // for submit

getSize

  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}
   */

dispatchEvent

    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

doubleClick

  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}
   */

alert

  const awb = require('awb')
  const { element, client } = awb()
  const alert = client.alert //getter
  // return client alert api

presskeys

  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
   */

accept

await alert.accept()

sendKeys

  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

dismiss

 await alert.dismiss()

getText

const alertText =  await alert.getText()
/*
return text from alert
*/

maximizeWindow

  const awb = require('awb')
  const { element, client } = awb()
  await client.maximizeWindow()
  // will maximize browser window

localStorage

  const awb = require('awb')
  const { element, client } = awb()
  const localStorage = client.localStorage //getter
 // return client localStorage api

get

const token = await localStorage.get('token')
/*
  args key = string
  return value
*/

set

 await localStorage.set('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 } = awb()
  const sessionStorage = client.sessionStorage //getter
  // return client sessionStorage api

pageSource

  const awb = require('awb')
  const { element, client } = awb()
  const source = await client.pageSource()
  // return current window page source

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 } = awb()
  await client.startDriver()
  /*
   * it will start selenium process
   * if selenium standalone chromedriver geckdriver was install
   * /

stopDriver

  await client.stopDriver()
  /*
   * it will stop selenium process
   * if it was runned by previous command
   * /

closeCurrentTab

  const awb = require('awb')
  const { element, client } = awb()
  await client.closeCurrentTab()
  /*
   * will close current tab
   * if opened tabs length more than 1
   * /

waitForUrlIncludes

  const awb = require('awb')
  const { element, client } = awb()
  await client.waitForUrlIncludes('test', 1000)
  /*
   * will wait 1000ms for url includes test
   * /

getRect

  const awb = require('awb')
  const { element, client } = awb()
  await client.getRect()
  /*
   * will return object format { height: number, width: number, x: number, y: number }
   * /

waitForTitleInclude

  const awb = require('awb')
  const { element, client } = awb()
  await
  await client.waitForTitleInclude('New title', 1000)
  /*
   * will wait 1000ms for title includes test
   * /

switchToFrame

  const awb = require('awb')
  const { element, client } = awb()
  await client.switchToFrame(element('#myFrame'))
  /*
   * arg element frame
   * /

switchBack

  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
   * /

refresh

  const awb = require('awb')
  const { element, client } = awb()
  await client.refresh()
  /*
   * refresh client current page
   * /

back

  const awb = require('awb')
  const { element, client } = awb()
  await client.back()
  /*
   * client histor go back
   * /

forward

  const awb = require('awb')
  const { element, client } = awb()
  await client.forward()
  /*
   * client histor go forward
   * /

getTitle

  const awb = require('awb')
  const { element, client } = awb()
  const currentTitle = await client.getTitle()
  /*
   * will return tab title
   * /

executeScript

  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
   * /

executeScriptAsync

  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
   * /

switchToTab

  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
   * /

close

  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
   * /

getCurrentclientTab

  const awb = require('awb')
  const { element, client } = awb()
  const tabId = await client.getCurrentclientTab()
  /* return selenium tab id * /

getclientTabs

  const awb = require('awb')
  const { element, client } = awb()
  const tabIdS = await client.getclientTabs()
  /*
  * return array with selenium tab ids
  */

sleep

  const awb = require('awb')
  const { element, client } = awb()
  await client.sleep(1000)
  /* args number timeout
  * will wait until timeout end
  */

getUrl

  const awb = require('awb')
  const { element, client } = awb()
  const currentUrl = await client.getUrl()
  /* return current tab url*/

takeScreenshot

  const awb = require('awb')
  const { client } = awb()
  const screenshot = await client.takeScreenshot()
  /* return string (base64 encoded image) */

saveScreenshot

  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*/

Element

ConstructorElement

  const awb = require('awb')
  const { element, client } = awb()
  const elementDiv = element('div')
  /*
  * args css selector for example '#id', '[name="name"]', '.class'
  */

element.css

  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'
  */

element.xpath

  const awb = require('awb')
  const { element, client } = awb()
  const elementDiv = element.xpath('/html/body/div')
  /*
  * args xpath
  */

element.id

  const awb = require('awb')
  const { element, client } = awb()
  const elementDiv = element.id('uniq-id')
  /*
  * args element id
  */

sendKeys

  const awb = require('awb')
  const { element, client } = awb()
  const elementInput = element('input')
  await elementInput.sendKeys('test value')
  /*
  * args string or array string
  */

size

  const awb = require('awb')
  const { element, client } = awb()
  const elementInput = element('input')

  const {width, height} = await elementInput.size()
  /*
  * return element`s width and height
  */

getRect

  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
  */

location

  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
  */

locationView

  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
  */

clear

  const awb = require('awb')
  const { element, client } = awb()
  const elementInput = element('input')
  await elementInput.clear()
  /*
  * clear value inside input
  */

waitTextContains

  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'
  */

getElementHTML

  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
  */

getText

  const awb = require('awb')
  const { element, client } = awb()
  const elementDiv = element('div')
  const divText = await elementDiv.getText()
  /*
  * return all text inside element , return string
  */

getComputedStyle

  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
   * /

getColor

  const awb = require('awb')
  const { element, client } = awb()
  const elementDiv = element('div')
  const divText = await elementDiv.getColor()
  /*
  * return rgba color
  */

waitForElement

  const awb = require('awb')
  const { element, client } = awb()
  const elementDiv = element('div').waitForElement(1000)

  /*
  * will wait for element mount to DOM node
  */

waitForElementPresent

  const awb = require('awb')
  const { element, client } = awb()
  const elementDiv = element('div').waitForElementPresent(1000)
  /*
  * will wait for element mount to DOM node
  */

wait

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
  */

waitForClickable

  const awb = require('awb')
  const { element, client } = awb()
  const elementDiv = element('div').waitForClickable(1000)
  /*
  * will wait for element mount to DOM node
  */

waitForElementVisible

  const awb = require('awb')
  const { element, client } = awb()
  const elementDiv = element('div').waitForElementVisible(1000)
  /*
  * will wait for element visible in DOM 1000ms
  */

waitUntilDisappear

  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
  */

element

  const awb = require('awb')
  const { element, client } = awb()
  const elementSpan = element('div').element('span').element('a')
  /*
  *  return element instanse
  */

elements

  const awb = require('awb')
  const { element, client } = awb()
  const elementsSpan = element('div').elements('span')
  /*
  *  return Elements instance
  */

elements.css

  const awb = require('awb')
  const { element, client } = awb()
  const elementsSpan = element('div').elements('span')
  /*
  *  return Elements instance
  */

getAttribute

  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
  */

click

  const awb = require('awb')
  const { element, client } = awb()
  const elementSpan = element('div').element('span')
  await elementSpan.click()
  /*
  * triger click
  */

rightClick

  const awb = require('awb')
  const { element, client } = awb()
  const elementSpan = element('div').element('span')
  await elementSpan.rightClick()
  /*
  * triger click right mouse button
  */

doubleClick

  const awb = require('awb')
  const { element, client } = awb()
  const elementSpan = element('div').element('span')
  await elementSpan.doubleClick()
  /*
  * triger doubleClick
  */

isPresent

  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
  */

isDisplayed

  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
  */

toElement

  const awb = require('awb')
  const { element, client } = awb()
  const elementSpan = element('div').element('span')
  await elementSpan.toElement()
  /*
  * will scroll view port to element
  */

mouseDownAndMove

  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
  */

Elements

Constructor elements

  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
  */

elements.css

  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
  */

elements.xpath

  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
  */

waitForElements

  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
  */

map

  // 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
  */

forEach

  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
  * /

every

  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
  * /

some

  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
  * /

waitUntilDisappear

  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
  */

count

  const awb = require('awb')
  const { element, elements, client } = awb()
  const elementsCount = await elements('span').count()
  /*
  * return elements quantity, return number
  * /

filter

  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
  * /

get

  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
  * /

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