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

How to use module.exports? #39

Closed
philipbeadle opened this issue Mar 3, 2016 · 15 comments
Closed

How to use module.exports? #39

philipbeadle opened this issue Mar 3, 2016 · 15 comments

Comments

@philipbeadle
Copy link

Hi :)
How do i use module.exports so i can set up things like a common instance of a browser driver. I'd like to do this.

var driver;
module.exports = function () {
  if (!driver) {
    driver = require('webdriverjs-angular');
    var options = {
      desiredCapabilities: {
        browserName: 'chrome'
      },
      ngRoot: 'body' // main application selector
    };
    console.log('test');
    driver
      .remote(options)
      .init()
      .url('http://127.0.0.1:8080/').then(function () {
      return driver;
    });
  } else {
    return driver
      .url('http://127.0.0.1:8080/').then(function () {
        return driver;
      });
  }
};

But I keep getting

driver.js:2
module.exports = function () {
^
ReferenceError: module is not defined
    at driver.js:2:1
    at ContextifyScript.Script.runInNewContext (vm.js:38:15)
    at Object.exports.runInNewContext (vm.js:69:17)
    at VM.run (/Users/PhilBeadle/.gauge/plugins/js/1.1.0/src/vm.js:19:6)
    at VM.runFile (/Users/PhilBeadle/.gauge/plugins/js/1.1.0/src/vm.js:24:8)
    at /Users/PhilBeadle/.gauge/plugins/js/1.1.0/src/impl-loader.js:9:8
    at Array.forEach (native)
    at Object.loadImpl [as load] (/Users/PhilBeadle/.gauge/plugins/js/1.1.0/src/impl-loader.js:7:68)
    at run (/Users/PhilBeadle/.gauge/plugins/js/1.1.0/src/gauge.js:11:15)
    at Object.<anonymous> (/Users/PhilBeadle/.gauge/plugins/js/1.1.0/src/gauge.js:26:3)

Cheers
Phil

@philipbeadle
Copy link
Author

plugin doesnt appear to be using node so well.

@kaustavdm
Copy link
Contributor

@philipbeadle The test code is executed in a sandbox. We have not exposed everything to the sandbox yet, because we are still trying to figure out what a test runner code will need :-) Looks like we overlooked module.exports in the process.

@renjithgr We need to improve the vm.js wrapper.

@ivanbportugal
Copy link
Contributor

I've definitely had some weird errors trying to fully integrate webdriver.io with gauge-js. For instance, some of the webdriver.io APIs weren't working.

I had trouble selecting values from combo boxes through methods like http://webdriver.io/api/action/selectByName.html

However, CodeceptJS uses webdriver.io too but I have no issues selecting there... If I figure out what the problem is I'll let you guys know but I can't necessarily dedicate too much time on this project on the short term :)

@kaustavdm
Copy link
Contributor

The solution will be custom implementation of require, module, process in gauge-js. Also, we need to set require path correctly. The require path currently includes test_project_root/node_modules. So doing a require() of a relative file will also fail.

All of these would go to src/vm.js.

@philipbeadle
Copy link
Author

Awesome, so glad you're onto it :)

kaustavdm pushed a commit that referenced this issue Mar 29, 2016
Signed-off-by: Kaustav Das Modak <kaustav.dasmodak@yahoo.co.in>
@kaustavdm
Copy link
Contributor

@philipbeadle @ivanbportugal I have pushed a change which addresses most of the issues raised here. It will be very helpful if you can build from source and test and let us know.

@kaustavdm
Copy link
Contributor

Fix in #43 addressed this 🎉

@philipbeadle
Copy link
Author

Awesome Ill give it a crack this weekend.

@ivanbportugal
Copy link
Contributor

Sorry for the radio silence... been busy. I'll definitely check this out when I get a chance. I'll let you know if I have any issues integrating with webdriver.io since that's what I was trying to do in the first place :)

@philipbeadle
Copy link
Author

Hi Ivan Ive added a new brnach on my demo to try to figure this out
https://github.com/philipbeadle/gauge-js-angular-webdriver-demo/tree/1-Using_module.exports_to_hold_Driver

Have a look at this and see if you can figure out why the code in the driver.js file doesnt execute.

@philipbeadle
Copy link
Author

I have done a git pull on gauge-js, packaged it and installed the plugin in this project so it should have the latest code which is supposed to pick up module.exports.

@kaustavdm
Copy link
Contributor

@philipbeadle Sorry for the delay. I was away for a couple of weeks. Did module.exports work for you?

I'll keep this issue reopened till this gets sorted.

@kaustavdm kaustavdm reopened this Apr 26, 2016
@philipbeadle
Copy link
Author

Nope, couldnt get it to work.

@kaustavdm
Copy link
Contributor

@philipbeadle I have created an example at https://github.com/getgauge-contrib/gauge-js/tree/master/examples.

This will eventually contain code examples of all the features. For now, I have added module.exports and require(). It works for me on gauge-js v1.2.0.

I took a quick look at the demo that you have created and I think the issue may be in the way your are creating the driver. When the variable is not in scope and gets repopulated each time. I could not find anything wrong with gauge-js there.

I'll try to take a deeper look next week. If I can, I'll send you some suggestions on how the code can actually work.

@kaustavdm
Copy link
Contributor

This seems to work now. I have tested this over some time.

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

No branches or pull requests

3 participants