问题描述
我正在尝试启动一个新的量角器项目来测试一个角度站点.我安装了 node.js、typescript、protractor global 和 jasmine.我转到项目文件夹并执行 webdriver-manager update
.然后我执行 webdriver-manager start
.我还使用 tsc config.ts
构建 config.ts.一切正常,直到我尝试 protractor config.ts
.在这里我将提供我的 config.ts 和我的 package.json.
I am trying to start a new protractor project to test an angular site. I installed node.js, typescript, protractor globally and jasmine. I go to the project folder and do webdriver-manager update
. Then I do webdriver-manager start
. I also build the config.ts using tsc config.ts
. Everything works fine until i try protractor config.ts
. Here i will provide my config.ts and my package.json.
{
"name": "protractortests",
"version": "1.0.0",
"description": "Automated tests for a game platform",
"main": "index.js",
"dependencies": {
"@types/jasmine": "^3.3.12",
"@types/node": "^12.0.2",
"jasmine": "^3.4.0",
"protractor": "^5.4.2"
},
"devDependencies": {},
"scripts": {
"test": "protractor config.ts"
}
还有我的 config.ts:
and my config.ts:
import { ProtractorBrowser, Config } from "protractor";
export let config: Config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
capabilities: {
'browserName': 'chrome'
},
framework: 'jasmine',
specs: ['./FirstSpec.ts'],
jasmineNodeOpts: {
defaultTimeoutInterval: 90000
},
onPrepare: () => {
let globals = require('protractor/built');
let browser = globals.browser;
browser.manage().window().maximize();
browser.manage().timeouts().implicitlyWait(5000);
}
}
E/configParser - Error code: 105
[11:40:53] E/configParser - Error message: failed loading configuration file config.ts
[11:40:53] E/configParser - C:UsersVictorDocumentsProtractorTestsconfig.ts:1
(function (exports, require, module, __filename, __dirname) { import { ProtractorBrowser, Config } from "protractor";
^
SyntaxError: Unexpected token {
at new Script (vm.js:80:7)
at createScript (vm.js:274:10)
at Object.runInThisContext (vm.js:326:10)
at Module._compile (internal/modules/cjs/loader.js:664:28)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
at Module.load (internal/modules/cjs/loader.js:600:32)
at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
at Function.Module._load (internal/modules/cjs/loader.js:531:3)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
npm ERR! Test failed. See above for more details.
推荐答案
参考链接中的例子 https://github.com/angular/protractor/tree/5.4.1/exampleTypescript
您不需要导入 ProtractorBrowser.您可以使用对象浏览器直接使用浏览器.
You don't need to import ProtractorBrowser. You can work with browser directly with object Browser.
这篇关于由于导入量角器而无法加载 config.ts的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!