TheIntern - determining the environment for dynamic test generation

63 views Asked by At

I have a situation in which I need to dynamically generate functional tests. Basically, I want to use BrowserStack to run my tests on a variety of different environments, but I want to register a different suite of tests depending on whether I'm running on desktop or mobile.

Here is a snippet of code from the file that kicks things off, so you can get an idea of how I'm going about it:

define(function (require) {
    var registerSuite = require('intern!object');
    var assert = require('intern/chai!assert');
    var config = require('intern/dojo/node!../../node_modules/our-repo/config');
    // RIGHT HERE I NEED TO KNOW PLATFORM + BROWSER INFO!
    var our_sites = ['A', 'C', 'C', 'D'];
    for (let i=0; i<our_sites.length; i++) {
        homepage_basic_site_test_suites(registerSuite, our_sites[i], config, assert);
    }
});

I then run through the config, dynamically generating tests and calling registerSuite.

What I would like is to be able to pass in one more parameter -- the environment that has been chosen.

https://theintern.io/leadfoot/module-leadfoot_Server.html#getSessionCapabilities Seems like it would provide the information I need, but I don't know how to get ahold of it.

My config for TheIntern includes the following list of environments, and I would like to know which one has been chosen for a particular run prior to calling the homepage_basic_site_test_suites() function:

environments: [
    {
        browserName: 'IE',
        version: ['11'],
        platform: ['WINDOWS']
    },
    {
        browserName: 'Edge',
        version: ['13', 'latest'],
        platform: ['WINDOWS']
    },
    {
        browserName: 'Firefox',
        version: ['54', 'latest'],
        platform: [ 'WINDOWS', 'MAC']
    },
    {
        browserName: 'Chrome',
        version: ['45', 'latest'],
        platform: ['WINDOWS', 'MAC']
    },
    {
        browserName: 'Safari',
        version: ['10.1', 'latest'],
        platform: 'MAC'
    },
    {
        browserName: 'iPhone',
        platform: 'MAC',
        device: ['iPhone 6'],
        realMobile: true
    },
    {
        browserName: 'iPad',
        platform: 'MAC',
        device: ['iPad 4th'],
        realMobile: true
    },
    {
        browserName: 'android',
        platform: 'ANDROID',
        device: ['Samsung Galaxy S5'],
        realMobile: true
    }
]
1

There are 1 answers

0
jason0x43 On BEST ANSWER

You can get environment information from the remote session. In a suite lifecycle method or a test, you would use this.remote.session.capabilities. However, the remote isn't available at the time registerSuite is called.

You could add tests within the suite itself, where the remote is available:

registerSuite({
    name: 'my suite',

    before: function () {
        if (this.remote.session.capabilities.something) {
            // Test is from intern/lib/Test
            this.tests.push(new Test({
                name: 'a test',
                parent: this,
                test: function () {
                    // test function
                }
            });
        }
    },

    ...
});

Another option would be to make remote-specific functional suites and load them using remote-specific configs. Like, have an Android config that loads android-specific functionalSuites, and an iOS config that loads iOS-specific functionalSuites. These configs can inherit from a central config, so that most properties will be shared.