forked from wookiehangover/wd-query
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Sam Breed
committed
Sep 23, 2013
1 parent
c2d53b9
commit 755aaf9
Showing
5 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,4 @@ logs | |
results | ||
|
||
npm-debug.log | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}; | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.