-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
yield statement instead of nested callback #367
Comments
Hi @addremove var chai = require("chai");
var chaiAsPromised = require("chai-as-promised");
chai.use(chaiAsPromised);
chai.should();
chaiAsPromised.transferPromiseness = client.transferPromiseness;
client
.remote(options)
.init()
.url('http://www.google.com')
.getTitle().should.eventually.equal("Google"); // true
.end(); Also no nested callbacks: client
.commandA('input').then(function(res) {
if(res.value.length > 2) {
return client.commandB();
} else {
return client.commandC();
}
}).then(function(res) {
// ...
}); What do you think? FYI if you are interested check out the WebdriverIO promise branch. It is almost stable. Only deep assertions with Chai doesn't work yet (e.g. |
so tests will look like describe('test', function() {
before(function(done) {
client.init(done).url('http://webdriverjs.christian-bromann.com/');
});
it('test', function() {
return client.getTitle().should.eventually.equal('WebdriverJS Testpage');
});
after(function(done) {
client.end(done);
});
}); |
Thank you for the sneak peek. I'll definitely check out the branch. Consider this HTML fragment, where I want to click a particular span, only if it's title matches a desired value.
If I want to get element
I was wondering if this can be simplified to something like.
I read in the issues that you are also working on integrating Sizzle. That should also simplify some of the code above (i.e. directly fetching nth element using ".class:eq(n)" ). |
@addremove for your particular case, you can try: `client.click('.label[title="value"]'). This css selector will select the element with class label and with title attrique equal to value. |
@addremove @thibaut-sticky or using xpath like Looking forward to have a simplification for this coming in WebdriverIO. xPath is really powerful (even though it's slow). |
Well but the idea to support yielding sounds great, so I'll keep that open. PR's are welcome! |
@thibaut-sticky : I specifically want @christian-bromann Yes, XPath would help. I'll try out to see if it also supports indexing. (I was subconsciously avoiding XPath due to performance reasons, and this slipped off my mind) |
Since each command returns with a unique promise in |
Got following example working in the var run = require('monocle-js').run;
var webdriverio = require('./index');
var client = webdriverio.remote({
desiredCapabilities: {
browserName: 'phantomjs'
}
});
run(function*() {
yield client.init().url('http://localhost:8080/test/site/www/');
var title = yield client.getTitle();
console.log(title);
yield client.end();
}); The runner basically just need to overwrite the |
Ok so this will be available in the good old callback way: describe('my feature', function() {
it('will do something', function(done) {
browser
.url('http://google.com')
.getTitle().then(function(title) {
console.log(title);
})
.call(done);
});
}); using promises: describe('my feature', function() {
it('will do something', function() {
return browser
.url('http://google.com')
.getTitle().then(function(title) {
console.log(title);
});
});
}); the new fancy generator way: describe('my feature', function() {
it('will do something', function* () {
yield browser.url('http://google.com');
var title = yield browser.getTitle()
console.log(title);
});
}); |
👍 for generators ! Would love to try it out for my next project. Thank you for the good work. |
+1 for generators Christian :-) |
are generators supported in v4? or is the fiber implementation used instead? |
We use fibers in v4 |
Writing tests is quite painless with
Webdriverio
, thanks to the well documented API. Although after a while, I feel my code could be more succinct & readable if there was something like Yiewd forWebdriverIO
, It gets rid of nested callbacks withyield
statements. The library is quite small and on the surface it looks like it might be straightforward to port it. Any thoughts?Here's an example of its usage with
wd
: https://github.com/admc/wd#yiewdP.S. I'm sure the developers are well aware of this but I couldn't find any reference in the issues section, hence bringing it up.
The text was updated successfully, but these errors were encountered: