2

I am able to have chrome click the sign in button. I am working with protractor and automating it so we can do e2e testing with phantomjs.

The html is:

<div class="form-input">
    <input type="submit" id="login-button" class="btn" value="Sign in">

I have tried:

element(by.css('[class="form-input"]')).click();
element(by.css('[type="submit"]')).click();
element.all(by.id('login-button')).first().click();
element(by.id('login-button')).click();
element(by.css('[class="btn"]')).click();
element(by.css('[value="Sign in"]')).click();
element.all(by.className('form-input')).last().click();

This is my ads-e2econf.js

var fs = require('fs');

//retrieving current date
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; //January is 0!
var yyyy = today.getFullYear();

//retrieving current time
var time = new Date();
var hour = time.getHours() + ":";
var minutes = time.getMinutes() + ":";

if(dd<10) {
    dd='0'+dd
} 
if(mm<10) {
    mm='0'+mm
} 

today = mm+'/'+dd+'/'+yyyy;
time = hour + minutes;

var results = '\nThe following Protractor tests have failed on '+ today + ' @' + time + '\n\n';

exports.config = {
  capabilities: {
    browserName: 'chrome',
    version: '',
    platform: 'ANY'
  },

  seleniumServerJar: 'node_modules/protractor/selenium/selenium-server-standalone-2.45.0.jar',

  specs: [
           'test/specs/manage/*.js',
           'test/specs/manage/clone/*.js',
           'test/specs/regression/*.js',
           'test/specs/create/create-basicAd.js',
           'test/specs/create/create-pagepost.js',
           'test/specs/create/create-targeting.js'
          ],

  onPrepare: function () {
    require('jasmine-reporters');
    jasmine.getEnv().addReporter(new jasmine.ConsoleReporter(console.log));
    jasmine.getEnv().addReporter(new function() {
      this.reportSpecResults = function(spec) {
        if (!spec.results().passed()) {
          results +=  spec.suite.description +  ' ' + spec.description;
          if(spec.suite.description.substring(0, 4) == 'ADS-') {
            results += 'censored' + spec.suite.description;
            results += 'censored';
          }
          results += '\n';
        }
      };
    });
  },

  jasmineNodeOpts: {
    showColors: true,
    defaultTimeoutInterval: 1000000,
    isVerbose: true
  },

  allScriptsTimeout: 1000000,

  onCleanUp: function() {
    fs.writeFileSync('/tmp/results.txt', results);
  }
}

This is my karma config file. // Karma configuration

module.exports = function(config) {
  'use strict';

  config.set({
    // base path, that will be used to resolve files and exclude
    basePath: '',

    // testing framework to use (jasmine/mocha/qunit/...)
    frameworks: ['jasmine'],

    // list of files / patterns to load in the browser
    files: [
        'app/bower_components/jquery/dist/jquery.js',
        'app/bower_components/lodash/dist/lodash.js',
        'app/bower_components/angular/angular.js',
        'app/bower_components/angular-mocks/angular-mocks.js',
        'app/bower_components/angular-resource/angular-resource.js',
        'app/bower_components/angular-cookies/angular-cookies.js',
        'app/bower_components/angular-sanitize/angular-sanitize.js',
        'app/bower_components/angular-route/angular-route.js',
        'app/bower_components/angular-lodash/angular-lodash.js',
        'app/bower_components/angular-bootstrap/ui-bootstrap.js',
        'app/bower_components/ui-utils/ui-utils.js',
        'app/bower_components/angulartics/src/angulartics.js',
        'app/bower_components/angulartics/src/angulartics-ga.js',
        'app/bower_components/ng-csv/src/ng-csv/ng-csv.js',
        'app/bower_components/angulartics/src/angulartics-ga.js',
        'app/bower_components/moment/moment.js',
        'app/bower_components/ng-bs-daterangepicker/src/ng-bs-daterangepicker.js',
        'app/bower_components/select2/select2.js',
        'app/bower_components/angular-ui-select/dist/select.js',
        'app/bower_components/angular-ui-select2/src/select2.js',
        'app/bower_components/bn-tokens-angular/dist/bn-tokens-angular.js',
        'app/bower_components/bn-catm-angular/dist/bn-catm-angular.js',
        'app/bower_components/bn-topnav/dist/js/bn-topnav.js',
        'app/bower_components/angular-ui-router/release/angular-ui-router.js',
        'app/bower_components/bn-expression-builder/dist/bn-expression-builder.js',
        'app/bower_components/bn-appbar/dist/js/bn-appbar.js',
        'app/bower_components/zeroclipboard/dist/ZeroClipboard.js',
        'app/bower_components/ng-clip/dest/ng-clip.min.js',
        'app/bower_components/bn.dayparting/dist/bn.dayparting.js',
        'app/lib/ng-grid/build/ng-grid.js',
        'app/lib/ns-popover/nsPopover.js',
        'app/lib/ps-input-time.js',
        'app/lib/angular-ui-scrollfix/scrollfix.js',
        'app/scripts/services/facebookAPI/providers/fbcommon.js', // FML
        'app/scripts/services/facebookAPI/providers/facebook.js', // FMLx2
        'app/scripts/*.js',
//        'app/mock/api/api.mock.js',
//        'app/mock/api/*.mock.js',
        'app/scripts/**/*.js',
        'app/templates/**/*.html',
        'test/unit/**/*.js'
    ],

    // generate js files from html templates to expose them during testing.
    preprocessors: {
      'app/templates/**/*.html': 'html2js'
    },

// list of files / patterns to exclude
exclude: [],

// web server port
port: 9010,

// level of logging
// possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG
logLevel: config.LOG_INFO,


// enable / disable watching file and executing tests whenever any file changes
//autoWatch: true,


// Start these browsers, currently available:
// - Chrome
// - ChromeCanary
// - Firefox
// - Opera
// - Safari (only Mac)
// - PhantomJS
// - IE (only Windows)
//browsers: ['Chrome'],

// Timeout for capturing a browser (in ms).
captureTimeout: 60 * 1e3,

// to avoid DISCONNECTED messages
browserDisconnectTimeout : 10000, // default 2000
browserDisconnectTolerance : 1, // default 0
browserNoActivityTimeout : 60 * 1e3, //default 10000


// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun: false

}); };

