axl-browser-tools
v1.1.2
Published
* Injectable browser tools for automated testing * Works across iframes (respecting CORS) * Universally smart-finds HTML elements with single method (by querySelector, by text, by property) * Universally clicks / touches / taps found elements, or given c
Downloads
20
Readme
axl-browser-tools
- Injectable browser tools for automated testing
- Works across iframes (respecting CORS)
- Universally smart-finds HTML elements with single method (by querySelector, by text, by property)
- Universally clicks / touches / taps found elements, or given coordinates, or found element coordinates offset by percentage of its dimensions, across the window frames...
- Collects message-events, dispatches and records macros to auto-respond to PostMessages
- Auto-detects sub-windows / frames through DOM Mutation Observer, injects itself further
- API for plugins
- PIXI Crawler plugin (smart finds, clicks and returns properties of PIXI display objects by selectors)
Use it
Main library bit is to live in browser context. This one leaves in bin
directory,
and is result of building this project.
To be clear - this lib does not provide way to transit it to browser, as this may be implemented in verity of (more and less sophisticated) ways.
Once in browser / window context exposes API to communicate / perform / gather number of aspects.
Transit to context
At least 3 options:
- copy-paste contents of
bin/axl-browser-tools.js
orbin/axl-browser-tools-plugged.js
into page's console - inject it through any browser-driver (e.g. ChromeDriver) executeScript (
test/toolbox/macro.js
does it) - (recommended) make your page loading it as a script (explicitly or through proxy injection)
Use in context
Injected script creates global object with api, which you can access from any window
that axl
was able to further inject itself. Things to block injection would be
for instance CORS frame.
Most of API calls are performed cross-frames.
That means if your page (A) has opened an iframe (B), executing window.axl.find("hello")
would try to find "hello" element in both A and B windows.
window.axl = {
click: {function(selectorConfig){}},
find: {function(selectorConfig){}},
msg: {
getFirst: {function(stringToRegex){}},
getAll: {function(stringToRegex){}},
getOrWait: {function(stringToRegex, timeout){}},
post: {function(messageData){}},
postAndWait: {function(messageData, timeout){}},
autoRespond: {function(messagesAutoResponderData){}},
},
defer: {
add:{function(checker){}},
purgeCheckers:{function(){}},
purgeDeferred:{function(){}},
getDeferred:{function(){}},
},
info: {function},
until: {function(conditionFn, untilConfig){}},
_advanced: {WindowLibInstance}
}
Use it remotely
Import methods from 'axl-browser-tools' to your testing app and benefit from documented API.
Set your remote executor to communicate with window.axl
API.
Example setup
import {cfg, getEvents} from "axl-browser-tools";
// setup driver (eg. chromedriver) on your own
cfg.executor = driver.executeScript.bind(driver);
const messageEvents = await getEvents(`.`);