1

I'm currently testing with Chrome(driver) only. I want to test it with Firefox and Safari too. One after the other, it cannot be in parallel.

Here's my gulp task to start the tests:

gulp.task('test', function() {
  return gulp.src('*test/features/*').pipe(cucumber({
    'steps': '*test/features/steps/*.js'
  }));
});

A simple feature file:

Feature: UI
    Testing UI

    Scenario: Check the title of the page
        When I open the homepage
        Then I should see "Test - IntApp" in the title

And the step file:

const chrome = require('selenium-webdriver/chrome');
const webdriver = require('selenium-webdriver');
const assert = require('assert');


module.exports = function () {
    let options = new chrome.Options();
    options.addArguments('start-maximized');

    var driver = new webdriver.Builder()
    .forBrowser('chrome')
    .setChromeOptions(options)
    .build();

    this.When('I open the homepage', function (done) {
        driver.get('http://intapp.dev/').then(done);
    });

    this.Then('I should see "Test - IntApp" in the title', function (done) {
        driver.getTitle().then(function(title) {
          assert.equal(title, "Test - IntApp");
        }).then(done);
    });


    this.registerHandler('AfterFeatures', function (features) {
        return driver.quit();
    });
};

I was thinking that maybe I could pass the browser's name as parameter somehow from the gulp task, but it doesn't seem to be possible.

2
  • One after the other, it cannot be in parallel. is quite unusual requirement. Out of curiosity, why? Commented Jul 6, 2017 at 8:19
  • @AlexBlex The server controls some custom hardware so in order for the state of the external hardware to be the same as expected on each test, the tests need to be run sequentially. Commented Jul 6, 2017 at 8:31

3 Answers 3

1

Write a bash or batch script and create a setup file.

In the setup file, you can set a variable that can be changed with the script (by editing the line), and hand this over to where you declare which driver you'll be using.

This script will run them one after the other, but they will be different suites (creating different reports if you use the JSON or HTML output).

It's how I've been doing cross browser automation for a while now.

Preference would be to use bash over batch, as bash can be run on Mac, UNIX and Windows 10, but batch is primarily Windows (from memory I think it's Windows only).

If you need guidance on where to start, on request I'll give you an outline, but I should have given you enough information to research how to do it.

Sign up to request clarification or add additional context in comments.

Comments

1

Since I wanted to do the tests sequentially this is what I came up with:

gulp.task('test', function(cb) {
  runSequence(
    'test-chrome',
    'test-firefox',
  cb);
});

gulp.task('test-chrome', function(cb) {
  return gulp.src('*test/features/*').pipe(cucumber({
      'steps': '*test/features/steps/*.js',
      'support': '*test/support/chrome.js'
    }));
});

gulp.task('test-firefox', function(cb) {
  return gulp.src('*test/features/*').pipe(cucumber({
      'steps': '*test/features/steps/*.js',
      'support': '*test/support/firefox.js'
    }));
});

Comments

0

I was thinking that maybe I could pass the browser's name as parameter somehow from the gulp task, but it doesn't seem to be possible.

Just remember that each browser has it's own driver, each driver needs to be created/initialized in it's own way.

If you go in the direction you planed, you could keep all browser handles (after you create them) in an array, and just pull the one you want by it's name.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.