2017-01-13 65 views
3

我正在使用量角器 - 黄瓜框架,无法运行我的测试。浏览器启动,但不会浏览到我的网址,然后我收到以下错误:量角器黄瓜测试不运行

$ protractor conf.js 
(node:10648) DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead. 
[11:25:05] I/hosted - Using the selenium server at http://127.0.0.1:4444/wd/hub 
[11:25:05] I/launcher - Running 1 instances of WebDriver 
[11:25:09] E/launcher - Error: TypeError: Cannot call a class as a function 
    at exports.default (C:\Source\test\node_modules\babel-runtime\helpers\classCallCheck.js:7:11) 
    at Object.Cli (C:\Source\test\node_modules\cucumber\lib\cli\index.js:64:34) 
    at C:\Source\test\node_modules\protractor-cucumber-framework\index.js:31:16 
    at Function.promise (C:\Source\test\node_modules\q\q.js:682:9) 
    at C:\Source\test\node_modules\protractor-cucumber-framework\index.js:24:14 
    at _fulfilled (\\hermes\vhd_profiles\VDI_Home_VHD1\modisej\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:834:54) 
    at self.promiseDispatch.done (\\hermes\vhd_profiles\VDI_Home_VHD1\modisej\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:863:30) 
    at Promise.promise.promiseDispatch (\\hermes\vhd_profiles\VDI_Home_VHD1\modisej\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:796:13) 
    at \\hermes\vhd_profiles\VDI_Home_VHD1\modisej\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:556:49 
    at runSingle (\\hermes\vhd_profiles\VDI_Home_VHD1\modisej\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:137:13) 
    at flush (\\hermes\vhd_profiles\VDI_Home_VHD1\modisej\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:125:13) 
    at _combinedTickCallback (internal/process/next_tick.js:67:7) 
    at process._tickCallback (internal/process/next_tick.js:98:9) 
[11:25:09] E/launcher - Process exited with error code 100 

Conf.js

exports.config = { 
    seleniumAddress: 'http://127.0.0.1:4444/wd/hub', 
    //// getPageTimeout: 60000, 
    ////allScriptsTimeout: 500000, 
    framework: 'custom', 
    // path relative to the current config file 
    frameworkPath: require.resolve('protractor-cucumber-framework'), 
    capabilities: { 
     'browserName': 'chrome' 
    }, 

    // Spec patterns are relative to this directory. 
    specs: ['Features/*.feature'], 

    baseURL: 'http://localhost:/8080', 



    cucumberOpts: { 
     require: 'Features/step_definitions/homePage.js', 
     tags: false, 
     format: undefined, 
     profile: false, 
     'no-source': true 
    } 
}; 

特性文件:

#features/test.feature 
Feature: App hub home page 

    Scenario: First sample 
    Given I go to the app hub site 
    When the homepage has loaded 
    Then I expect to see title app hub 

步骤定义:

目前,我只把步骤定义为声明“鉴于我去应用中心站点”

的step_definitions是在“功能”文件夹中保存在一个名为“step_definitions”文件夹中,我在我的conf.js文件中提到过。

module.exports = function() {  

    this.Given('I go to the app hub site', function (callback) { 
     browser.get('http://localhost:8080') 
     .then (callback); 
    }); 

}; 

任何帮助将不胜感激。

回答

0

它可能是不匹配的软件包版本造成的麻烦。当你运行npm list <package-name>你会得到什么?

我目前拥有的在下面的package.json:

"devDependencies": { 
    "chai": "^3.5.0", 
    "chai-as-promised": "^5.3.0", 
    "chai-string": "^1.2.0", 
    "cucumber": "^1.0.0", 
    "gulp": "^3.9.1", 
    "gulp-angular-protractor": "^0.1.1", 
    "protractor": "^3.3.0", 
    "protractor-cucumber-framework": "^0.6.0" 
    }, 

就这样,我与这些版本的运行没有任何问题:

  • 黄瓜 - 1.3.1
  • 量角器-cucumber-framework - 0.6.0
  • 量角器 - 3.3.0
+0

下面是Protractor Cookbook示例的'package.json'链接,其中包含typescript和cucumber:https://github.com/angular/protractor-cookbook/blob/master/protractor-typescript-cucumber/package以.json。 – cnishina

+0

上述错误是由于量角器黄瓜框架还不支持的黄瓜2.0! –

1

这是错误很可能是因为您正在使用黄瓜2.0与量角器黄瓜框架。目前它们不兼容,请将您的黄瓜版本降级到1.3.1,这将解决您的问题。

