3
votes

I'm using the protractor - cucumber framework and can't run my test. A browser is launched but doesn't navigate to my URL and then I receive the following error:

$ protractor conf.js
(node:10648) DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead.
[11:25:05] I/hosted - Using the selenium server at http://127.0.0.1:4444/wd/hub
[11:25:05] I/launcher - Running 1 instances of WebDriver
[11:25:09] E/launcher - Error: TypeError: Cannot call a class as a function
    at exports.default (C:\Source\test\node_modules\babel-runtime\helpers\classCallCheck.js:7:11)
    at Object.Cli (C:\Source\test\node_modules\cucumber\lib\cli\index.js:64:34)
    at C:\Source\test\node_modules\protractor-cucumber-framework\index.js:31:16
    at Function.promise (C:\Source\test\node_modules\q\q.js:682:9)
    at C:\Source\test\node_modules\protractor-cucumber-framework\index.js:24:14
    at _fulfilled (\\hermes\vhd_profiles\VDI_Home_VHD1\modisej\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:834:54)
    at self.promiseDispatch.done (\\hermes\vhd_profiles\VDI_Home_VHD1\modisej\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:863:30)
    at Promise.promise.promiseDispatch (\\hermes\vhd_profiles\VDI_Home_VHD1\modisej\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:796:13)
    at \\hermes\vhd_profiles\VDI_Home_VHD1\modisej\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:556:49
    at runSingle (\\hermes\vhd_profiles\VDI_Home_VHD1\modisej\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:137:13)
    at flush (\\hermes\vhd_profiles\VDI_Home_VHD1\modisej\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:125:13)
    at _combinedTickCallback (internal/process/next_tick.js:67:7)
    at process._tickCallback (internal/process/next_tick.js:98:9)
[11:25:09] E/launcher - Process exited with error code 100

Conf.js

exports.config = {
    seleniumAddress: 'http://127.0.0.1:4444/wd/hub',
   //// getPageTimeout: 60000,
    ////allScriptsTimeout: 500000,
    framework: 'custom',
    // path relative to the current config file
    frameworkPath: require.resolve('protractor-cucumber-framework'),
    capabilities: {
        'browserName': 'chrome'
    },

    // Spec patterns are relative to this directory.
    specs: ['Features/*.feature'],

    baseURL: 'http://localhost:/8080',



    cucumberOpts: {
        require: 'Features/step_definitions/homePage.js',
        tags: false,
        format: undefined,
        profile: false,
        'no-source': true
    }
};

Feature file:

#features/test.feature
Feature: App hub home page

  Scenario: First sample
    Given I go to the app hub site
    When the homepage has loaded
    Then I expect to see title app hub

Step Definitions:

At the moment I have only put in step definitions for statement "Given I go to the app hub site"

The step_definitions are saved in a folder called 'step_definitions' within the 'Features' folder which I have referred to in my conf.js file.

module.exports = function() {       

     this.Given('I go to the app hub site', function (callback) {
        browser.get('http://localhost:8080')
        .then (callback);
     });

};

Any help would be much appreciated.

4

4 Answers

2
votes

This is error is most likely because you are using cucumber 2.0 with protractor-cucumber-framework. Currently they are incompatible please downgrade your cucumber version to 1.3.1 which should solve your problem.

In the meantime good progress is being made to support cucumber 2.0 with protractor-cucumber-framework. You can check out this repo- protractor-cucumber-frameowrk for more details.

0
votes

It may be mismatched package versions causing the trouble. When you run npm list <package-name> what do you get?

I currently have the following in package.json:

"devDependencies": {
    "chai": "^3.5.0",
    "chai-as-promised": "^5.3.0",
    "chai-string": "^1.2.0",
    "cucumber": "^1.0.0",
    "gulp": "^3.9.1",
    "gulp-angular-protractor": "^0.1.1",
    "protractor": "^3.3.0",
    "protractor-cucumber-framework": "^0.6.0"
  },

