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 · 8 comments

Comments

Projects
None yet
7 participants
@satispunk

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

This comment has been minimized.

Show comment
Hide comment
@senocular

senocular Sep 26, 2016

Contributor

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.

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

This comment has been minimized.

Show comment
Hide comment
@beatfactor

beatfactor Sep 26, 2016

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.

Member

beatfactor commented Sep 26, 2016

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

@beatfactor beatfactor closed this Sep 26, 2016

@satispunk

This comment has been minimized.

Show comment
Hide comment
@satispunk

satispunk Sep 26, 2016

@senocular @beatfactor Sad but true. Thx for reply

@senocular @beatfactor Sad but true. Thx for reply

@aaronbeall

This comment has been minimized.

Show comment
Hide comment
@aaronbeall

aaronbeall 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.

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

This comment has been minimized.

Show comment
Hide comment
@amatiasq

amatiasq May 23, 2017

Any update here?

Any update here?

@sandeepthukral

This comment has been minimized.

Show comment
Hide comment

Any update?

@codeluggage

This comment has been minimized.

Show comment
Hide comment
@codeluggage

codeluggage Aug 25, 2017

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?

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

This comment has been minimized.

Show comment
Hide comment
@codeluggage

codeluggage 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!

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment