Yiewd
Yiewd is a Wd.js wrapper that uses V8's new
generators for cleaner code! It's called yiewd
because it uses the new
yield
syntax with wd
. yield
+ wd
= yiewd
. Amazing, right? And a great
way to exercise vowel pronunciation.
Yiewd is made possible with the monocle-js library.
Install with: npm install yiewd
The problem
Let's say we want to write a webdriver test:
var wd = driver = wd; driver;
Yeah, that sucks. Look at that callback pyramid! Look at all those repetitive error checks!
The (generator-based) solution
Let's all be a little more sane, shall we?
var yiewd = driver = yiewd; driver;
Niiice.
How it works
Basically, you get a driver object as a result of the call to wd.remote()
.
You can use this driver object inside a monocle o-routine to yield
to
asynchronous function execution rather than using callbacks. And you'll get the
result of the callback as the assignment to the yield expression!
Once you have a driver object, you can use driver.run
as a way to kick off
a series of commands inside a generator. Here you have access to the driver
object as this
, so you can do things like yield this.get("http://mysite.com")
.
Integrating with test suites
It's relatively easy to break up bits of sessions between testcases and so on. Here's what a simple mocha test suite could look like:
var yiewd = ; ;
Notice how you get a driver
object from yiewd.remote()
. You can hold onto
this and later use driver.run()
and pass it another generator which will take
over execution for the driver. Easy!
Composing functionality
Using monocle-js, you can compose your own custom automation behaviors:
var o_O = o_O yiewd = driver = yiewd; var flow1 = ; var flow2 = ; ;
Chaining driver calls
Often in WebDriver-land, you only want to find an element in order to do something with it. In those cases, it's a bit tedious to do something like this:
var el1 = driver;var text = el1text;textshould;
Of course, using Javascript™ we can already "chain" these calls:
var text = drivertext;textshould;
But we have this goofy double-yield business. So Yiewd lets you do away with it:
var text = drivertexttextshould;
Integrating with Sauce Labs
We've got some special sauce so you can sauce while you Sauce:
var yiewd = driver = yiewd; driver;
Probably the pass/fail reporting would be handled in some kind of global tearDown method, of course.
Requirements
Either:
- Node >= 0.11.3 (one with generators)
- Make sure you start your test runner with the
--harmony
flag; this might be non-trivial but for mocha, see below.
Or:
-
Any recent node
-
Run your test scripts through regenerator to get generator support, e.g.:
regenerator my_test.js > my_test_es5.js && mocha my_test_es5.js
And:
- For running tests:
npm install -g mocha
Run the Tests
Make sure you have your chromedriver-enabled Selenium server running, then:
mocha -R spec -t 60000 --harmony test/es6/
Architecture
This is a simple wrapper around Wd.js that is really easy to maintain: (a) new methods from Wd.js can be added with one word in Yiewd, (b) there's nothing really to maintain beyond the generator glue which should stabilize quickly.
Contributing
Give it a whirl and contribute bugfixes! Pull requests welcome. Biggest area of need right now is filling out our testsuite to make sure everything works correctly.