2016-05-12 64 views
1

所以,我一直在用量角器(茉莉花2)編寫非常漂亮的e2e測試,但現在我的需求已經發生了變化:我需要從Jasmine2切換到黃瓜。截至目前,黃瓜不再被量角器直接支持。我嘗試了一個自定義框架設置=>不成功。 正如我所提到的,我使用的是gulp-angular-protractor,它爲我提供了一個非常簡單的工作環境(運行測試時開啓/關閉webdriver,gulp命令等),我仍然想保留它。吞嚥角度量角器與黃瓜的集成

這裏是我的配置:

的package.json

... 

    "devDependencies": { 
    "angular-mocks": "^1.5.1", 
    "browser-sync": "^2.10.0", 
    "cucumber": "^0.10.2", 
    "del": "^2.1.0", 
    "gulp": "^3.9.1", 
    "gulp-angular-protractor": "^0.1.1", 
... 

gulpfile.js:

gulp.task('e2e', function(callback) { 
    gulp 
     .src(['./dist/**/*.e2e.js']) 
     .pipe(gulpProtractorAngular({ 
      'configFile': 'protractor.conf.js', 
      'debug': false, 
      'autoStartStopServer': true 
     })) 
     .on('error', function(e) { 
      console.log(e); 
     }) 
     .on('end', callback); 
}); 

protractor.conf.js

exports.config = { 
    baseUrl: 'http://localhost:3000', 
    specs: ['dist/**/*.feature'], 
    directConnect: true, 
    exclude: [], 
    multiCapabilities: [{ 
     browserName: 'chrome' 
    }], 
    allScriptsTimeout: 110000, 
    getPageTimeout: 100000, 

    framework: 'custom', 
    frameworkPath: require.resolve('cucumber'), 
    cucumberOpts: { 
     require: 'dist/**/*steps.js', 
     format: 'pretty' 
    }, 

    /** 
    * ng2 related configuration 
    * 
    * useAllAngular2AppRoots: tells Protractor to wait for any angular2 apps on the page instead of just the one matching 
    * `rootEl` 
    * 
    */ 
    useAllAngular2AppRoots: true 
}; 

假人測試:

world.js

module.exports = function() { 

    this.World = function World(callback) { 
    this.prop = "Hello from the World!"; // this property will be available in step definitions 

    this.greetings = function(name, callback) { 
     console.log("\n----Hello " + name); 
     callback(); 
    }; 

    callback(); // tell Cucumber we're finished and to use 'this' as the world instance 
    }; 
} 

login.component.feature

Feature: Sample 

Scenario: First sample 
Given this is the first sample 

Scenario: Second sample 
Given this is the second sample 

login.component.steps.js

var sampleSteps = function() { 

    this.Given(/^this is the first sample$/, function (callback) { 
     console.log("\n----" + this.prop); 
     callback(); 
    }); 

    this.Given(/^this is the second sample$/, function (callback) { 
     this.greetings("everybody", callback); 
    }); 

}; 

module.exports = sampleSteps; 

項目文件夾樹是這個樣子: Cucumber with protractor

問題: 當我運行一飲而盡E2E我得到:

launcher] Error: TypeError: require(...).run is not a function 

