sebv/node-wd-sync

Sync vs. Async?

geekdave opened this issue · 4 comments

@sebv, since you went through all the trouble of porting wd to a synchronous API, I figured you must have had a good reason. :)

For someone just starting out with integration testing using Selenium, do you find it easier to create end-to-end tests using a synchronous vs. async API?

I've been playing around with your promise-chain API over on the main project, and I have been struggling a bit with understanding the "magic" of how objects/elements returned from one function in the chain are passed to the next. I'm curious if the sync API might be more "intuitive". On the other hand, I imagine there are cases where the sync API is limited in what it can express (for instance, waiting for two different async functions to complete before moving on in the chain, like you demonstrate using Q.all in the other project).

Just wanted to get your insight about these two approaches. Do each excel at different problems? Is one usually better for "large scale end to end testing"?

Thanks for any advice.

sebv commented

The sync API is easier to start with, and I wrote it because I come from a sync programming background and was annoyed at first with all this callback stuff. I still maintain the project, but I don't use it anymore. I figured it out that if I ever wanted to write sync code, javascript is probably not the best language to do it.

Nowadays I use Q promise everywhere, and use a very functional style to write my code, so using a sync api has become "unnatural".

The logic of keeping the element context is very simple:

  • There is no state passed between calls, except for what the method returns.
  • If the method returns an element the element scope is propagated.
  • If the method returns nothing (click, type etc...) we make the method return the current element, so the element scope is propagated.
  • If the method returns something (text, getAttribute...), the element scope is lost.
  • You can use "<" as the first parameter to get out of the element scope.

Thanks for the detailed response! Just one question:

the element scope is propagated

What is the "data structure" of the element scope? i.e. what properties / API does it expose?

sebv commented

The element class is defined there:
https://github.com/admc/wd/blob/master/lib/element.js

Or just look for element. in the README.

Great, thanks!