Skip to content

Wrap promises in async+await to make your testcode easier to deal with... and jasmine parallel runner!

Notifications You must be signed in to change notification settings

tokunbo/nodejsSeleniumWrapper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nodejsSeleniumWrapper (and other stuff)

This is just a wild experiment. I'm tired of .then() everywhere and I'm not the world's biggest fan of nodejs in general, but reading some article somewhere I came to learn of async & await:

UPDATE: Nodejs v8.11.1 has built-in async+await. It's not 100% the same but still works very good, take a look at the branch nodejs_native_asyncawait

It seemed too good to be true so I went to try some things and sure enough, this thing really works and removes the madness of .then(func(){}) chains all over the place. Between that and confusing errors when a promise chain didn't resolve properly, I use to go crazy trying to write selenium tests. When automating a browser I pretty much always want my steps to be synchronous so I decided to see how far I could (ab)use this asyncawait module. Turns out you can really get rid of a lot of the nodejs madness using asyncawait in interesting way. Look atexample.jsto see a selenium test(function main())with no .then()'s in it. Then look atutils.jsto see how I altered a bunch of webdriver methods to stop returning promises and instead make await() fully resolve them before returning to testcode.

  • Other stuff

Besides the functionsawaitSeleniumDriver & awaitWebElements....

  • You'll see insideutils.jsthat I also have a sleep(milliseconds) that you can use.

  • You'll see the makeTimeoutPromise(fnptr,millisecons) method. Any function wrapped by this method, will have access to a this.resolve() and this.reject(). One of them must happen before milliseconds after the function is called or you'll get a timeout. If you give null as the maxRunTime then the promise can run foever.

This may not be too special to hardcore nodejs people out there, but for me async&await takes nodejs from unviable to actually usable. Though I still just pick a synchronous language like ruby/python/etc, if nodejs is a requirement for a project I'm working on, I'd have to be allowed to use asyncawait or I'd just go crazy.

  • And look into the jasmine_tests dir for even more craziness

About

Wrap promises in async+await to make your testcode easier to deal with... and jasmine parallel runner!

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published