开发者问题收集

收到 npm run protractor 配置文件的错误消息,之前运行正常

2018-11-02
445

我正在创建我的第一个量角器框架,并尝试在我的项目中本地运行示例测试。我可以更新并启动 webdriver。完全没有问题。非常困惑我哪里做错了!

我进入项目级别并执行命令

npm run protractor

我从 Mac 终端收到以下消息

Jacquelines-MacBook-Air:JSworkspace jacquelinegeorge$ cd LocatorTraining
Jacquelines-MacBook-Air:LocatorTraining jacquelinegeorge$ npm run protractor

> LocatorTraining@ protractor /Users/jacquelinegeorge/Documents/JSworkspace/LocatorTraining
> protractor configurations.js

[11:12:24] I/launcher - Running 1 instances of WebDriver
[11:12:24] I/hosted - Using the selenium server at http://localhost:4444/wd/hub
Started
F

Failures:
1) protractor page Object  training encountered a declaration exception
  Message:
    ReferenceError: datadrive is not defined
  Stack:
    ReferenceError: datadrive is not defined
        at Object.<anonymous> (/Users/jacquelinegeorge/Documents/JSworkspace/LocatorTraining/data.js:10:13)
        at Module._compile (module.js:571:32)
        at Object.Module._extensions..js (module.js:580:10)
        at Module.load (module.js:488:32)
        at tryModuleLoad (module.js:447:12)
        at Function.Module._load (module.js:439:3)
        at Module.require (module.js:498:17)
        at require (internal/module.js:20:19)
        at Suite.<anonymous> (/Users/jacquelinegeorge/Documents/JSworkspace/LocatorTraining/PageObjectLocator1.js:3:9)
  Message:
    WebDriverError: unknown error: failed to change window state to maximized, current state is normal
      (Session info: chrome=70.0.3538.77)
      (Driver info: chromedriver=2.43.600229 (3fae4d0cda5334b4f533bede5a4787f7b832d052),platform=Mac OS X 10.13.6 x86_64)
  Stack:
    WebDriverError: unknown error: failed to change window state to maximized, current state is normal
      (Session info: chrome=70.0.3538.77)
      (Driver info: chromedriver=2.43.600229 (3fae4d0cda5334b4f533bede5a4787f7b832d052),platform=Mac OS X 10.13.6 x86_64)
        at Object.checkLegacyResponse (/Users/jacquelinegeorge/Documents/JSworkspace/LocatorTraining/node_modules/selenium-webdriver/lib/error.js:546:15)
        at parseHttpResponse (/Users/jacquelinegeorge/Documents/JSworkspace/LocatorTraining/node_modules/selenium-webdriver/lib/http.js:509:13)
        at doSend.then.response (/Users/jacquelinegeorge/Documents/JSworkspace/LocatorTraining/node_modules/selenium-webdriver/lib/http.js:441:30)
        at process._tickCallback (internal/process/next_tick.js:103:7)
    From: Task: WebDriver.manage().window().maximize()
        at thenableWebDriverProxy.schedule (/Users/jacquelinegeorge/Documents/JSworkspace/LocatorTraining/node_modules/selenium-webdriver/lib/webdriver.js:807:17)
        at Window.maximize (/Users/jacquelinegeorge/Documents/JSworkspace/LocatorTraining/node_modules/selenium-webdriver/lib/webdriver.js:1686:25)
        at onPrepare (/Users/jacquelinegeorge/Documents/JSworkspace/LocatorTraining/configurations.js:10:37)
        at q_1.Promise (/Users/jacquelinegeorge/Documents/JSworkspace/LocatorTraining/node_modules/protractor/built/util.js:46:49)
        at Function.promise (/Users/jacquelinegeorge/Documents/JSworkspace/LocatorTraining/node_modules/q/q.js:682:9)
        at Object.runFilenameOrFn_ (/Users/jacquelinegeorge/Documents/JSworkspace/LocatorTraining/node_modules/protractor/built/util.js:38:16)
        at plugins_.onPrepare.then (/Users/jacquelinegeorge/Documents/JSworkspace/LocatorTraining/node_modules/protractor/built/runner.js:98:27)
        at _fulfilled (/Users/jacquelinegeorge/Documents/JSworkspace/LocatorTraining/node_modules/q/q.js:834:54)
        at self.promiseDispatch.done (/Users/jacquelinegeorge/Documents/JSworkspace/LocatorTraining/node_modules/q/q.js:863:30)
        at Promise.promise.promiseDispatch (/Users/jacquelinegeorge/Documents/JSworkspace/LocatorTraining/node_modules/q/q.js:796:13)

