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

Give sections a link back to the nightwatch-cucumber api #333

Closed
wants to merge 2 commits into from

Conversation

clayreimann
Copy link

@clayreimann clayreimann commented Jan 16, 2018

This PR allows for the dynamic creation of nightwatch Sections (either from commands or otherwise). Without this reference any Sections created by the user are not tied into nightwatch-cucumber's promises and runtime.

Now possible:

// some-page-object.js
const Section = require('nightwatch/lib/page-object/section');

module.exports = {
  commands: [{
    getScalarSection: function getScalarSection(metric) {
      const selector = `//div[contains(@class, "scalar-container")]//h6[contains(text(), "${metric}")]/..`;
      const props = {
        name: `Scalar - ${metric}`,
        parent: this,
        selector,
        locateStrategy: 'xpath',
        elements: {
          title: {
            selector: `${selector}/h6`,
            locateStrategy: 'xpath'
          },
          value: {
            selector: `${selector}/h1/*`,
            locateStrategy: 'xpath'
          }
        }
      };
      const section = new Section(props);
      this.__nwc.promisifySection(section);
      return section;
    }
  }]
}

@coveralls
Copy link

Coverage Status

Coverage increased (+0.01%) to 94.56% when pulling 2742299 on clayreimann:leave-a-trace into fa29bc9 on mucsi96:master.

@mucsi96
Copy link
Owner

mucsi96 commented Jan 16, 2018

Hi @clayreimann!

Thank you so much for contribution! Wow this is your first contribution! 🎉
I want to clarify the code example you have provided to make sure that this is the best way to solve your issue.

Can you explain where the Section constructor come from?

@clayreimann
Copy link
Author

clayreimann commented Jan 16, 2018

Thanks for the prompt response @mucsi96!

Section is a nightwatch primitive. I've updated the code sample. Basically what I'm trying to do is to achieve dynamic sections similar to this comment on nightwatch#821.

My motivation is that I have many similar components/widgets and I'd like to keep my code reasonably DRY so I'm templating what a widget looks like and then I can call this function to find that particular widget.

@clayreimann
Copy link
Author

Any thoughts @mucsi96?

@mucsi96
Copy link
Owner

mucsi96 commented Jan 17, 2018

Sorry for log reply. I am thinking about patching the Nightwatch Section constructor as it would be more obvious for the user. I need some time to investigate that.

@coveralls
Copy link

coveralls commented Jan 17, 2018

Coverage Status

Coverage remained the same at 94.56% when pulling ef11e9c on clayreimann:leave-a-trace into 893f8bf on mucsi96:master.

@clayreimann
Copy link
Author

@mucsi96 is there anything I can do to help keep this PR alive? I'm more than willing to prototype other ways of achieving this, the project that I'm working will be using this soon.

@clayreimann
Copy link
Author

clayreimann commented Jan 30, 2018

@mucsi96 more ping.

I think I've hit on a cleaner solution (by wrapping the native Section object). I'll add some tests once I ensure this is doing what I want and expect.

@mucsi96
Copy link
Owner

mucsi96 commented Jan 30, 2018

Hi!

This looks much better. I also created a PR with similar solution. Test is included.

#340

Please check it. Can I ask you to add some documentation to it?

You can find it under site\data\index.md

To run the test yarn e2e-test --grep "should enable the usage of section constructor" or npm run e2e-test -- --grep "should enable the usage of section constructor"

One problem I noticed which is not related to this session constructor. That after running the test I cannot run it again. For some reason the phantomJS process does not exit. I have checked that Nightwatch closes the WebDriver session properly. The same behaviour is with Chrome as well.

Will try to investigate that. If you have time would be very helpful if you can also take a look on it.

As of cucumber 4 has parallel execution out of the box I am planning to rewrite this package. And remove a lot of hacks from it. From now I want to use the Nightwatch only for browser controlling. Cucumber will be the only runner. This will simplify the code a lot.

@mucsi96
Copy link
Owner

mucsi96 commented Feb 7, 2018

Fixed by #340

@mucsi96 mucsi96 closed this Feb 7, 2018
@clayreimann clayreimann deleted the leave-a-trace branch February 8, 2018 16:22
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

Successfully merging this pull request may close these issues.

None yet

3 participants