NickTomlin / protractor-flake

Rerun potentially flakey protractor tests before failing.
MIT License
80 stars 51 forks source link

Receiving error "SyntaxError: Invalid or unexpected token" #64

Closed moinuddin14 closed 7 years ago

moinuddin14 commented 7 years ago

I have tried to pass suites and params args of protractor through the command line using protractor-flake and am receiving the following error.

(function (exports, require, module, __filename, __dirname) { @IF EXIST "%~dp0\n
ode.exe" (
                                                              ^
SyntaxError: Invalid or unexpected token
    at createScript (vm.js:56:10)
    at Object.runInThisContext (vm.js:97:10)
    at Module._compile (module.js:542:28)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:390:7)
    at startup (bootstrap_node.js:150:9)

I have tried various combinations of command line arguments as below and for all am receiving similar issues.

node_modules\.bin\protractor-flake.cmd --protractor-path=node_modules\.bin\protractor.cmd --parser standard --node-bin node --max-attempts=3 --color=magenta -- suite=synthetic params.env syn_sat protractor.conf.js

node_modules\.bin\protractor-flake.cmd --protractor-path=node_modules\.bin\protractor.cmd --parser standard --node-bin node --max-attempts=3 --color=magenta protractor.conf.js -- suite=synthetic params.env syn_sat

node_modules\.bin\protractor-flake.cmd --protractor-path=node_modules\.bin\protractor.cmd --parser standard --node-bin node --max-attempts=3 --color=magenta -- protractor.config.js

node_modules\.bin\protractor-flake.cmd --protractor-path=node_modules\.bin\protractor.cmd --parser standard --node-bin node --max-attempts=3 --color=magenta protractor.conf.js -- suite=synthetic params.env syn_sat --

tinker20 commented 7 years ago

@moinuddin14 How are you providing the suites and the params arguments via the command line? Can you provide your conf.jsso as to get more input regarding this?

NickTomlin commented 7 years ago

Interesting!

As @tinker20 said, could you provide your protractor.conf, and:

From doing some light googling this seems like an issue with node executables in a windows shell. I don't develop on windows so i'm a bit clueless here unfortunately. Can you confirm that it works without the suite arguments?

I'd also try omitting protractor-path and node-bin and see what happens. Also, any protractor args should be passed after an additional -- and params should also be proceeded by a -- e.g. --params.env syn_sat

node_modules\.bin\protractor-flake.cmd --parser standard --max-attempts=3 --color=magenta -- --suite=synthetic --params.env syn_sat protractor.conf.js

Another thing to try is invoking this via npm scripts, which should resolve pathing issues:

"scripts": {
  "flake": "protractor-flake --parser standard --max-attempts=3 --color=magenta -- --suite=synthetic --params.env syn_sat protractor.conf.js
}

This could just be a miss on my part for windows compatibility; i'm happy to collaborate on making things play nicely there but as I said it is an area of weakness for me since I don't use windows to develop, just to play games ;)

moinuddin14 commented 7 years ago

@tinker20 Please find below the conf.js file

var appConfig = require('./data/app.config.json');
var testData = require('./data/TestData.json');
var dataProvider = require('jasmine-data-provider');
var login = require('./pageObjects/Login.po.js');
var HtmlReporter = require('protractor-html-screenshot-reporter');
var path = require('path');
var currentdate = new Date();
var time = currentdate.getDate() + "-" + (currentdate.getMonth() + 1) + "-" + currentdate.getFullYear() + "-"
    + currentdate.getHours() + 'h' + currentdate.getMinutes() + 'm' + currentdate.getSeconds() + 's';
var screenpath = 'Reports/' + currentdate.getDate() + "-" + (currentdate.getMonth() + 1) + "-" + currentdate.getFullYear() + "-"
    + 'h' + currentdate.getHours() + 'm' + currentdate.getMinutes() + 's' + currentdate.getSeconds();
var HtmlScreenshotReporter = require('protractor-jasmine2-screenshot-reporter');
var reporter = new HtmlScreenshotReporter({
    preserveDirectory: false,
    dest: 'target/' + screenpath,
    filename: 'my-report.html',
    //Use the below only when we want to take failed scripts
    //captureOnlyFailedSpecs: true
});
var AllureReporter = require('jasmine-allure-reporter');
var protractorFlake = require('protractor-flake');