1 spec, 1 failure
Finished in 0.136 seconds

[11:12:27] I/launcher - 0 instance(s) of WebDriver still running
[11:12:27] I/launcher - chrome #01 failed 1 test(s)
[11:12:27] I/launcher - overall: 1 failed spec(s)
[11:12:27] E/launcher - Process exited with error code 1

npm ERR! Darwin 17.7.0
npm ERR! argv "/Users/jacquelinegeorge/.nvm/versions/node/v7.2.0/bin/node" "/Users/jacquelinegeorge/.nvm/versions/node/v7.2.0/bin/npm" "run" "protractor"
npm ERR! node v7.2.0
npm ERR! npm  v3.10.9
npm ERR! code ELIFECYCLE
npm ERR! LocatorTraining@ protractor: `protractor configurations.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the LocatorTraining@ protractor script 'protractor configurations.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the LocatorTraining package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     protractor configurations.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs LocatorTraining
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls LocatorTraining
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/jacquelinegeorge/Documents/JSworkspace/LocatorTraining/npm-debug.log

因此,我检查了如下所示的 configuration.js 文件(这是我正在测试的正确 Spec.js 文件):

exports.config = {
  seleniumAddress: 'http://localhost:4444/wd/hub',
  specs: ['PageObjectLocator1.js'],
  capabilities: {
    browserName: 'chrome'
  },

  onPrepare: function() {
      browser.driver.manage().window().maximize(); 
     //logs
     //command for non angular web site

     //reporting
     //site Url???


  }
}

然后,我转到项目中的运行配置和 cli.js

在此处输入图像描述

因此,我检查了我的 Spec 文件,没有错误。

describe('protractor page Object  training',function(){
    var obj= require("./PageObjectDemo.js");
    var d= require("./data.js");

    beforeEach(function() {
        obj.geturl();//the url on your test page is a method

      });


    it('Perform Simple Calculation ',function(){
    // write your code here!!!

        obj.firstnumber.sendKeys(d.datadrive.firstinput);//page of object properties
        obj.secondnumber.sendKeys(d.datadrive.secondinput);//page object properties

        obj.gobutton.click();


      //Jasmine Attribute Syntax toBe. Jasmine takes care of the promise 'resolve'internally

        expect(obj.result.getText()).toBe(d.datadrive.result);      
        //this confirm printout in console.

   obj.result.getText().then(function(text){
        console.log(text) 
     }) //end of console log message           


    })//end of it block

    afterEach(function () {
       console.log("If you can see this, test is completed. Well Done!!");
    });

因此我检查了数据规范文件:

module.exports.datadrive= 
    {
    firstinput:"3",
    secondinput:"5",
    result: "8"


    }

console.log(datadrive.result);

按照 Yong 的建议,我更新为:

exports.datadrive = {
firstinput:"3",
secondinput:"5",
result: "8"

>

得到以下结果:

[17:16:06] I/launcher - 0 instance(s) of WebDriver still running
[17:16:06] I/launcher - chrome #01 failed 1 test(s)
[17:16:06] I/launcher - overall: 1 failed spec(s)
[17:16:06] E/launcher - Process exited with error code 1

npm ERR! Darwin 17.7.0
npm ERR! argv "/Users/jacquelinegeorge/.nvm/versions/node/v7.2.0/bin/node" "/Users/jacquelinegeorge/.nvm/versions/node/v7.2.0/bin/npm" "run" "protractor"
npm ERR! node v7.2.0
npm ERR! npm  v3.10.9
npm ERR! code ELIFECYCLE
npm ERR! LocatorTraining@ protractor: `protractor configurations.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the LocatorTraining@ protractor script 'protractor configurations.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the LocatorTraining package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     protractor configurations.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs LocatorTraining
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls LocatorTraining
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/jacquelinegeorge/Documents/JSworkspace/LocatorTraining/npm-debug.log

好的,星期六我更新了我的 node.js(全局安装了更新的 node.js,但是我在本地项目级别运行了我的 npm run protractor 。这样做做错了什么吗?)并再次运行了 Spec 文件。收到以下消息(叹气)。我真的不知道我做错了什么。我完全糊涂了。

