0
votes

So I have the following scenario.

We have a Protractor-Cucumber framework based on this framework.

The framework has been modified in a way that the config files are written in TS. This is an example config:

import { browser, Config } from 'protractor';
import { Reporter } from '../support/reporter';

const jsonReports = process.cwd() + '/reports/json';

export const config: Config = {

    directConnect: true,
    SELENIUM_PROMISE_MANAGER: false,

    stackTrace: true,

    capabilities: {
        browserName: 'chrome'
    },

    framework: 'custom',
    frameworkPath: require.resolve('protractor-cucumber-framework'),

    specs: [
        '../../features/*.feature',
        '../../features/**/*.feature',
    ],

    onPrepare: () => {
        browser.manage().window().maximize();
        Reporter.createDirectory(jsonReports);
    },

    cucumberOpts: {
        compiler: 'ts:ts-node/register',
        format: 'json:./reports/json/cucumber_report.json',
        require: [
            '../../stepdefinitions/*.ts',
            '../../stepdefinitions/**/*.ts',
            '../../support/*.ts'
        ],
        strict: true,
        tags: '(@e2e) and (not @ignore) and (not @notImplemented)',
        keepAlive: false,
    },
    allScriptsTimeout: 10000,
    getPageTimeout: 5000,
    onComplete: () => {
        return Reporter.generateReports();
    },
    afterLaunch: exitCode => {
        if (exitCode === 1) {
            console.log('Actual Exit code: ' + exitCode);
            process.exit(0);
        }
    }
};

Looking back at the framework this was implemented from, now they have implemented protractor-flake, which is something I need to include.

I have tried using the actual config which is being used, and can be seen here however when I try to run it I get the following error:

E/configParser - Error code: 105
[09:14:04] E/configParser - Error message: failed loading configuration file ./build/config/conf.debug.js
[09:14:04] E/configParser - Error: Cannot find module 'C:\Users\Protractor\build\config\conf.debug.js'

Please note that I have changed the protractor args to load the config shown above hence it is showing that is cannot load config.debug.js.

I have also been through Nick Tomlin's repositories for protractor flake and the cucumber specific documentation and added the necessary console.log in the After support code and tested running protractor flake from the cli but nothing seems to work. I get the error above followed by :

Using cucumber to parse output Tests failed but no specs were found.

All specs will be run again.Re-running tests: test attempt 2

However no tests are run .i.e. no run at all.

When I run the usual config using npm all runs well, without the re run of protractor flake.

Can anyone offer their 2 cents on this issue, what am I missing?

I have searched quite a bit to find a typescript example for this but as yet have not, unless I missed it.

Sorry I know it is long but wanted to try to cover everything I have tried.

Thanks in advance.

1
Could you provide the test start command with it's args ? - Silvan Bregy
Sure. npm run build && protractor-flake --parser cucumber --max-attempts=3 ./build/config/config.debug.js - David

1 Answers

3
votes

I struggled with similar problems when embedding protractor-flake.

1) Check if your current debug.conf.js works. Achieve this by copying debug.conf.js into some folder on your computer and running protractor-flake with an absolute path to your debug.conf.js in args.

2) If step 1 worked, you have to migrate your debug.conf.js into typescript, by simply putting .ts at the end and changing the content to:

// debug.conf.ts
const protractorFlake = require('protractor-flake');
const argv = require('yargs').argv;

export default (function () {
  protractorFlake({
    maxAttempts: 2,
    parser: 'cucumber',
    protractorArgs: [
      './e2e-tests/config/protractor.e2e.conf.js',
      `--feature=${argv.feature || '*'}`,
      `--tags=${argv.tags || ''}`
    ]
  }, (status) => {
    process.exit(status);
  });
})();

You will have to adjust this path in config: './e2e-tests/config/protractor.e2e.conf.js', it should be correct relative path pointing to builded javascript protractor.e2e.conf.js.

In debug.conf.ts you can see a default export which is a function and this function is executed immediately.That means, if we run require('./somePath/debug.conf'), OR ts-node debug.conf.ts, protractor-flake will directly be executed. You can then for example store following npm script for running protractor-flake:

// ...
"scripts": {
   "protractor.flake": "ts-node ./somePath/debug.conf.ts"
}
// ...

Let me know if anything is unclear or doesn't work, Cheers!