protractorchaicucumberjschai-as-promised

Protractor tests are passing but didn't execute the tests


I am new to java script protractor cucumber framework.

I can see similar issue raised here an year ago but this was fixed in a protractor release an year ago as well. hence raising a new question.

I am using latest version of cucumber, protractor, protractor-cucumber-framework, chai, chai-as-promised. I am using visual studio code as editor. Node Version is 6.11.4. Please look at the package.json below for all version details.

When I execute my tests, it finishes of in less than a second with a pass result but it just launches the browser and then doesn't do anything in the browser.

Please look at the files I am using and suggest me where is the problem. I am not sure whether this is a bus in the latest version of protractor.

protractor.conf.js:

exports.config = {  
    seleniumAddress: 'http://localhost:4444/wd/hub',  
    specs: ['features/*.feature'],  
    getPageTimeout: 60000,
    allScriptsTimeout: 500000,
    baseURL: 'http://www.protractortest.org/testapp/ng1/#/form',
    framework: 'custom',
    frameworkPath: require.resolve('protractor-cucumber-framework'),
    capabilities: {
      'browserName': 'chrome'
    },
    cucumberOpts: {
      require: [ './features/step_definitions/*.steps.js' ],
      tags: false,
      profile: false,
      'no-source': true
    }
};

package.json:

{
  "name": "protractor_test",
  "version": "1.0.0",
  "description": "",
  "main": "protractor.conf.js",
  "dependencies": {
    "protractor": "^5.2.0",
    "cucumber": "^3.1.0",
    "chai": "^4.1.2",
    "chai-as-promised": "^7.1.1",
    "@types/chai-as-promised": "^7.1.0",
    "@types/cucumber": "^2.0.4",
    "@types/protractor": "^4.0.0"
  },
  "devDependencies": {
    "protractor-cucumber-framework": "^4.1.1"
  },
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}

test.feature:

Feature: Running Cucumber with Protractor
    As a user of Protractor
    I should be able to use Cucumber
    In order to run my E2E tests

    Scenario: Login to myApp
        Given I go to Login page
        When I login with "username" and "pwd"
        Then "You are logged in as ADMIN" is displayed

test.steps.js:

var chai = require('chai');
var chaiAsPromised = require('chai-as-promised');
var {defineSupportCode} = require('cucumber');
var expect = chai.expect;
chai.use(chaiAsPromised);
defineSupportCode(function({Given, When, Then}) {
    Given('I go to DSH Login page', function () {
        browser.get("http://localhost/myapp");
        expect(element(by.buttonText('Login')).isDisplayed()).to.eventually.equal(true);
    });
    When('I login with {string} and {string}', function (username, password) {
        element(by.id('username')).sendKeys(username);
        element(by.id('password')).sendKeys(password);
        element(by.buttonText('Login')).click();
    });
    Then('{string} is displayed', function (headerText) {
        expect(element(by.cssContainingText('ng-isolate-scope', headerText)).isDisplayed()).to.eventually.equal(true);
    });
});

Console Output:

Debugging with legacy protocol because Node.js v6.11.4 was detected.
'C:\Program Files\nodejs\node.exe' --debug-brk=38084 --nolazy node_modules\protractor\bin\protractor protractor.conf.js 
Debugger listening on [::]:38084
[16:48:02] I/launcher - Running 1 instances of WebDriver
[16:48:02] I/hosted - Using the selenium server at http://localhost:4444/wd/hub
...
1 scenario (1 passed)
3 steps (3 passed)
0m00.015s
[16:48:05] I/launcher - 0 instance(s) of WebDriver still running
[16:48:05] I/launcher - chrome #01 passed

Selenium Chrome node console output:

Starting ChromeDriver 2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f) on port 11099
Only local connections are allowed.
16:48:04.496 INFO - Found handler: org.openqa.selenium.remote.server.ServicedSession@1418ca00
16:48:04.496 INFO - Handler thread for session ed9fb79d586bc77176974953aaf98ef2 (chrome): Executing POST on /session/ed9fb79d586bc77176974953aaf98ef2/timeouts (handler: ServicedSession)
16:48:04.496 INFO - To upstream: {"script":500000}
16:48:04.496 INFO - To downstream: {"sessionId":"ed9fb79d586bc77176974953aaf98ef2","status":13,"value":{"message":"unknown error: 'ms' must be a double\n  (Session info: chrome=60.0.3112.78)\n  (Driver info: chromedriver=2.33.506120 (e3e
53437346286c0bc2d2dc9aa4915ba81d9023f),platform=Windows NT 6.3.9600 x86_64)"}}
16:48:04.512 INFO - Found handler: org.openqa.selenium.remote.server.ServicedSession@1418ca00
16:48:04.512 INFO - Handler thread for session ed9fb79d586bc77176974953aaf98ef2 (chrome): Executing POST on /session/ed9fb79d586bc77176974953aaf98ef2/timeouts (handler: ServicedSession)
16:48:04.512 INFO - To upstream: {"type":"script","ms":500000}
16:48:04.527 INFO - To downstream: {"sessionId":"ed9fb79d586bc77176974953aaf98ef2","status":0,"value":null}
16:48:05.010 INFO - Found handler: org.openqa.selenium.remote.server.ServicedSession@1418ca00
16:48:05.010 INFO - Found handler: org.openqa.selenium.remote.server.ServicedSession@1418ca00
16:48:05.010 INFO - Handler thread for session ed9fb79d586bc77176974953aaf98ef2 (chrome): Executing DELETE on /session/ed9fb79d586bc77176974953aaf98ef2 (handler: ServicedSession)
16:48:05.010 INFO - Handler thread for session ed9fb79d586bc77176974953aaf98ef2 (chrome): Executing POST on /session/ed9fb79d586bc77176974953aaf98ef2/url (handler: ServicedSession)
16:48:05.026 INFO - To upstream: {"url":"data:text/html,<html></html>"}
16:48:05.088 INFO - To downstream: {"sessionId":"ed9fb79d586bc77176974953aaf98ef2","status":0,"value":null}
16:48:05.088 INFO - Removing session org.openqa.selenium.remote.server.ServicedSession@1418ca00
16:48:05.138 INFO - To downstream: {"sessionId":"","status":0,"value":null}
16:48:05.138 INFO - To downstream: {"sessionId":"","status":6,"value":{"message":"no such session\n  (Driver info: chromedriver=2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f),platform=Windows NT 6.3.9600 x86_64)"}}

Solution

  • Can you try using callback argument instead of relying on promises. If it works, then for entering username & password you can make use of Q package to resolve all the promises.

    var chai = require('chai');
    var chaiAsPromised = require('chai-as-promised');
    var {defineSupportCode} = require('cucumber');
    var expect = chai.expect;
    chai.use(chaiAsPromised);
    defineSupportCode(function({Given, When, Then}) {
        Given('I go to DSH Login page', function (callback) {
            browser.get("http://localhost/myapp");
            expect(element(by.buttonText('Login')).isDisplayed()).to.eventually.equal(true).and.notify(callback);
        });
        When('I login with {string} and {string}', function (username, password, callback) {
            element(by.id('username')).sendKeys(username);
            element(by.id('password')).sendKeys(password);
            element(by.buttonText('Login')).click().then(function() {
                callback();
            });
        });
        Then('{string} is displayed', function (headerText, callback) {
            expect(element(by.cssContainingText('ng-isolate-scope', headerText)).isDisplayed()).to.eventually.equal(true).notify(callback);
        });
    });