我正在创建我的第一个量角器框架,并且尝试在我的项目中本地运行示例测试。我可以更新并启动网络驱动程序。完全没有问题。超级困惑我哪里出错了!
我已经进入项目级别并执行了命令
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$
答案 0 :(得分:1)
错误来自您的data.js
,请尝试按以下步骤更改:
exports.datadrive = {
firstinput:"3",
secondinput:"5",
result: "8"
}
答案 1 :(得分:0)
好的,我找到了问题的根本原因。我注意到他们不断提及"protractor": + my config.js file.
所以我决定重新配置package.json文件的这一部分。
注意:我已经在using this method机器上更新了node.js
我进入了 .bin文件夹(我是Mac用户,因此按下shift+cmd+.
以显示此隐藏文件夹),然后拖动n将量角器命令文件的位置放到我的package.json文件。
然后我将其链接到configuration.js文件,以确保拼写正确。
再次按下shift+cmd+.
隐藏.bin文件夹
保存更新的package.json文件
打开终端,然后使用cd和ls命令进入本地项目
运行npm run start
以启动量角器服务器
运行npm run protractor
进行测试
完美的测试!!!!