Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Breed committed Sep 23, 2013
1 parent c2d53b9 commit 755aaf9
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ logs
results

npm-debug.log
node_modules
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,42 @@
wd-query
========

jQuery style selectors for [wd]().

### tl;dr

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

```javascript
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 $('body').hasClass('loggedIn');
})
.then(function(body){
assert.ok(body);
browser.quit();
});
```

### Why jQuery

Because selector's 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.

### Why wd promises?

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

By using the wd promise interface wd-query is able to chain multiple async calls
into a unified syntax.
41 changes: 41 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
module.exports = function(browser){

var wdQuery = function( selector ){
if( !(this instanceof wdQuery) ){
return new wdQuery(selector);
}

this.selector = selector;
return this;
};

var $ = browser.elementByCssSelector;

wdQuery.fn = wdQuery.prototype = {

get: function(selector){
selector = selector || this.selector;
return browser.elementByCssSelector(selector);
},

val: function(value){
return this.get()
.then(function(elem){
return value ? elem.type(value) : elem.getValue();
});
},

click: function(){
return this.get()
.then(function(elem){
elem.click();
});
}

};

return function(selector, context){
return new wdQuery(selector, context);
};

};
27 changes: 27 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "wd-query",
"version": "0.0.0",
"description": "A jQuery-esue wrapper for wd",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "[email protected]:wookiehangover/wd-query.git"
},
"keywords": [
"wd",
"selenium",
"automation"
],
"author": "wookiehangover",
"license": "MIT",
"bugs": {
"url": "https://github.com/wookiehangover/wd-query/issues"
},
"devDependencies": {
"grunt": "~0.4.1",
"grunt-mocha-selenium": "~0.4.0"
}
}
Empty file added test/index.js
Empty file.

0 comments on commit 755aaf9

Please sign in to comment.