Skip to content

wookiehangover/wd-query

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

wd-query

v0.2.1

jQuery style selectors for wd promises.

tl;dr

In selenium tests with wd, wouldn't it be nice if you could do this:

browser.init()
  .then(function(){
    return $('#email-input').val('[email protected]');
  })
  .then(function(){
    return $('#password-input').val('some_password');
  })
  .then(function(){
    return $('#login-form').submit();
  })
  .then(function(){
    return $('.loggedIn').isDisplayed('loggedIn');
  })
  .then(function(body){
    assert.ok(body);
    browser.quit();
  });

Why jQuery?

Because selectors make sense and so does chaining. Approaching selenium webdriver interactions as starting with selectors makes it easy to combine multi-step sequences into terse and expressive statements.

By mapping wd's webdirver API in chainable constructor, a jQuery-esque API is possible with very little code. This is not jQuery. It just looks like it.

Why wd promises?

Because the nested callback style is unruly for anything complex. Promises are also portable--they can be easily passed around between functions and scopes.

By using the wd promise interface wd-query is able to chain multiple async calls into a unified, selector-driven syntax.

Usage

To use, just pass an initialized wd instance (called browser by convention) to the function exported by wd-query. Note that you must be use wd.promiseRemote.

var wd = require('wd');
var wdQuery = require('wd-query');

var browser = wd.promiseRemote( ... );
var $ = wdQuery(browser);

browser.init()
  .then(function(){
    return $('.open-modal').click()
  })
  .then(function(){
    return $('#modal').get();
  })
  .then(function(elem){
    assert.ok(elem)
    browser.quit();
  });

If you've already called browser.init(), for instance at the start of your test suite, calls to wd-query instances can begin a promise chain.

$('.open-modal').click().then( ... )

Goals

The ultimate goal is to have pairity with the wd API for all actions that work with css selectors while adding support for selecting multiple elements.

Contributing

This is a need-based project, so I only wrote it to account for my needs as of right now. If you have suggestestions, opinions, optimizations or fixes, please fork and pull request to contribute.

License

MIT

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published