Failures:
1) protractor page Object  training Perform Simple Calculation 
  Message:
    WebDriverError: unknown error: failed to change window state to maximized, current state is normal
      (Session info: chrome=70.0.3538.77)
      (Driver info: chromedriver=2.43.600229 (3fae4d0cda5334b4f533bede5a4787f7b832d052),platform=Mac OS X 10.13.6 x86_64)
  Stack:
    WebDriverError: unknown error: failed to change window state to maximized, current state is normal
      (Session info: chrome=70.0.3538.77)
      (Driver info: chromedriver=2.43.600229 (3fae4d0cda5334b4f533bede5a4787f7b832d052),platform=Mac OS X 10.13.6 x86_64)
        at Object.checkLegacyResponse (/Users/jacquelinegeorge/Documents/JSworkspace/LocatorTraining/node_modules/selenium-webdriver/lib/error.js:546:15)
        at parseHttpResponse (/Users/jacquelinegeorge/Documents/JSworkspace/LocatorTraining/node_modules/selenium-webdriver/lib/http.js:509:13)
        at doSend.then.response (/Users/jacquelinegeorge/Documents/JSworkspace/LocatorTraining/node_modules/selenium-webdriver/lib/http.js:441:30)
        at process._tickCallback (internal/process/next_tick.js:103:7)
    From: Task: WebDriver.manage().window().maximize()
        at thenableWebDriverProxy.schedule (/Users/jacquelinegeorge/Documents/JSworkspace/LocatorTraining/node_modules/selenium-webdriver/lib/webdriver.js:807:17)
        at Window.maximize (/Users/jacquelinegeorge/Documents/JSworkspace/LocatorTraining/node_modules/selenium-webdriver/lib/webdriver.js:1686:25)
        at onPrepare (/Users/jacquelinegeorge/Documents/JSworkspace/LocatorTraining/configurations.js:10:37)
        at q_1.Promise (/Users/jacquelinegeorge/Documents/JSworkspace/LocatorTraining/node_modules/protractor/built/util.js:46:49)
        at Function.promise (/Users/jacquelinegeorge/Documents/JSworkspace/LocatorTraining/node_modules/q/q.js:682:9)
        at Object.runFilenameOrFn_ (/Users/jacquelinegeorge/Documents/JSworkspace/LocatorTraining/node_modules/protractor/built/util.js:38:16)
        at plugins_.onPrepare.then (/Users/jacquelinegeorge/Documents/JSworkspace/LocatorTraining/node_modules/protractor/built/runner.js:98:27)
        at _fulfilled (/Users/jacquelinegeorge/Documents/JSworkspace/LocatorTraining/node_modules/q/q.js:834:54)
        at self.promiseDispatch.done (/Users/jacquelinegeorge/Documents/JSworkspace/LocatorTraining/node_modules/q/q.js:863:30)
        at Promise.promise.promiseDispatch (/Users/jacquelinegeorge/Documents/JSworkspace/LocatorTraining/node_modules/q/q.js:796:13)
  Message:
    Failed: Error while waiting for Protractor to sync with the page: "both angularJS testability and angular testability are undefined.  This could be either because this is a non-angular page or because your test involves client-side navigation, which can interfere with Protractor's bootstrapping.  See http://git.io/v4gXM for details"
  Stack:
    Error: Error while waiting for Protractor to sync with the page: "both angularJS testability and angular testability are undefined.  This could be either because this is a non-angular page or because your test involves client-side navigation, which can interfere with Protractor's bootstrapping.  See http://git.io/v4gXM for details"
        at runWaitForAngularScript.then (/Users/jacquelinegeorge/Documents/JSworkspace/LocatorTraining/node_modules/protractor/built/browser.js:463:23)
        at ManagedPromise.invokeCallback_ (/Users/jacquelinegeorge/Documents/JSworkspace/LocatorTraining/node_modules/selenium-webdriver/lib/promise.js:1376:14)
        at TaskQueue.execute_ (/Users/jacquelinegeorge/Documents/JSworkspace/LocatorTraining/node_modules/selenium-webdriver/lib/promise.js:3084:14)
        at TaskQueue.executeNext_ (/Users/jacquelinegeorge/Documents/JSworkspace/LocatorTraining/node_modules/selenium-webdriver/lib/promise.js:3067:27)
        at asyncRun (/Users/jacquelinegeorge/Documents/JSworkspace/LocatorTraining/node_modules/selenium-webdriver/lib/promise.js:2927:27)
        at /Users/jacquelinegeorge/Documents/JSworkspace/LocatorTraining/node_modules/selenium-webdriver/lib/promise.js:668:7
        at process._tickCallback (internal/process/next_tick.js:103:7)Error
        at ElementArrayFinder.applyAction_ (/Users/jacquelinegeorge/Documents/JSworkspace/LocatorTraining/node_modules/protractor/built/element.js:459:27)
        at ElementArrayFinder.(anonymous function) [as sendKeys] (/Users/jacquelinegeorge/Documents/JSworkspace/LocatorTraining/node_modules/protractor/built/element.js:91:29)
        at ElementFinder.(anonymous function) [as sendKeys] (/Users/jacquelinegeorge/Documents/JSworkspace/LocatorTraining/node_modules/protractor/built/element.js:831:22)
        at UserContext.<anonymous> (/Users/jacquelinegeorge/Documents/JSworkspace/LocatorTraining/PageObjectLocator1.js:14:19)
        at /Users/jacquelinegeorge/Documents/JSworkspace/LocatorTraining/node_modules/jasminewd2/index.js:112:25
        at new ManagedPromise (/Users/jacquelinegeorge/Documents/JSworkspace/LocatorTraining/node_modules/selenium-webdriver/lib/promise.js:1077:7)
        at ControlFlow.promise (/Users/jacquelinegeorge/Documents/JSworkspace/LocatorTraining/node_modules/selenium-webdriver/lib/promise.js:2505:12)
        at schedulerExecute (/Users/jacquelinegeorge/Documents/JSworkspace/LocatorTraining/node_modules/jasminewd2/index.js:95:18)
        at TaskQueue.execute_ (/Users/jacquelinegeorge/Documents/JSworkspace/LocatorTraining/node_modules/selenium-webdriver/lib/promise.js:3084:14)
        at TaskQueue.executeNext_ (/Users/jacquelinegeorge/Documents/JSworkspace/LocatorTraining/node_modules/selenium-webdriver/lib/promise.js:3067:27)
    From: Task: Run it("Perform Simple Calculation ") in control flow
        at UserContext.<anonymous> (/Users/jacquelinegeorge/Documents/JSworkspace/LocatorTraining/node_modules/jasminewd2/index.js:94:19)
        at emitOne (events.js:96:13)
        at process.emit (events.js:188:7)
    From asynchronous test: 
    Error
        at Suite.<anonymous> (/Users/jacquelinegeorge/Documents/JSworkspace/LocatorTraining/PageObjectLocator1.js:11:2)
        at Object.<anonymous> (/Users/jacquelinegeorge/Documents/JSworkspace/LocatorTraining/PageObjectLocator1.js:1:63)
        at Module._compile (module.js:571:32)
        at Object.Module._extensions..js (module.js:580:10)
        at Module.load (module.js:488:32)
        at tryModuleLoad (module.js:447:12)

