score:0

you can now use protractor-react-selector to identify web elements by react's component, props, and state. this will automatically wait to load react in your app and then identify the web elements. it can save you from doing an extra ton of workarounds.

you can identify your target element by:

const myelement = element(
    by.react('mycomponent', { somebooleanprop: true }, { somebooleanstate: true })
);

find out some sample tests here

let me know if this helps!

score:3

the way i solved the problem is to start several processes or services in order to test e2e with mocha:

  1. webserver: i start a simple webserver (like express) that provides the webpack build packages (https://www.npmjs.com/package/express)
  2. selenium: for controlling the browser (https://www.npmjs.com/package/selenium-standalone)
  3. mocha within a 'child_process' fork

this looks in my test_runner.js file following which i start with 'node test_runner.js':

 var async = require('async');
 var web_runner = require('./web_server');'
 //... and other runner scripts

 var start = function () {
   console.log('starting services:');
   async.series([
       function (callback) {
          web_runner.start(args[0], callback);
       },
       function (callback) {
           selenium_runner.start(callback);
       },
       function (callback) {
            mocha_runner.start(args[0], args[1], callback);
       },
       function (callback) {
            selenium_runner.stop(callback_stop, 0);
            mock_runner.stop(callback_stop);
            web_runner.stop(callback_stop);
            callback();
       }
   ]);
};
start();

once the test is done the function stops all services.

the webserver should be no problem to start. i had some difficilises with the selenium start and found a nice way here: https://github.com/nkbt/nightwatch-autorun/blob/master/index.js

var selenium = require('selenium-standalone');

function onseleniumstarted(err, seleniumchild) {
  if (err) {
      process.exit(1);
  }
  process.on('uncaughtexception', err2 => {
     console.error(err2.stack);
     seleniumchild.kill('sigint');
     process.exit(1);
  });
  startserver(onserverstarted(seleniumchild));
}

function onseleniuminstalled(err) {
  if (err) {
     console.error(err.stack);
     process.exit(1);
   }
   selenium.start({seleniumargs: ['-debug']}, onseleniumstarted);
}

selenium.install({}, onseleniuminstalled);

the mocha is then basically a node process that starts and looks like this in javascript:

module.exports = {
    start: function (env, test_path, callback) {
        var env_mocha = {env: process.env.env = env};
        console.log('start mocha with:', env_mocha, mocha, test_path);
        cp.fork(mocha,
            [
                test_path
            ], [
                env_mocha
            ])
            .on('error', function (error) {
                runner.stop(error);
                return process.exit(1);
            })
            .on('close', function (code) {
                callback();
            });
    },
    stop: function (reason) {
        return process.exit(reason);
    }
}

now the test cases have to use a selenium driver. i choose webdriverio, but there are other alternatives (see here: http://www.slant.co/topics/2814/~node-js-selenium-webdriver-client-libraries-bindings)

var env = process.env.env;
var webdriverio = require('webdriverio');
var assert = require('assert');

describe('file: some_test_spec', function () {

    var client = {};

    before(function (done) {
        client = webdriverio.remote({desiredcapabilities: {browsername: 'chrome'}});
        client.init(done);
    });

    after(function (done) {
        client.end(done);
    });

    describe('login success', function () {
            before(function (done) {
                // user needs to be logged in 
                client
                    .url(url_start)
                    .waitforvisible('#comp\\.user\\.login\\.button', 1000)
                    .setvalue('#comp\\.user\\.login\\.email', 'my@email.com')
                    .setvalue('#comp\\.user\\.login\\.password', 'mysecret')
                    .click('#comp\\.user\\.login\\.button')
                    .waitforvisible('#comp\\.user\\.home', 1000)
                    .call(done);
            });
     });
});

last note: phantomjs does not work with the .bind(this) function of react, therefore the phantomjs browser is no option at the moment. reason is explained here: https://groups.google.com/forum/#!msg/phantomjs/r0hpomncupc/uxusqsl2lnoj

hope this helped ;) good luck.


Related Query

More Query from same tag