DarthOpto
DarthOpto

Reputation: 1652

Getting Protractor Tests to Run on SauceLabs

I am trying to launch some tests with protractor going to SauceLabs. I have my SauceConnect up and running. I have my protractor.config.js setup correctly I believe, but when I run the tests on my machine it with ng e2e --suite smoke, it is just running on my local machine and not going through the tunnel. Any suggestions? I have been following this "tutorial" and it has been going pretty well, but I am just not seeing anything going through the tunnel.

Here is my protractor.config.js file:

const baseUrl = '<BASEURL>';
const maxNumberOfInstances = process.env.NUMBER_OF_INSTANCES ? process.env.NUMBER_OF_INSTANCES : 1;
const reportPath = 'protractor/report';
const HtmlScreenshotReporter = require('protractor-jasmine2-screenshot-reporter');
const screenShotReporter = new HtmlScreenshotReporter({
    dest: reportPath,
    filename: 'artemis-e2e-report.html'
});
const SAUCELABS_USERNAME = '<SAUCEUSERNAME';
const SAUCELABS_AUTHKEY = '<SAUCEKEY>';

const chromeArgs = process.env.IS_LOCAL ? ['--no-sandbox', '--test-type=browser', '--lang=en', '--window-size=1680,1050'] : ['--disable-gpu', '--no-sandbox', '--test-type=browser', '--lang=en', '--window-size=1680,1050'];
const browserCapabilities = [{
    sauceUser: SAUCELABS_USERNAME,
    sauceKey: SAUCELABS_AUTHKEY,
    browserName: 'chrome',
    tunnelIdentifier: '<SAUCETUNNEL>',
    shardTestFiles: true,
    maxInstances: maxNumberOfInstances,
    platform: 'Windows 10',
    version: '73.0',
    screenResolution: '1280x1024',
    chromeOptions: {
        args: chromeArgs,
        prefs: {
            'credentials_enable_service': false,
            'profile': {
                'password_manager_enabled': false
            },
            download: {
                prompt_for_download: false,
                directory_upgrade: true,
                default_directory: 'C:\\downloads\\'
            },
        },
    },
    loggingPrefs: {
        browser: 'SEVERE'
    },
}, ];

// Protractor config
exports.config = {
    baseUrl: baseUrl,

    directConnect: true,
    allScriptsTimeout: 2 * 60 * 1000,
    jasmineNodeOpts: {
        defaultTimeoutInterval: 3 * 60 * 1000
    },
    getPageTimeout: 2 * 60 * 1000,
    suites: {
        smoke: 'protractor/smokeTests/*.scenario.ts',
    },

    multiCapabilities: browserCapabilities,

    framework: 'jasmine2',
    onPrepare: function () {
        browser.waitForAngularEnabled(true);
        require('ts-node').register({
            project: 'protractor/tsconfig.json',
        });
        const jasmineReporters = require('jasmine-reporters');
        const jUnitXMLReporter = new jasmineReporters.JUnitXmlReporter({
            consolidateAll: false,
            savePath: reportPath,
            filePrefix: 'xmloutput'
        });

        const JasmineConsoleReporter = require('jasmine-console-reporter');
        const consoleReporter = new JasmineConsoleReporter({
            colors: 1,
            cleanStack: 1,
            verbosity: 4,
            listStyle: 'indent',
            activity: true,
            emoji: true,
            beep: true,
            timeThreshold: {
                ok: 10000,
                warn: 15000,
                ouch: 30000,
            }
        });

        jasmine.getEnv().addReporter(jUnitXMLReporter);
        jasmine.getEnv().addReporter(screenShotReporter);
        jasmine.getEnv().addReporter(consoleReporter);

        browser.get(browser.baseUrl);
    },

    beforeLaunch: function () {
        return new Promise(function (resolve) {
            screenShotReporter.beforeLaunch(resolve);
        });
    },

    afterLaunch: function (exitCode) {
        return new Promise(function (resolve) {
            screenShotReporter.afterLaunch(resolve.bind(this, exitCode));
        });
    },
};

Upvotes: 0

Views: 1215

Answers (2)

wswebcreation
wswebcreation

Reputation: 2375

First of all you are mentioning this

it is just running on my local machine and not going through the tunnel. Any suggestions

This is not related to the tunnel, but related to:

  1. You still have directConnect: true,, remove it from your config
  2. You added the Sauce Labs credentials to your capabilities, but you should use them in your config file at the root level. Here's and example (it's written for TypeScript, but it should give you an idea about how to set up your config file). The tunnel identifier is correct, you only need to be sure that you are getting the correct tunnel id as @fijiaaron mentioned

Hope this helps

Upvotes: 1

fijiaaron
fijiaaron

Reputation: 5185

Where are you getting your tunnelIdentifier from?

You want to make sure:

  1. The tunnel is running
  2. You can access the tunnel from where you are testing
  3. If you have a named tunnel (e.g. sc -i myTunnel) then "myTunnel" should be the tunnelIdentifier, not the tunnel id that is shown in the console outnot (i.e. not Tunnel ID: cdceac0e33db4d5fa44093e191dfdfb0)
  4. If you have an unnamed tunnel then you should not need to specify a tunnelIdentifier for it to be used.
  5. If you appear to be using the tunnel but cannot access your local environment, try a manual test session in Sauce Labs and select the tunnel to see if it works there.

Upvotes: 0

Related Questions