webdriver-helper
This helper library offer lots of friendly api while using JavaScript WebDriver
Getting Started
Install the module with: npm install webdriver-helper
to enable the friendly APIs.
Documentation
You could setup the selenium webdriver like this. Remember to require 'webdriver-helper' to enable friendly apis.
var webdriver = ;;// enable the friendly apis by requiring 'webdriver-helper'; var builder = ;var browser = builder;browser;
Browser API
browser.navigateTo(path)
Go to the path which is relative to current path.
browser;browser;
browser.currentUrl(currHandler)
Get current url.
browser;browser;
browser.refresh()
Refresh current page.
browser.forward()
Go forward to next page in history.
browser.back()
Go back to privious page in history.
browser.title(titleHandler)
Get title in current page.
browsertitle { titleshould;};
Window API
browser.window()
Get current window.
browser.window().position(positionHandler)
Get current window's position.
browser;
browser.window().position(x, y)
Set current window's position to (x, y) relative to screen.
browser;
browser.window().size(sizeHandler)
Get current window's size.
browsersize { widthshould; heightshould;};
browser.window().size(width, height)
Set current window's size with width
and height
.
browsersize500 500
browser.window().maximize()
Maximize the current window to full screen.
Elements API
browser.elements(selector)
Get all matched element by selector. every element could use the friendly api listed below.
browser.elements(selector).count(coundHandler)
Get count of all matched elements.
browserelements'input';
browser.elements(selector).get(index, elemHandler)
Get the element in matched elements according to index.
browserelements'input';
browser.elements(selector).initialized
Get the status that all elements is initialized or not.
browser.elements(selector).init(initedHandler)
Initialize all elements and save inside. In initedHandler, initialized
property will be updated to true
. And you could change asyn-invoking to sync-invoking. For example,
browserelements'input';
browser.element(selector)
Get first matched element by selector.
browser.element(selector).click()
Click the element, the click
method is also used for browser.input()
, browser.dropdownlist()
and browser.link()
element.
browser.element(selector).value(valueHandler)
Get value for the the matched element's value attribute. It could used in browser.input(selector).value()
as well.
browservalue { valshould;};
browser.element(selector).attr(attrName, attrHandler)
Get value of the matched element's attrubute with attribute name attrName
.
browser;
browser.element(selector).css(propertyName, valueHandler)
Get css value of the matched element's css property with name propertyName
.
browser;
browser.element(selector).text(textHandler)
Get the innerText of the matched element.
browsertext { textshould;};
browser.element(selector).html(htmlHandler)
Get the innerHTML of the matched element.
browser;
browser.element(selector).isEnabled(enabledHandler)
Get value for the matched element's status.
browser;
browser.element(selector).isDisplayed(displayedHandler)
Get value for visibility of element.
browser;
browser.input(selector)
Get first matched input
element by selector, it includes textbox, checkbox, radio etc...
browser.input(selector).enter(text)
Enter text into matched textbox.
browser.input(selector).value(valueHandler)
Get value of matched textbox
browser.input(selector).check()
Check matched checkbox.
browser.input(selector).uncheck()
Uncheck matched checkbox.
browser.input(selector).isChecked(checkedHandler)
Get the checked status.
browserinput'input#checkbox'
browser.input(selector).select()
Select matched radio button.
browser.input(selector).isSeleced(selectedHandler)
Get the selected status. Same as isChecked
.
browser.dropdownlist(selector)
Get first matched select
element by selector.
browser.dropdownlist(selector).option(val1/*, val2 ... */)
Select these options with the valus in arguments. If the dropdownlist couldn't be multi-selected, the option with the last value would be selected.
browser.dropdownlist(selector).value(valueHandler)
Get the value for matched dropdownlist.
browser.dropdownlist(selector).values(valuesHandler)
For the multi-selected dropdownlist, it will return array of values.
browser;
browser.link(selector)
Use css selector to find the matched link
browser.link(partialLinkText)
ONLY FOR LINK
browserlink':contains("Partial Link Text")'
browser.exec(script, args, callback)
browser;
Use args
browser;
Use elements
browser
browser.execAsync(script, args, callback)
browser;browser;
Use args
browser;browser;
Use elements
browser;browser;
Alert API
browser.dialog()
Get the dialog which could be alert, confirm, prompt dialog.
browser.dialog().text(textHandler)
Get the text on the dialog.
browser.dialog().accept(thenHandler)
Accept(Ok) the confirm and prompt dialog.
browser.dialog().dismiss(thenHandler)
Dismiss(Cancel) the alert, confirm and prompt dialog.
browser.dialog().enter(text, thenHandler)
Enter text in prompt dialog.
Contributing
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.
Release History
0.2.1 2013-10-20 Add exec
and execAsync
JavaScript support
0.2.0 2013-10-20 Add dialog behaviors
0.1.0 2013-10-17 MVP
License
Copyright (c) 2013 Wang Qiu
Licensed under the MIT license.