javascripttypescriptgulpgulp-protractor

Typescript+Gulp+Protractor => Cannot find module config.js


I am trying to run the protractor using gulp. I am able to run first two task but when I try to run the third task its not able to find the config.js file which is stored in below path (Windows system)

F:\Selenium2\Protractor\TypeScriptProject\ConvertedJSFiles\config\config.js

gulpfile.js

import * as gulp from 'gulp';
import * as protractor from 'gulp-protractor';

gulp.task('webdriver-update', protractor.webdriver_update);
gulp.task('webdriver-standalone', protractor.webdriver_standalone);
gulp.task('run-prot', function () {
    console.log('About to run the specs...........')

    gulp.src(['ConvertedJSFiles/specs/*.js']).pipe(protractor.protractor({
            configFile: 'ConvertedJSFiles/config/config.js'
    })).on('error',function(e){
            throw e;

    });
});
console.log(protractor.getProtractorDir() + ' is the protractor directory ***');

Console Error

F:\Selenium2\Protractor\TypeScriptProject\ConvertedJSFiles\build>gulp run-prot
F:\Selenium2\Protractor\TypeScriptProject\node_modules\.bin is the protractor directory ***
[18:16:17] Using gulpfile F:\Selenium2\Protractor\TypeScriptProject\ConvertedJSFiles\build\gulpfile.js
[18:16:18] Starting 'run-prot'...
About to run the specs...........
[18:16:18] Finished 'run-prot' after 106 ms
[18:16:20] E/configParser - Error code: 105
[18:16:20] E/configParser - Error message: failed loading configuration file ConvertedJSFiles/config/config.js
[18:16:20] E/configParser - Error: Cannot find module 'F:\Selenium2\Protractor\TypeScriptProject\ConvertedJSFiles\build\Convert
edJSFiles\config\config.js'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at ConfigParser.addFileConfig (F:\Selenium2\Protractor\TypeScriptProject\node_modules\protractor\built\configParser.js:125:
26)
    at Object.initFn [as init] (F:\Selenium2\Protractor\TypeScriptProject\node_modules\protractor\built\launcher.js:93:22)
    at Object.<anonymous> (F:\Selenium2\Protractor\TypeScriptProject\node_modules\protractor\built\cli.js:112:10)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)

F:\Selenium2\Protractor\TypeScriptProject\ConvertedJSFiles\build\gulpfile.js:11
        throw e;
        ^
Error: protractor exited with code 105

Solution

  • Issue was with wrong directory reference. I debugged it with "path" package. below is the updated file.

    import * as gulp from 'gulp';
    import * as protractor from 'gulp-protractor';
    import * as path from 'path';
    gulp.task('webdriver-update', protractor.webdriver_update);
    gulp.task('webdriver-standalone', protractor.webdriver_standalone);
    gulp.task('run-prot', function () {
        console.log('About to run the specs...........')
        let srcfiles=path.resolve('../specs/*.js');
        console.log(srcfiles);
        gulp.src([srcfiles]).pipe(protractor.protractor({
                configFile: '../config/config.js'
        })).on('error',function(e){
                throw e;
    
        });
    });
    console.log(protractor.getProtractorDir() + ' is the protractor directory ***');