与此同时,使用量角器黄瓜框架支持黄瓜2.0也取得了很好的进展。你可以查看这个repo- protractor-cucumber-frameowrk了解更多详情。

0

非常感谢您的帮助。我正在使用黄瓜2.0。我在量角器网站上找到了一个解决方法,并更改了我的config.js文件,以便frameworkPath现在引用index.js文件,并且工作正常。

Config.js

/protractor.conf.js 

exports.config = { 
seleniumAddress: 'http://127.0.0.1:4444/wd/hub', 
getPageTimeout: 60000, 
allScriptsTimeout: 500000, 
framework: 'custom', 
// path relative to the current config file 
frameworkPath: './index.js', 
//frameworkPath: require.resolve('protractor-cucumber-framework'), 
capabilities: { 
    'browserName': 'chrome' 
}, 
useAllAngular2AppRoots: true, 
// Spec patterns are relative to this directory. 
specs: ['Features/*.feature'], 

baseURL: 'http://localhost/', 

cucumberOpts: { 
    require: 'Features/step_definitions/homePage.js', 
    tags: false, 
    format: undefined, 
    profile: false, 
    'no-source': true 
}}; 
+0

这没有任何意义。什么在你的'./index.js'文件中? – hackel

0

这是我index.js文件

index.js`

var q = require('q'), 
path = require('path'), 
glob = require('glob'), 
assign = require('object-assign'), 
debug = require('debug')('protractor-cucumber-framework'), 
Cucumber = require('cucumber'), 
state = require('./lib/runState'); 

/*** Execute the Runner's test cases through Cucumber. 
* @param {Runner} runner The current Protractor Runner. 
* @param {Array} specs Array of Directory Path Strings. 
* @return {q.Promise} Promise resolved with the test results 
*/ 
exports.run = function(runner, specs) { 
var results = {}; 

return runner.runTestPreparer().then(function() { 
    var config = runner.getConfig(); 
    var opts = assign({}, config.cucumberOpts, config.capabilities.cucumberOpts); 
    state.initialize(runner, results, opts.strict); 

    return q.promise(function(resolve, reject) { 
     var cliArguments = convertOptionsToCliArguments(opts); 
     cliArguments.push('--require', path.resolve(__dirname, 'lib', 'resultsCapturer.js')); 
     cliArguments = cliArguments.concat(specs); 

     debug('cucumber command: "' + cliArguments.join(' ') + '"'); 

     Cucumber.Cli(cliArguments).run(function (isSuccessful) { 
      try { 
       var complete = q(); 
       if (runner.getConfig().onComplete) { 
        complete = q(runner.getConfig().onComplete()); 
       } 
       complete.then(function() { 
        resolve(results); 
       }); 
      } catch (err) { 
       reject(err); 
      } 
     }); 
    }); 
}); 

function convertOptionsToCliArguments(options) { 
    var cliArguments = ['node', 'cucumberjs']; 

    for (var option in options) { 
     var cliArgumentValues = convertOptionValueToCliValues(option, options[option]); 

     if (Array.isArray(cliArgumentValues)) { 
      cliArgumentValues.forEach(function (value) { 
       cliArguments.push('--' + option, value); 
      }); 
     } else if (cliArgumentValues) { 
      cliArguments.push('--' + option); 
     } 
    } 

    return cliArguments; 
} 

function convertRequireOptionValuesToCliValues(values) { 
    var configDir = runner.getConfig().configDir; 

    return toArray(values).map(function(path) { 
     // Handle glob matching 
     return glob.sync(path, {cwd: configDir}); 
    }).reduce(function(opts, globPaths) { 
     // Combine paths into flattened array 
     return opts.concat(globPaths); 
    }, []).map(function(requirePath) { 
     // Resolve require absolute path 
     return path.resolve(configDir, requirePath); 
    }).filter(function(item, pos, orig) { 
     // Make sure requires are unique 
     return orig.indexOf(item) == pos; 
    }); 
} 

function convertGenericOptionValuesToCliValues(values) { 
    if (values === true || !values) { 
     return values; 
    } else { 
     return toArray(values); 
    } 
} 

function convertOptionValueToCliValues(option, values) { 
    if (option === 'require') { 
     return convertRequireOptionValuesToCliValues(values); 
    } else { 
     return convertGenericOptionValuesToCliValues(values); 
    } 
} 

function toArray(values) { 
    return Array.isArray(values) ? values : [values]; 
}}; 

这不是一个解决方案,但解决方法并使我能够成功运行我的测试。