nightwatchjs / nightwatch

Integrated end-to-end testing framework written in Node.js and using W3C Webdriver API. Developed at @browserstack
https://nightwatchjs.org
MIT License
11.79k stars 1.31k forks source link

How's the order of the multiple steps defined? #298

Closed esamattis closed 8 years ago

esamattis commented 9 years ago

In this example http://nightwatchjs.org/guide#write-tests there is "step one" and "step two" but how Nightwatch.js knows how to run the "step one" before "step two" since the order of the keys in objects are not guaranteed in javascript?

geekdave commented 9 years ago

Relying on key order seems to be frowned-upon, and apparently could stop working any day:

http://stackoverflow.com/questions/9179680/is-it-acceptable-style-for-node-js-libraries-to-rely-on-object-key-order

geekdave commented 9 years ago

While other current Javascript engines enumerate object properties in insertion order, V8 orders properties with numeric keys in numeric order.

(http://book.mixu.net/node/ch4.html - section 4.3)

This means that any step name which is parseable as a number will be inserted above other non-number steps.

So let's say we have steps named:

"foo", "2 foo", "1 bar"

They would get executed in the order you have them defined.

But if you had:

"foo", "2", "1 bar"

They would get executed in the order: "2", "foo", "1 bar"

This is probably unlikely, as most folks would give their test steps descriptive names, and not just a number. But it might be worth calling out in the docs that we're relying on non-spec behavior of V8.

esamattis commented 9 years ago

I really would like to see some other syntax for defining steps. I feel uncomfortable relying on it after years of avoiding doing that...

Suggestion:

module.exports = function(step){

  step("step one", function(browser) {

  });

  step("step two", function(browser) {

  });

};

It would be possible to support this while not breaking the current behavior.

beatfactor commented 8 years ago

Closing due to inactivity and also this is now possible with using mocha runner.