Cornwell
Cornwell

Reputation: 3410

Run tests on multiple browsers (Sequentially)

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.

Upvotes: 1

Views: 1180

Answers (3)

Cornwell
Cornwell

Reputation: 3410

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'
    }));
});

Upvotes: 1

KyleFairns
KyleFairns

Reputation: 3057

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.

Upvotes: 1

Ofer Skulsky
Ofer Skulsky

Reputation: 743

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.

Upvotes: 0

Related Questions