在C:\用戶\文檔\ dev的\ node_modules \吞掉-角量角器\ node_m dules \一飲而盡,量角器\ node_modules \量角器\ LIB \ runner.js:337:35 at _fulfilled(C:\ Users \ Documents \ dev \ node_modules \ gulp-angular-protr ctor \ node_modules \ gulp-protractor \ node_modules \ protractor \ node_modules \ q \ q.js:7 7:54) at self.promiseDispatch.done(C:\ Users \ Documents \ dev \ node_modules \ gul -angular-protractor \ node_modules \ gulp-protractor \ node_modules \ protractor \ node_m dules \ q \ q.js: 826:30) 在Promise.promise.promiseDispatch(C:\ Users \ Documents \ dev \ node_modul s \ gulp-angular-protractor \ node_modules \ gulp-protractor \ node_modules \ protractor \ ode_modules \ q \ q.js:759:13) at C:\ Users \ Documents \ dev \ node_modules \ gulp-angular-massractor \ node_m dules \ gulp-protractor \ node_modules \ protractor \ node_modules \ q \ q.js:525:49 at flush(C:\ Users \文檔\ dev的\ node_modules \吞掉-角量角器 node_modules \吞掉,量角器\ node_modules \量角器\ node_modules \ q \ q.js:108:17

任何想法,我究竟做錯了什麼?

回答

0

首先,你爲什麼說量角器不支持黃瓜?我的意思是,你需要使用它作爲一個自定義FW,並且你需要在你的配置文件中使用Protractor-CucumberJS ...

framework: 'custom', 
    frameworkPath: require.resolve('protractor-cucumber-framework'), 
    specs: [ 
     'e2e/features/*.feature' 
    ], 
    cucumberOpts: { 
     require: './e2e/features/*/*.js', 
     format: 'pretty', 
     keepAlive: true 
    } 

和關於向吞氣的任務,我一直在使用:

"gulp-protractor": "^2.1.0", 

配置好這樣的任務:

/** 
* run protractor 
*/ 


var args = require('yargs').argv; 

module.exports = function(gulp, plugins) { 
    return function (done) { 
     var protractorConfig = '', 
      testConfig = '', 
      environment = args.environment || 'devel', 
      tag = args.tag || '@Sanity', 
      baseUrl; 

     if (!args.baseUrl) { 
      baseUrl = 'XXXXXXXX'; 
     } else if (args.baseUrl.match(/^(?:https?\:)?\/\//)) { 
      baseUrl = args.baseUrl; 
     } else { 
      baseUrl = 'XXXXXXXX' + args.baseUrl + '/'; 
     } 

     switch(environment) { 
      case 'devel' : 
       protractorConfig = 'e2e/protractor.config.devel.js'; 
       testConfig = '../config/devel'; 
       break; 
      case 'live' : 
       protractorConfig = 'e2e/protractor.config.live.js'; 
       testConfig = '../config/live'; 
       break; 
      case 'remote' : 
       protractorConfig = 'e2e/protractor.config.remote.js'; 
       testConfig = '../config/live'; 
       break; 
      default: 
      case 'build' : 
       protractorConfig = 'e2e/protractor.config.build.js'; 
       testConfig = '../config/build'; 
       break; 
     } 

     gulp.src([ 
      'e2e/features/*.feature' 
     ]) 
      .pipe(plugins.protractor.protractor({ 
       configFile: protractorConfig, 
       args: [ 
        '--verbose', 
        '--no-stackTrace', 
        '--params.test.config', testConfig, 
        '--baseUrl', baseUrl, 
        '--cucumberOpts.tags', tag 
       ] 
      })) 
      .on('error', function() { 
       done(); 
       process.exit(1); 

      }); 
    }; 
}; 

希望這有助於

0

我意思是:量角器不再爲箱子外的黃瓜服務。 我建議使用"protractor-cucumber-framework"。這裏是我的protractor.conf:

exports.config = { 
    baseUrl: 'http://localhost:3000', 
    specs: ['dist/**/*.feature'], 
    directConnect: true, 
    exclude: [], 
    multiCapabilities: [{ 
     browserName: 'chrome' 
    }], 
    allScriptsTimeout: 110000, 
    getPageTimeout: 100000, 

    framework: 'custom', 
    frameworkPath: require.resolve('protractor-cucumber-framework'), 
    cucumberOpts: { 
     require: 'dist/**/*steps.js', 
     format: 'pretty', 
     tags: '@Login', 
     keepAlive: false 
    }, 
//  cucumberOpts: { 
//  require: 'dist/**/steps.js', 
//  tags: '@dev', 
//  format: 'progress', 
//  profile: false, 
//  'no-source': true 
// } 

    /** 
    * ng2 related configuration 
    * 
    * useAllAngular2AppRoots: tells Protractor to wait for any angular2 apps on the page instead of just the one matching 
    * `rootEl` 
    * 
    */ 
    useAllAngular2AppRoots: true 
};