exports.config = {
    //seleniumAddress: 'http://localhost:4444/wd/hub',
    seleniumArgs: ['-Dwebdriver.ie.driver=node_modules/protractor/selenium/IEDriverServer.exe'],
    framework: 'jasmine',
    //directConnect:true,
    suites: {
        smoke: ['./specs/login.spec.js', './specs/LaunchApplicationFromTile.spec.js'],
        //smoke: ['./specs/LaunchApplicationFromTile.spec.js'],
        sanity: ['./specs/test.js'],
        test: './dummy/TestLoginPage.js',
        regression: '',
        synthetic: ['./synthetic_tests/*.js']
    },
    //Protractor supported Browsers list https://github.com/angular/protractor/blob/master/docs/browser-support.md
    multiCapabilities: [{
        'browserName': 'internet explorer',
        //  "ie.forceCreateProcessApi": true,
        //  "ie.browserCommandLineSwitches": "-private",
        //  "ie.ensureCleanSession": "true",
        'platform': 'ANY',
        'version': '11',
        "seleniumAddress": 'http://localhost:4444/wd/hub'
        //{
        //  browserName: 'chrome',
        //    seleniumAddress: 'http://localhost:4444/wd/hub',
        //    chromeOptions: {
        //        args: [
        //            '--disable-infobars'
        //        ],
        //       prefs: {
        //            // disable chrome's annoying password manager
        //            'profile.password_manager_enabled': false,
        //            'credentials_enable_service': false,
        //            'password_manager_enabled': false
        //        }
        //    }
        //},
        //{
        //For Headless Chrome Browser Testing
        //We use Chrome Headless because PhantomJs no longer is oficially supported by Protractor
        //    browserName: 'chrome',

        //    chromeOptions: {
        //        args: ["--headless", "--disable-gpu", "--window-size=800x600"]
        //    }
        //}, 
        //{
        //    browserName: 'internet explorer',
        //    seleniumAddress: 'http://localhost:4444/wd/hub'
    }],
    //capabilities: {
    //    browserName: 'chrome',
    //    //seleniumAddress: 'http://localhost:4444/wd/hub',
    //    chromeOptions: {
    //        args: [
    //            '--disable-infobars'
    //        ],
    //        prefs: {
    //            // disable chrome's annoying password manager
    //            'profile.password_manager_enabled': false,
    //            'credentials_enable_service': false,
    //            'password_manager_enabled': false
    //        }
    //    }
    //},
    allScriptsTimeout: 60000,
    beforeLaunch: function () {
        return new Promise(function (resolve) {
            reporter.beforeLaunch(resolve);
        });
    },
    params: {
        currentTime: time,
        env: null
    },
    resultJsonOutputFile: './result.json',
    onPrepare: function () {

        /*****************log4js logging*****************/
        var log4js = require('log4js');
        var logger = log4js.getLogger('ls2.0UiAutomation');
        log4js.configure({
            appenders: [
                { type: 'console' },
                { type: 'file', filename: 'logs/' + currentdate.getDate() + '_executionLog.log', category: 'synthetic' }
            ]
        });
        logger.setLevel('INFO');

        console.log('Starting the onPrepare Function');
        logger.log('INFO', 'Strating the onPrepare Function');
        /*****************npm install, webdriver-manager update and webdriver-manager-start*****************/
        //cmd = require('node-cmd');
        //cmd.run('npm_webdriver.bat');

        /*****************Maximum and Minimum Wait Times*****************/
        MAXWAITTIME = 90000;

        // set browser size...  
        //browser.manage().window().setSize(1024, 800);
        // To maximize the browser use browser.driver.manage().window().maximize();
        //Initializing with the environment that we want to run our test suite
        //console.log("Starting the test cases on the environment : " + appConfig.env);
        console.log("Starting the test cases on the environment : " + browser.params.env);
        //browser.waitForAngularEnabled(true);
        browser.manage().timeouts().implicitlyWait(60000);
        browser.ignoreSynchronization = false;

        /****************Allure Reports*****************/

        jasmine.getEnv().addReporter(new AllureReporter({
            resultsDir: './node_modules/jasmine-allure-reporter/allure-results'
        }));
        jasmine.getEnv().afterEach(function (done) {
            browser.takeScreenshot().then(function (png) {
                allure.createAttachment('Screenshot', function () {
                    return new Buffer(png, 'base64')
                }, 'image/png')();
                done();
            })
        });

    },
    onComplete: function () {
        cmd = require('node-cmd');
        cmd.run('allure-report.bat');
    },
    jasmineNodeOpts: {
        showColors: true,
        displayStacktrace: true,
        displaySpecDuration: true,
        defaultTimeoutInterval: 600000000
    }
}

@NickTomlin Please find below the requested details

Your version of protractor: Your version of node: v6.10.3, npm 3.10.10 Your operating system (this looks like windows from your snippets?): Yes, it's Windows OS (As i would also be running this on various other Windows Jenkins Slave machines, unfortunately this code has to run ranging from Windows 7 Enterprise N, Windows Vista and Windows 10 as well :( )

I have tried your suggestion of removing node and protractor path and its working fine now. Next time on if i face any issue with flake on windows OS, will be happy to collaborate with you and help try to resolve.

I am closing this issue now. Thanks for your quick response @NickTomlin

NickTomlin commented 7 years ago

@moinuddin14 great, glad to hear it is working 😄 !