With that, I'm running with these versions without any trouble:

  • cucumber - 1.3.1
  • protractor-cucumber-framework - 0.6.0
  • protractor - 3.3.0
0
votes

Great, thanks for your help. I am using cucumber 2.0. I found a workaround on the protractor site, and changed my config.js file so the frameworkPath now references the the index.js file, and this worked.

Config.js

/protractor.conf.js

exports.config = {
seleniumAddress: 'http://127.0.0.1:4444/wd/hub',
getPageTimeout: 60000,
allScriptsTimeout: 500000,
framework: 'custom',
// path relative to the current config file
frameworkPath: './index.js',
//frameworkPath: require.resolve('protractor-cucumber-framework'),
capabilities: {
    'browserName': 'chrome'
},
useAllAngular2AppRoots: true,
// Spec patterns are relative to this directory.
specs: ['Features/*.feature'],

baseURL: 'http://localhost/',

cucumberOpts: {
    require: 'Features/step_definitions/homePage.js',
    tags: false,
    format: undefined,
    profile: false,
    'no-source': true
}};
0
votes

this is my index.js File

index.js`

var q = require('q'),
path = require('path'),
glob = require('glob'),
assign = require('object-assign'),
debug = require('debug')('protractor-cucumber-framework'),
Cucumber = require('cucumber'),
state = require('./lib/runState');

/*** Execute the Runner's test cases through Cucumber.
 * @param {Runner} runner The current Protractor Runner.
 * @param {Array} specs Array of Directory Path Strings.
 * @return {q.Promise} Promise resolved with the test results
 */
exports.run = function(runner, specs) {
var results = {};

return runner.runTestPreparer().then(function() {
    var config = runner.getConfig();
    var opts = assign({}, config.cucumberOpts, config.capabilities.cucumberOpts);
    state.initialize(runner, results, opts.strict);

    return q.promise(function(resolve, reject) {
        var cliArguments = convertOptionsToCliArguments(opts);
        cliArguments.push('--require', path.resolve(__dirname, 'lib', 'resultsCapturer.js'));
        cliArguments = cliArguments.concat(specs);

        debug('cucumber command: "' + cliArguments.join(' ') + '"');

        Cucumber.Cli(cliArguments).run(function (isSuccessful) {
            try {
                var complete = q();
                if (runner.getConfig().onComplete) {
                    complete = q(runner.getConfig().onComplete());
                }
                complete.then(function() {
                    resolve(results);
                });
            } catch (err) {
                reject(err);
            }
        });
    });
});

function convertOptionsToCliArguments(options) {
    var cliArguments = ['node', 'cucumberjs'];

    for (var option in options) {
        var cliArgumentValues = convertOptionValueToCliValues(option, options[option]);

        if (Array.isArray(cliArgumentValues)) {
            cliArgumentValues.forEach(function (value) {
                cliArguments.push('--' + option, value);
            });
        } else if (cliArgumentValues) {
            cliArguments.push('--' + option);
        }
    }

    return cliArguments;
}

function convertRequireOptionValuesToCliValues(values) {
    var configDir = runner.getConfig().configDir;

    return toArray(values).map(function(path) {
        // Handle glob matching
        return glob.sync(path, {cwd: configDir});
    }).reduce(function(opts, globPaths) {
        // Combine paths into flattened array
        return opts.concat(globPaths);
    }, []).map(function(requirePath) {
        // Resolve require absolute path
        return path.resolve(configDir, requirePath);
    }).filter(function(item, pos, orig) {
        // Make sure requires are unique
        return orig.indexOf(item) == pos;
    });
}

function convertGenericOptionValuesToCliValues(values) {
    if (values === true || !values) {
        return values;
    } else {
        return toArray(values);
    }
}

function convertOptionValueToCliValues(option, values) {
    if (option === 'require') {
        return convertRequireOptionValuesToCliValues(values);
    } else {
        return convertGenericOptionValuesToCliValues(values);
    }
}

function toArray(values) {
    return Array.isArray(values) ? values : [values];
}};

This isn't a solution, but a workaround and enables me to run my tests successfully.