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

Use cucumber mink from within a node javascript file #326

Open
MattLish opened this issue Dec 5, 2017 · 3 comments
Open

Use cucumber mink from within a node javascript file #326

MattLish opened this issue Dec 5, 2017 · 3 comments

Comments

@MattLish
Copy link

MattLish commented Dec 5, 2017

I want to run cucumber mink using gulp (instead of from the command line).
So to do this, I need to just run mink from a javascript file.

I have tried doing:

const cucumber = require('cucumber');
const Mink = require('cucumber-mink');
Mink.init(cucumber);

and

const { defineSupportCode } = require('cucumber');

defineSupportCode((cucumber) => {
  const Mink = require('cucumber-mink');
  Mink.init(cucumber);
});

However, both times I receive the same error:

TypeError: Path must be a string. Received undefined
    at assertPath (path.js:28:11)
    at Object.relative (path.js:1247:5)
    at getDefinitionLineAndUri (/Users/lishmanm/Documents/workspace/cucumber-test/node_modules/cucumber/lib/support_code_library_builder/define_helpers.js:146:28)
    at Object.BeforeAll (/Users/lishmanm/Documents/workspace/cucumber-test/node_modules/cucumber/lib/support_code_library_builder/define_helpers.js:84:34)
    at Mink.registerHooks (/Users/lishmanm/Documents/workspace/cucumber-test/node_modules/cucumber-mink/src/mink.js:180:14)
    at Mink.init (/Users/lishmanm/Documents/workspace/cucumber-test/node_modules/cucumber-mink/src/mink.js:80:10)
    at Object.<anonymous> (/Users/lishmanm/Documents/workspace/cucumber-test/test.js:3:6)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Function.Module.runMain (module.js:605:10)
    at startup (bootstrap_node.js:158:16)
    at bootstrap_node.js:575:3

Is it possible to run cucumber mink from a javascript file rather than the command line?
Is there something I am missing/not understanding here?

@arnaud-dezandee
Copy link
Owner

Hello @MattLish
If you wish to execute cucumber from your own .js file, you'll have to mimic the initialisation procedure here: https://github.com/cucumber/cucumber-js/blob/master/src/cli/index.js
And then inject mink support code inside this procedure.

hope this helps

@pmestrum
Copy link

pmestrum commented Feb 6, 2018

Hi, I want to add mink to my angular 5 project using protractor-cucumber-framework. I've put a 'onPrepare' in my protractor.conf.js that initializes mink & registers itself to cucumber, and I get the same error as MatLish.

  onPrepare() {
    require('ts-node').register({
      project: 'e2e/tsconfig.e2e.json'
    });

    const Mink = require('cucumber-mink');
    const parameters = {
      driver: {
        logLevel: 'silent',
        desiredCapabilities: {
          browserName: 'chrome',
        },
        port: 9515,
      },
    };
    const cucumber = require('cucumber');

    Mink.configure(parameters);
    Mink.init(cucumber);
  }

On the homepage of mink: http://cucumber-mink.js.org/ it's described how to run with cucumber.js support code, but still uses the deprecated method 'defineSupportCode' which I replaced with the new approach (see my code fragment).
It's not clear to me how to mimic the initialisation procedure myself (cfr your response above). Why isn't Mink.init doing that? What's that paragraph describing on the homepage then?

@matmar10
Copy link

matmar10 commented Aug 5, 2019

@pmestrum where you ever able to find a viable solution for new(er) versions of protractor? If so, would you mind sharing a snippet?

EDIT: note I eventually ended up porting this as it was easier than working around not using protractor natively -- https://github.com/matmar10/protractor-cucumber-mink

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

4 participants