1 spec, 1 failure
Finished in 0.186 seconds

[12:40:08] I/launcher - 0 instance(s) of WebDriver still running
[12:40:08] I/launcher - chrome #01 failed 1 test(s)
[12:40:08] I/launcher - overall: 1 failed spec(s)
[12:40:08] E/launcher - Process exited with error code 1

npm ERR! Darwin 17.7.0
npm ERR! argv "/Users/jacquelinegeorge/.nvm/versions/node/v7.2.0/bin/node" "/Users/jacquelinegeorge/.nvm/versions/node/v7.2.0/bin/npm" "run" "protractor"
npm ERR! node v7.2.0
npm ERR! npm  v3.10.9
npm ERR! code ELIFECYCLE
npm ERR! LocatorTraining@ protractor: `protractor configurations.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the LocatorTraining@ protractor script 'protractor configurations.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the LocatorTraining package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     protractor configurations.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs LocatorTraining
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls LocatorTraining
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/jacquelinegeorge/Documents/JSworkspace/LocatorTraining/npm-debug.log
Jacquelines-MacBook-Air:LocatorTraining jacquelinegeorge$ 
2个回答

错误来自您的 data.js ,请尝试按如下方式更改:

exports.datadrive = {
    firstinput:"3",
    secondinput:"5",
    result: "8"
}
yong
2018-11-02

好的,我找到了问题的根源。我注意到错误消息中他们一直提到 “protractor”:+ 我的 config.js 文件。

因此,我决定重新配置 package.json 文件的这一部分。

注意:我已经 使用此方法 在我的计算机上更新了我的 node.js

我进入了 .bin 文件夹 (我是 Mac 用户,因此按 shift+cmd+. 显示此隐藏文件夹)并将 protractor 命令文件的位置拖放到我的 package.json 文件中。

然后我将它链接到 configuration.js 文件,确保拼写正确。

再次按 shift+cmd+. 隐藏 .bin 文件夹

保存了更新的 package.json文件

打开一个终端并使用 cd 和 ls 命令进入本地项目

运行 npm run start 来启动量角器服务器

运行 npm run protractor 来运行测试

测试完美运行!!!!!

fypnlp
2018-11-03