[英]protractor + cucumber + Typescript failing
4.4.5
4.4.5
3.3.0
3.3.0
chrome
chrome
Win 7
Win 7
I am trying to write protractor + cucumber combination in typescript. 我正在尝试在打字稿中写出量角器+黄瓜组合。 My project has a simple feature to open the page and input three fields.
我的项目有一个简单的功能来打开页面并输入三个字段。 I am failing to run protractor.
我没能运行量角器。 its throwing me below error.
它让我低于错误。
$ protractor protractor.conf.js [13:40:55] I/hosted - Using the selenium server at http://localhost:4444/wd/hub
$ protractor protractor.conf.js [13:40:55]我/托管 - 在http:// localhost:4444 / wd / hub使用selenium服务器
[13:40:55] I/launcher - Running 1 instances of WebDriver
[13:40:55] I / launcher - 运行WebDriver的1个实例
⨯ Unable to compile TypeScript
⨯无法编译TypeScript
..\\e2e\\features\\step_definitions\\factory\\factory-form.page.ts (1,30): Cannot find namespace 'protractor'.
.. \\ e2e \\ features \\ step_definitions \\ factory \\ factory-form.page.ts(1,30):找不到命名空间'量角器'。 (2503) ..\\e2e\\features\\step_definitions\\factory\\factory-form.page.ts (2,18): Cannot find namespace 'webdriver'.
(2503).. \\ e2e \\ features \\ step_definitions \\ factory \\ factory-form.page.ts(2,18):找不到命名空间'webdriver'。 (2503) ..\\e2e\\features\\step_definitions\\factory\\factory-form.page.ts (14,21): Cannot find name 'element'.
(2503).. \\ e2e \\ features \\ step_definitions \\ factory \\ factory-form.page.ts(14,21):找不到名称'element'。 (2304) ..\\e2e\\features\\step_definitions\\factory\\factory-form.page.ts (14,29): Cannot find name 'by'.
(2304).. \\ e2e \\ features \\ step_definitions \\ factory \\ factory-form.page.ts(14,29):找不到名字'by'。 (2304) ..\\e2e\\features\\step_definitions\\factory\\factory-form.page.ts (15,44): Cannot find name 'by'.
(2304).. \\ e2e \\ features \\ step_definitions \\ factory \\ factory-form.page.ts(15,44):找不到名称'by'。 (2304) ..\\e2e\\features\\step_definitions\\factory\\factory-form.page.ts (16,48): Cannot find name 'by'.
(2304).. \\ e2e \\ features \\ step_definitions \\ factory \\ factory-form.page.ts(16,48):找不到名称'by'。 (2304) ..\\e2e\\features\\step_definitions\\factory\\factory-form.page.ts (17,50): Cannot find name 'by'.
(2304).. \\ e2e \\ features \\ step_definitions \\ factory \\ factory-form.page.ts(17,50):找不到名字'by'。 (2304) ..\\e2e\\features\\step_definitions\\factory\\factory-form.page.ts (18,47): Cannot find name 'by'.
(2304).. \\ e2e \\ features \\ step_definitions \\ factory \\ factory-form.page.ts(18,47):找不到名称'by'。 (2304) ..\\e2e\\features\\step_definitions\\factory\\factory-form.page.ts (19,32): Cannot find name 'element'.
(2304).. \\ e2e \\ features \\ step_definitions \\ factory \\ factory-form.page.ts(19,32):找不到名称'element'。 (2304) ..\\e2e\\features\\step_definitions\\factory\\factory-form.page.ts (19,40): Cannot find name 'by'.
(2304).. \\ e2e \\ features \\ step_definitions \\ factory \\ factory-form.page.ts(19,40):找不到名字'by'。 (2304) ..\\e2e\\features\\step_definitions\\factory\\factory-form.page.ts (36,29): Cannot find name 'by'.
(2304).. \\ e2e \\ features \\ step_definitions \\ factory \\ factory-form.page.ts(36,29):找不到名字'by'。 (2304) ..\\e2e\\features\\step_definitions\\factory\\factory-form.steps.ts (1,13): Cannot find name 'require'.
(2304).. \\ e2e \\ features \\ step_definitions \\ factory \\ factory-form.steps.ts(1,13):找不到名称'require'。 (2304) ..\\e2e\\features\\step_definitions\\factory\\factory-form.steps.ts (1,33): Cannot find name 'require'.
(2304).. \\ e2e \\ features \\ step_definitions \\ factory \\ factory-form.steps.ts(1,33):找不到名称'require'。 (2304) ..\\e2e\\features\\step_definitions\\factory\\factory-form.steps.ts (4,42): Cannot find module 'cucumber-tsflow'.
(2304).. \\ e2e \\ features \\ step_definitions \\ factory \\ factory-form.steps.ts(4,42):找不到模块'cucumber-tsflow'。 (2307) ..\\e2e\\features\\step_definitions\\factory\\factory-form.steps.ts (5,19): Cannot find namespace 'cucumber'.
(2307).. \\ e2e \\ features \\ step_definitions \\ factory \\ factory-form.steps.ts(5,19):找不到名称空间'cucumber'。 (2503) ..\\e2e\\features\\step_definitions\\factory\\factory-form.steps.ts (10,7): Experimental support for decorators is a feature that is subject to change in a future release.
(2503).. \\ e2e \\ features \\ step_definitions \\ factory \\ factory-form.steps.ts(10,7):对装饰器的实验支持是一个在将来的版本中可能会发生变化的功能。 Set the 'experimentalDecorators' option to remove this warning.
设置'experimentalDecorators'选项以删除此警告。 (1219) ..\\e2e\\features\\step_definitions\\factory\\factory-form.steps.ts (14,13): Experimental support for decorators is a feature that is subject to change in a future release.
(1219).. \\ e2e \\ features \\ step_definitions \\ factory \\ factory-form.steps.ts(14,13):对装饰器的实验支持是一个在将来的版本中可能会发生变化的功能。 Set the 'experimentalDecorators' option to remove this warning.
设置'experimentalDecorators'选项以删除此警告。 (1219) ..\\e2e\\features\\step_definitions\\factory\\factory-form.steps.ts (15,9): Cannot find name 'browser'.
(1219).. \\ e2e \\ features \\ step_definitions \\ factory \\ factory-form.steps.ts(15,9):找不到名称'浏览器'。 (2304) ..\\e2e\\features\\step_definitions\\factory\\factory-form.steps.ts (15,21): Cannot find name 'browser'.
(2304).. \\ e2e \\ features \\ step_definitions \\ factory \\ factory-form.steps.ts(15,21):找不到名称'浏览器'。 (2304) ..\\e2e\\features\\step_definitions\\factory\\factory-form.steps.ts (16,27): Cannot find name 'element'.
(2304).. \\ e2e \\ features \\ step_definitions \\ factory \\ factory-form.steps.ts(16,27):找不到名称'element'。 (2304) ..\\e2e\\features\\step_definitions\\factory\\factory-form.steps.ts (16,35): Cannot find name 'by'.
(2304).. \\ e2e \\ features \\ step_definitions \\ factory \\ factory-form.steps.ts(16,35):找不到名称'by'。 (2304) ..\\e2e\\features\\step_definitions\\factory\\factory-form.steps.ts (21,13): Experimental support for decorators is a feature that is subject to change in a future release.
(2304).. \\ e2e \\ features \\ step_definitions \\ factory \\ factory-form.steps.ts(21,13):对装饰器的实验支持是一个在将来的版本中可能会发生变化的功能。 Set the 'experimentalDecorators' option to remove this warning.
设置'experimentalDecorators'选项以删除此警告。 (1219) ..\\e2e\\features\\step_definitions\\factory\\factory-form.steps.ts (26,13): Experimental support for decorators is a feature that is subject to change in a future release.
(1219).. \\ e2e \\ features \\ step_definitions \\ factory \\ factory-form.steps.ts(26,13):对装饰器的实验支持是一个在将来的版本中可能会发生变化的功能。 Set the 'experimentalDecorators' option to remove this warning.
设置'experimentalDecorators'选项以删除此警告。 (1219)
(1219)
..\\e2e\\features\\step_definitions\\factory\\factory-form.steps.ts (31,13): Experimental support for decorators is a feature that is subject to change in a future release.
.. \\ e2e \\ features \\ step_definitions \\ factory \\ factory-form.steps.ts(31,13):对装饰器的实验支持是一个在将来的版本中可能会发生变化的功能。 Set the 'experimentalDecorators' option to remove this warning.
设置'experimentalDecorators'选项以删除此警告。 (1219)
(1219)
[13:40:58] E/launcher - Process exited with error code 1
[13:40:58] E / launcher - 进程已退出,错误代码为1
protractor.conf.js protractor.conf.js
require('ts-node/register');
exports.config = {
useAllAngular2AppRoots: true,
exclude: [],
allScriptsTimeout: 110000,
seleniumAddress: 'http://localhost:4444/wd/hub',
baseUrl: "http://localhost:5001/",
framework: 'custom',
frameworkPath: require.resolve('protractor-cucumber-framework'),
capabilities: {
'browserName': 'chrome'
},
cucumberOpts: {
require: ["../e2e/features/step_definitions/factory/*.steps.ts"],
format: "pretty"
},
specs: ['../e2e/features/createfactory.feature'],
onPrepare: function () {
browser.ignoreSynchronization = true;
}
};
factory-form.steps.ts 工厂form.steps.ts
let chai = require('chai').use(require('chai-as-promised'));
let expect = chai.expect;
import {binding, given, when, then} from "cucumber-tsflow";
import Callback = cucumber.CallbackStepDefinition;
import {FactoryFormPageObject} from './factory-form.page';
@binding
class FactoryFormSteps {
private factoryFormPageObject: FactoryFormPageObject = new FactoryFormPageObject();
@given(/^I navigate to factory page$/)
private givenUserClicksFactoryLink(callback: Callback) {
browser.get(browser.baseUrl);
var factoryMenu = element(by.id("factory"));
factoryMenu.click().then(callback);
};
@given(/^I input mandatory fields$/)
private givenUserInputsMandatoryFields(callback: Callback) {
callback(null, 'pending');
};
@when(/^I click save button$/)
private whenUserClicksSaveButton(callback: Callback) {
callback(null, 'pending');
};
@then(/^a new factory should be created with the mandatory fields$/)
private thenFactoryisSaved(callback: Callback) {
callback(null, 'pending');
};
}
factory-form.page.ts 工厂form.page.ts
import ElementArrayFinder = protractor.ElementArrayFinder;
import Promise = webdriver.promise.Promise;
export class FactoryFormPageObject {
private form;
private nameInput;
private address1Input;
private countryDropdown;
private submitButton;
private goToFactoryLink;
constructor() {
this.form = element(by.name('factoryForm'));
this.nameInput = this.form.element(by.name('factoryName'));
this.address1Input = this.form.element(by.name('address1'));
this.countryDropdown = this.form.element(by.name('country'));
this.submitButton = this.form.element(by.name('save'));
this.goToFactoryLink = element(by.id('factory'));
}
setName(value: string): Promise<void> {
return this.nameInput.clear().sendKeys(value);
}
setAddress1(value: string): Promise<void> {
return this.address1Input.clear().sendKeys(value);
}
setCountry(value: string): Promise<void> {
return this.selectDropdownbyNum(this.countryDropdown, 1);
}
selectDropdownbyNum(element, optionNum): Promise<void> {
return element.all(by.tagName('option')).get(optionNum).click();
};
}
package.json 的package.json
{
"name": "ethos-client",
"version": "0.0.0",
"license": "MIT",
"angular-cli": {},
"scripts": {
"start": "ng serve",
"postinstall": "typings install",
"lint": "tslint \"src/**/*.ts\"",
"test": "ng test",
"pree2e": "webdriver-manager update",
"e2e": "protractor"
},
"private": true,
"dependencies": {
"@angular/common": "2.0.0-rc.4",
"@angular/compiler": "2.0.0-rc.4",
"@angular/core": "2.0.0-rc.4",
"@angular/forms": "0.2.0",
"@angular/http": "2.0.0-rc.4",
"@angular/platform-browser": "2.0.0-rc.4",
"@angular/platform-browser-dynamic": "2.0.0-rc.4",
"@angular/router": "3.0.0-beta.1",
"@angular/router-deprecated": "2.0.0-rc.2",
"@angular/upgrade": "2.0.0-rc.4",
"angular2-in-memory-web-api": "0.0.14",
"systemjs": "0.19.27",
"core-js": "^2.4.0",
"reflect-metadata": "^0.1.3",
"rxjs": "5.0.0-beta.6",
"zone.js": "^0.6.12",
"bootstrap": "^3.3.6",
"es6-shim": "0.35.1",
"ng2-bootstrap": "^1.0.17"
},
"devDependencies": {
"angular-cli": "1.0.0-beta.6",
"chai": "^3.5.0",
"chai-as-promised": "^5.3.0",
"codelyzer": "0.0.20",
"cucumber": "^1.2.1",
"ember-cli-inject-live-reload": "1.4.0",
"jasmine-core": "2.4.1",
"jasmine-spec-reporter": "2.5.0",
"karma": "0.13.22",
"karma-chrome-launcher": "0.2.3",
"karma-jasmine": "0.3.8",
"protractor": "3.3.0",
"protractor-cucumber-framework": "^0.6.0",
"ts-node": "0.5.5",
"tslint": "3.11.0",
"typescript": "^1.8.10",
"typings": "^1.0.5"
}
}
I have made my project using Angular-cli ( https://github.com/angular/angular-cli ) and I tried to follow https://github.com/samvloeberghs/protractor-gherkin-cucumberjs-angular2 . 我使用Angular-cli( https://github.com/angular/angular-cli )创建了我的项目,并尝试关注https://github.com/samvloeberghs/protractor-gherkin-cucumberjs-angular2 。
do i need to do some extra step that protractor will compile the typescript files first? 我需要做一些额外的步骤,量角器会先编译打字稿文件吗? or is there anything i am missing?
或者我有什么遗失的?
The main problem is this: 主要问题是:
Cannot find namespace 'protractor'
找不到命名空间'量角器'
You need to fix that. 你需要解决这个问题。 You either need to define
protractor
typings globally or 您需要全局或定义
protractor
import {protractor} from 'protractor'
I don't know your tsconfig.js
or system.config.js
but you essentially have to enable the above to have tsc
resolve protractor
module. 我不知道你的
tsconfig.js
或system.config.js
但你基本上必须启用上面的tsc
解析protractor
模块。
Update typescript to 2.0+ and protractor 4.0+ . 将打字稿更新到2.0+和量角器4.0+。 Make sure you update your global and local version.
确保更新全局和本地版本。 Updating typescript to 2.0 should fix it.
将typescript更新为2.0应该修复它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.