This is my package.json:

{
  "name": "client",
  "version": "0.0.0",
  "dependencies": {},
  "devDependencies": {
    "grunt": "^0.4.5",
    "grunt-angular-templates": "^0.5.4",
    "grunt-autoprefixer": "~0.4.0",
    "grunt-concurrent": "~0.4.1",
    "grunt-contrib-clean": "~0.5.0",
    "grunt-contrib-coffee": "~0.7.0",
    "grunt-contrib-compass": "~0.6.0",
    "grunt-contrib-concat": "~0.3.0",
    "grunt-contrib-connect": "~0.5.0",
    "grunt-contrib-copy": "~0.4.1",
    "grunt-contrib-cssmin": "~0.7.0",
    "grunt-contrib-htmlmin": "~0.1.3",
    "grunt-contrib-imagemin": "~0.3.0",
    "grunt-contrib-jshint": "~0.7.1",
    "grunt-contrib-uglify": "~0.2.0",
    "grunt-contrib-watch": "~0.5.2",
    "grunt-google-cdn": "~0.2.0",
    "grunt-jscs": "^0.8.1",
    "grunt-karma": "~0.6.2",
    "grunt-newer": "~0.5.4",
    "grunt-ng-constant": "^1.1.0",
    "grunt-ngmin": "~0.0.2",
    "grunt-protractor-runner": "~0.2.3",
    "grunt-rev": "~0.1.0",
    "grunt-svgmin": "~0.2.0",
    "grunt-usemin": "~2.0.0",
    "grunt-wiredep": "~2.0.0",
    "jasmine-reporters": "~0.4.1",
    "jshint-stylish": "~0.1.3",
    "karma": "~0.10.9",
    "karma-chrome-launcher": "~0.1.2",
    "karma-coffee-preprocessor": "~0.1.2",
    "karma-firefox-launcher": "~0.1.3",
    "karma-html2js-preprocessor": "~0.1.0",
    "karma-jasmine": "~0.1.5",
    "karma-ng-html2js-preprocessor": "~0.1.0",
    "karma-ng-scenario": "~0.1.0",
    "karma-phantomjs-launcher": "~0.1.1",
    "karma-requirejs": "~0.2.1",
    "karma-script-launcher": "~0.1.0",
    "load-grunt-tasks": "~0.2.0",
    "phantomjs": "~1.9.7-1",
    "protractor": "~2.0.0",
    "requirejs": "~2.1.10",
    "time-grunt": "~0.2.1"
  },
  "engines": {
    "node": ">=0.10.0"
  },
  "scripts": {
    "start": "grunt serve",
    "test": "grunt test"
  }
}
4
  • try element(by.id('login-button')).trigger('click'); Mar 30, 2015 at 18:40
  • have you tried adding some pause or waiting for body to render?
    – Marcus
    Mar 30, 2015 at 18:48
  • @Marcus FYI, this is what I've also suggested as an option.
    – alecxe
    Mar 30, 2015 at 18:51
  • @Marcus and @alecxe I have a browser.driver.sleep(4000); before the click.
    – tosh
    Mar 30, 2015 at 19:35

1 Answer 1

2

PhantomJS is the worst choice for e2e testing with protractor.

Even protractor core developers recommend against it:

We recommend against using PhantomJS for tests with Protractor. There are many reported issues with PhantomJS crashing and behaving differently from real browsers.

If you still want to solve this with PhantomJS, here is the list of things to try:

  • trigger click via executeScript():

    browser.executeScript("arguments[0].click();", button.getWebElement());
    
  • wait for element to become clickable before making a click:

    var EC = protractor.ExpectedConditions;
    browser.wait(EC.elementToBeClickable(button), 5000);
    
  • maximize browser window at the startup:

    browser.manage().window().maximize();
    

where button is an element you've found, e.g.:

var button = element(by.id("login-button"));
4
  • I am aware that this is the case/issue. I have no choice but to use it as I am an intern and this is not my environment to change.
    – tosh
    Mar 30, 2015 at 18:45
  • none of the solutions worked. I got a Wait timed out after 5002ms error. I have a expect( element(by.id('login-button')).isPresent()).toBe(true); so I know it's there.
    – tosh
    Mar 30, 2015 at 19:33
  • @tosh could you update the question and describe what is happening when you try the solutions? Also, I would need your entire spec and protractor config. Thanks.
    – alecxe
    Mar 30, 2015 at 19:34
  • @alexcxe Nothing happens after each of the solutions you gave except the wait one. My guess is that phantomjs never clicked it since I have a expect(browser.driver.getCurrentUrl()).toContain('censored url'); and it failed. also updated question.
    – tosh
    Mar 30, 2015 at 19:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.