当我在量角器黄瓜中运行步骤定义文件时,浏览器没有捕获给定的URL

时间:2017-12-29 11:10:51

标签: protractor

我是这个量角器 - 黄瓜的新手。如果我出错了,请纠正我。 我正在使用量角器3.2.2 当我运行功能文件时,它给出正确的输出。但是当我运行步骤定义时,浏览器没有采用给定的URL。

我的功能文件如下。

Feature: Login page test   
Scenario: Verify whether the user is able to view the login page while 
giving the URL.   
Given I go to "http://localhost:4200/login"       
When The URL of the page should be "http://localhost:4200/login" 

我的步骤定义文件如下所示。

var chai = require('chai');
var chaiAsPromised = require('chai-as-promised');

chai.use(chaiAsPromised);
var expect = chai.expect;

module.exports = function() {

this.Given('I go to {string}', function (string) {
browser.get(string);
});
this.When('The URL of the page should be {string}', function (string) {
expect(browser.getCurrentUrl()).to.eventually.equal(string);
});
}

我的配置。文件如下:

exports.config = {
seleniumAddress: 'http://127.0.0.1:4444/wd/hub', 
allScriptsTimeout: 11000,
specs: [ 
'features/*.feature'    
],  
capabilities: {  
'browserName': 'chrome'    
},  
directConnect: true,  
baseUrl: 'http://localhost:4200/login',
framework: 'custom',
frameworkPath: require.resolve('protractor-cucumber-framework'),

cucumberOpts: {  
require: 'features/step_definitions/*.js',   
tags: false,
format: 'pretty',
profile: false,
'no-source': true
}  }; 

下面给出了我运行'protractor protractor.conf.js'时出现的错误。

Using ChromeDriver directly...
[launcher] Running 1 instances of WebDriver
(node:7508) [DEP0022] DeprecationWarning: os.tmpDir() is deprecated. Use 
os.tmpdir() instead.
[7884:6800:1229/145724.847:ERROR:browser_gpu_channel_host_factory.cc(107)] 
Failed to launch GPU process.

DevTools listening on ws://127.0.0.1:12425/devtools/browser/74f2a81c-51c2-
4a8a-afec-26166a388d1f

C:\Users\CS1027C\AppData\Roaming\npm\node_modules\protractor\node_modules\se
lenium-webdriver\http\index.js:365
  onError(new Error(message));
          ^
Error: ECONNREFUSED connect ECONNREFUSED 127.0.0.1:54206
at ClientRequest.<anonymous> (C:\Users\CS1027C\AppData\Roaming\npm\node_modu
les\protractor\node_modules\selenium-webdriver\http\index.js:365:15)
at emitOne (events.js:116:13)
at ClientRequest.emit (events.js:211:7)
at Socket.socketErrorListener (_http_client.js:387:9)
at emitOne (events.js:116:13)
at Socket.emit (events.js:211:7)
at emitErrorNT (internal/streams/destroy.js:64:8)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
From: Task: WebDriver.createSession()
at acquireSession (C:\Users\CS1027C\AppData\Roaming\npm\node_modules\protrac
tor\node_modules\selenium-webdriver\lib\webdriver.js:62:22)
at Function.createSession (C:\Users\CS1027C\AppData\Roaming\npm\node_modules
\protractor\node_modules\selenium-webdriver\lib\webdriver.js:295:12)
at new Driver (C:\Users\CS1027C\AppData\Roaming\npm\node_modules\protractor\
node_modules\selenium-webdriver\chrome.js:778:38)
at DirectDriverProvider.getNewDriver (C:\Users\CS1027C\AppData\Roaming\npm\n
ode_modules\protractor\built\driverProviders\direct.js:69:16)
at Runner.createBrowser (C:\Users\CS1027C\AppData\Roaming\npm\node_modules\p
rotractor\built\runner.js:203:37)
at C:\Users\CS1027C\AppData\Roaming\npm\node_modules\protractor\built\runner
.js:293:21
at _fulfilled (C:\Users\CS1027C\AppData\Roaming\npm\node_modules\protractor\
node_modules\q\q.js:834:54)
at self.promiseDispatch.done (C:\Users\CS1027C\AppData\Roaming\npm\node_modu
les\protractor\node_modules\q\q.js:863:30)
at Promise.promise.promiseDispatch (C:\Users\CS1027C\AppData\Roaming\npm\nod
e_modules\protractor\node_modules\q\q.js:796:13)
at C:\Users\CS1027C\AppData\Roaming\npm\node_modules\protractor\node_modules
\q\q.js:556:49
[launcher] Process exited with error code 1

1 个答案:

答案 0 :(得分:0)

从错误消息:    错误:ECONNREFUSED连接ECONNREFUSED 127.0.0.1:54206,

您的问题应该由使用较高的Chrome浏览器使用较低的chromedriver引起,升级chromedriver应该可以解决您的问题。

并在配置文件中更改cucumberOpts,如下所示:

cucumberOpts: {
    monochrome: true,
    strict: true,
    plugin: ["pretty"],
    require: [
        'features/step_definitions/*.js'
    ],
    tags: ''
}

更改您的步骤定义文件,如下所示:(如果您使用黄瓜1或以下)

var chai = require('chai');
var chaiAsPromised = require('chai-as-promised');

chai.use(chaiAsPromised);
var expect = chai.expect;

module.exports = function() {

    this.Given('I go to "(.*?)"', function (url) {
        browser.get(url);
    });

    this.When('The URL of the page should be "(.*?)"', function (url) {
        expect(browser.getCurrentUrl()).to.eventually.equal(url);
    });

};

将步骤定义文件更改为(如果您使用黄瓜2或以上)

var {defineSupportCode} = require('cucumber');

defineSupportCode(function ({ Given, When, Then }) {

    Given('I go to "(.*?)"', function (url) {
        browser.get(url);
    });

    When('The URL of the page should be "(.*?)"', function (url) {
        expect(browser.getCurrentUrl()).to.eventually.equal(url);
    });
});