Skip to content
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

ES6 classes for commands #1199

Closed
satispunk opened this issue Sep 26, 2016 · 10 comments
Closed

ES6 classes for commands #1199

satispunk opened this issue Sep 26, 2016 · 10 comments

Comments

@satispunk
Copy link

Hi, is it possible to use es6 classes for commands?

modules.exports = class CustomCommand() {
    command() {
   }
}

At the moment I got such error: Class constructor CreateHubCommand cannot be invoked without 'new'

Any plans to support this?

@senocular
Copy link
Contributor

senocular commented Sep 26, 2016

Nightwatch is written in ES5 and uses ES5-style class definitions to implement custom command classes. This involves subclassing custom commands and calling their constructors for super on the subclass. Because ES6 does not allow callable constructors, they are not compatible with this approach. Basically its the problem of:

class SuperClass {} // ES6

function SubClass () { // ES5
    SuperClass.call(this); // equiv of super()
}

new SubClass(); // constructor err

So to answer your first question: No, this isn't currently supported. I also doubt there's any pre-existing plan to change that, but that's what these issues are for.

@beatfactor
Copy link
Member

There is a plan to write nightwatch in ES6, but that will take some time. Until then, I'm afraid we cannot support this.

@satispunk
Copy link
Author

@senocular @beatfactor Sad but true. Thx for reply

@aaronbeall
Copy link

aaronbeall commented Mar 24, 2017

@beatfactor Just curious, is there any roadmap or update on when an ES6 class API might be available? I'd like to know because it would mean we could use TypeScript (ES6 classes + static typing). We can use TS now but the the compiler has a hard time following our code because of the behind-the-scenes magic that Nightwatch does. Cheers.

@amatiasq
Copy link

Any update here?

@sandeepthukral
Copy link

Any update?

@codeluggage
Copy link

I wrote a small snippet that converts basic ES6 classes (test suites or page objects) to Nightwatch compatible objects. We just pass our ES6 classes through this function and get an object out the other end that we export for Nightwatch.

Could this be useful for people in this thread?

@codeluggage
Copy link

codeluggage commented Aug 28, 2017

Here is the Gist for converting ES6 classes to Nightwatch compatible objects. It doesn't cover sections yet, but that should be a small change.

It does require the class to be written in a specific way - if your classes look different then you can just modify it to fit that. There is a page object and a test suite example at the bottom of the gist to show how you need to structure your classes to export them with that function. Hope it can help someone!

@dowenb
Copy link

dowenb commented Oct 7, 2018

It has been a a year or more since last response. Any update on ES6 re-write?

@johannesjo
Copy link

Still nothing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants