Krishnan VS
Krishnan VS

Reputation: 1

Protractor with Cucumber - scenario not getting invoked

We are new to using Protractor, have followed the below link to try the test setup. http://maushamgupta.blogspot.com/2016/09/getting-started-with-protractor-cucumber.html

Below is the conf file (named as protractor.conf.js).

var config;
config = {

    //chromeDriver:'path\\to\\your\\chromedriver.exe',
    //seleniumArgs: ['-Dwebdriver.ie.driver=path\\to\\your\\IEDriverServer.exe'], //incase you want to test your application on internet explorer
    seleniumAddress: 'http://127.0.0.1:4444/wd/hub',

    specs: 'testwithpro.feature',

    capabilities: {
          browserName: 'chrome'
       },

    framework: 'custom', // need to add for protractor 3.x and above
    frameworkPath: './node_modules/protractor-cucumber-framework',  // need to add for protractor 
    output:'./output.json',                                                                          //3.x and above

    cucumberOpts: {
          // define your step definitions in this file
          require: ['./testwithpro.js'],
          //format: './node_modules/pretty',
          tags:'false'
       }
};

exports.config = config;

testwithpro.feature

Feature: Testing Application

Scenario: Testing Login Given I am on the login page When I enter username And I enter password And I click on login button Then I should see Homepage

testwithpro.js

var myStepDefinitionsWrapper = function () {

this.Given(/^I am on the login page$/, function (callback) {

  // Write code here that turns the phrase above into concrete actions

  console.log('testing');
  browser.ignoreSynchronization=true; // To be added if the application is non-angular
  browser.driver.manage().window().maximize(); // To maximize the window
  //browser.get("https://www.facebook.com").then(function(){
  //  callback(); // To tell the cucumber that we are done with this step
  //})

            browser.get("https://www.facebook.com");
        browser.wait(function () {
        browser.sleep(10000);
        callback(); // To tell the cucumber that we are done with this step
        }, 20 * 10000);



});

this.When(/^I enter username$/, function (callback) {
  // Write code here that turns the phrase above into concrete actions
element(by.id("email")).sendKeys("[email protected]").then(function(){
  callback();
 });
});

this.When(/^I enter password$/, function (callback) {
  // Write code here that turns the phrase above into concrete actions
  element(by.id("pass")).sendKeys("*****").then(function(){
  callback();
 });
});

this.When(/^I click on login button$/, function (callback) {
  // Write code here that turns the phrase above into concrete actions 
  element(by.id("u_0_l")).click().then(function(){
  callback();
 });
});

};
module.exports = myStepDefinitionsWrapper;

package.json (protractor-cucumber-framework)

"chai": "^4.1.2",
"chai-as-promised": "^7.1.1",
"chai-like": "^0.2.14",
"eslint": "^5.4.0",
"eslint-config-prettier": "^3.0.1",
"eslint-plugin-mocha": "^5.2.0",
"eslint-plugin-prettier": "^2.6.2",
"express": "^4.16.3",
"httpster": "^1.0.4",
"mocha": "^5.2.0",
"multidep": "2.0.2",
"prettier": "^1.14.2",
"protractor": "^5.4.0"

package.json (protractor)

"dependencies": { "@types/q": "^0.0.32", "@types/selenium-webdriver": "^3.0.0", "blocking-proxy": "^1.0.0", "browserstack": "^1.5.1", "chalk": "^1.1.3", "glob": "^7.0.3", "jasmine": "2.8.0", "jasminewd2": "^2.1.0", "optimist": "~0.6.0", "q": "1.4.1", "saucelabs": "^1.5.0", "selenium-webdriver": "3.6.0", "source-map-support": "~0.4.0", "webdriver-js-extender": "2.1.0", "webdriver-manager": "^12.0.6" }, "deprecated": false, "description": "Webdriver E2E test wrapper for Angular.", "devDependencies": { "@types/chalk": "^0.4.28", "@types/glob": "^5.0.29", "@types/jasmine": "^2.5.47", "@types/jasminewd2": "^2.0.0", "@types/minimatch": "^2.0.28", "@types/minimist": "^1.1.28", "@types/node": "^6.0.46", "@types/optimist": "^0.0.29", "body-parser": "~1.15.2", "chai": "~3.5.0", "chai-as-promised": "~5.3.0", "clang-format": "1.0.49", "expect.js": "~0.3.1", "express": "~4.14.0", "gulp": "^3.9.1", "gulp-clang-format": "1.0.23", "gulp-tslint": "^7.0.1", "jshint": "^2.9.2", "lodash": "^4.5.1", "marked": "^0.3.3", "mocha": "2.5.3", "rimraf": "~2.5.3", "run-sequence": "^1.1.5", "semver": "^5.3.0", "tslint": "^4.1.1", "tslint-eslint-rules": "^3.1.0", "typescript": "^2.1.5", "vrsource-tslint-rules": "^4.0.1" },

package.json (cucumber)

"dependencies": { "@babel/polyfill": "^7.2.3", "assertion-error-formatter": "^2.0.1", "bluebird": "^3.4.1", "cli-table3": "^0.5.1", "colors": "^1.1.2", "commander": "^2.9.0", "cross-spawn": "^6.0.5", "cucumber-expressions": "^6.0.0", "cucumber-tag-expressions": "^1.1.1", "duration": "^0.2.1", "escape-string-regexp": "^1.0.5", "figures": "2.0.0", "gherkin": "^5.0.0", "glob": "^7.1.3", "indent-string": "^3.1.0", "is-generator": "^1.0.2", "is-stream": "^1.1.0", "knuth-shuffle-seeded": "^1.0.6", "lodash": "^4.17.10", "mz": "^2.4.0", "progress": "^2.0.0", "resolve": "^1.3.3", "serialize-error": "^3.0.0", "stack-chain": "^2.0.0", "stacktrace-js": "^2.0.0", "string-argv": "0.1.1", "title-case": "^2.1.1", "util-arity": "^1.0.2", "verror": "^1.9.0" }, "deprecated": false, "description": "The official JavaScript implementation of Cucumber.", "devDependencies": { "@babel/cli": "^7.2.3", "@babel/core": "^7.2.2", "@babel/plugin-proposal-function-bind": "^7.2.0", "@babel/preset-env": "^7.2.3", "@babel/register": "^7.0.0", "ansi-html": "^0.0.7", "babel-eslint": "^10.0.1", "babel-plugin-istanbul": "^5.1.0", "babelify": "^10.0.0", "browserify": "16.2.2", "chai": "^4.0.1", "coffee-script": "^1.10.0", "connect": "^3.4.0", "coveralls": "^3.0.0", "dependency-lint": "^5.0.1", "eslint": "^5.10.0", "eslint-config-prettier": "^3.3.0", "eslint-config-standard": "^12.0.0", "eslint-plugin-babel": "^5.3.0", "eslint-plugin-import": "^2.14.0", "eslint-plugin-node": "^8.0.0", "eslint-plugin-prettier": "^3.0.0", "eslint-plugin-promise": "^4.0.1", "eslint-plugin-standard": "^4.0.0", "fs-extra": "^6.0.1", "mocha": "^5.2.0", "mustache": "^2.3.0", "nyc": "^12.0.2", "prettier": "^1.5.2", "serve-static": "^1.10.0", "sinon": "^6.0.0", "sinon-chai": "^3.2.0", "stream-to-string": "^1.1.0", "tmp": "^0.0.33" },

When we run the cmd "protractor protractor.conf.js", the output shown in terminal is this -

[23:02:58] I/launcher - Running 1 instances of WebDriver [23:02:58] I/hosted - Using the selenium server at http://127.0.0.1:4444/wd/hub

0 scenarios 0 steps 0m00.000s [23:03:02] I/launcher - 0 instance(s) of WebDriver still running [23:03:02] I/launcher - chrome #01 passed

It does not process the scenario in the feature file and does not launch the web page defined in the test definition js file. The strange part is that the same output is shown even if we change the specs file name to "1testwithpro.feature" (such that it does not exist). No error is thrown.

Please let us know what we might be doing wrong. Appreciate your help.

Upvotes: 0

Views: 863

Answers (1)

Yevhen Laichenkov
Yevhen Laichenkov

Reputation: 8692

Change specs: 'testwithpro.feature' to specs: ['./testwithpro.feature']

Remove the tags in the cucumberOpts object.

    cucumberOpts: {
      require: ['./testwithpro.js']
   },
   specs: ['./testwithpro.feature']

Upvotes: 0

Related Questions