Code Monkey home page Code Monkey logo

nodejsseleniumwrapper's Introduction

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

nodejsseleniumwrapper's People

Contributors

tokunbo avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.