Typescript 量角器+;打字脚本+;Cucumber:未定义的步骤定义错误

Typescript 量角器+;打字脚本+;Cucumber:未定义的步骤定义错误,typescript,protractor,cucumberjs,Typescript,Protractor,Cucumberjs,我正在学习量角器/打字脚本/黄瓜,下面是我的第一个脚本。当我试图执行它的时候,我得到了一个错误(也在下面提到)并且被它卡住了。有人能告诉我我错过了什么吗 我已经定义了特征的步骤,但仍然得到步骤未定义的错误。 以下是当前状态的屏幕截图: 我所做的一切: 1) 我尝试过切换Step def的位置,甚至将其指向Step_def.js而不是ste_def.ts 当我在“require”中更新路径时,也会出现以下错误: “C:\Program Files\nodejs\node.exe” C:\Use

我正在学习量角器/打字脚本/黄瓜,下面是我的第一个脚本。当我试图执行它的时候,我得到了一个错误(也在下面提到)并且被它卡住了。有人能告诉我我错过了什么吗

我已经定义了特征的步骤,但仍然得到步骤未定义的错误。 以下是当前状态的屏幕截图:

我所做的一切:

1) 我尝试过切换Step def的位置,甚至将其指向Step_def.js而不是ste_def.ts

当我在“require”中更新路径时,也会出现以下错误:

“C:\Program Files\nodejs\node.exe” C:\Users***\WebstormProjects\CucumberProject\node\u modules\dragrator\bin\dragrator “C:\ProgramFiles\JetBrains\WebStorm 2018.3.1\plugins\JavaScriptLanguage\helpers\dragrator intellij\lib\dragrator intellij config.js” --intellijOriginalConfigFile=C:\Users***\WebstormProjects\CucumberProject\config\config\CucumberConfiguration.js --disableChecks[13:56:40]I/launcher-运行WebDriver[13:56:40]I/direct的1个实例-直接使用ChromeDriver。。。 [13:56:43]E/发射器-错误:

C:\Users***\WebstormProjects\CucumberProject\StepDefs\my_steps.ts:1 (函数(导出、要求、模块、_文件名、_目录名){import 来自“量角器”的{browser,by,element}

合成错误:

新脚本中出现意外的标记{(vm.js:74:7)

2) 全部删除并重新安装

以下是代码片段:

黄瓜配置。ts

exports.config={
使用Allangular2方法:正确,
能力:{
浏览器名称:“chrome”
},
规格:[“../../FeatureFiles/*.feature”],
框架:“自定义”,
frameworkPath:require.resolve(“量角器框架”),
directConnect:没错,
noGlobals:是的,
黄瓜:{
编译器:[],
严格:是的,
要求:“../StepDefs/*.js”,
//要求:'../StepDefs/*.js',
//require:“../StepDefs/my_steps.ts”,
标签:假,
//格式:['pretty'],
个人资料:错,
“无来源”:正确
}
};
my_steps.ts

从“量角器”导入{browser,by,element};
var myStepDefinitionsWrapper=函数(){
给定(/^I在第一页$/,异步函数(回调){
浏览器
.得到(
"http://www.way2automation.com/angularjs-protractor/registeration/#/login"
)
.然后(函数(){
浏览器睡眠(1000);
});
wait元素(browser.model(“Auth.user.name”)).sendKeys(“angular”);
wait元素(by.id(“密码”)).sendKeys(“密码”);
wait元素(by.id(“formly\u 1\u input\u username\u 0”)).sendKeys(“angular”);
等待元素(按.className(“btn btn danger”)。单击();
等待元素
.all(by.css(“[href*=”#/login']))
.first()
。单击()
.然后(函数(){
log(元素(by.id(“formly\u 1\u input\u username\u 0”));
});
});
};
module.exports=myStepDefinitionsWrapper;
package.json

{
  "name": "CucumberProject",
  "version": "1.0.0",
  "description": "First Framework of Protractor with Type Script and cucumber",
  "main": "index.js",
  "scripts": {
    "test": "protractor tmp/config/configuration.js",
    "pretest": "tsc",
    "cucumbertest": "protractor config/config/CucumberConfiguration.js",
    "protractor": "./node_modules/protractor/built/cli.js",
    "webdriver-update": "./node_modules/.bin/webdriver-manager update"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@types/cucumber": "^6.0.0",
    "@types/jasmine": "^3.5.0",
    "@types/jasminewd2": "^2.0.8",
    "@types/node": "^12.12.21",
    "cucumber": "~6.0.5",
    "jasmine": "^3.5.0",
    "package.json": "^2.0.1",
    "protractor-cucumber-framework": "^6.2.0",
    "ts-node": "^8.5.4",
    "protractor": "^5.4.2",
    "typescript": "3.6.4"
  }
} 
{
  "compilerOptions": {
    "target": "es6",
    "module": "commonjs",
    "moduleResolution": "node",
    "inlineSourceMap": true,
    "declaration": false,
    "noImplicitAny": false,
    "outDir": "config",
    "skipLibCheck": true
  },
  "exclude": [
    "node_modules",
    "asyncAwait",
    "plugins.ts"
  ]
} 
tsconfig.json

{
  "name": "CucumberProject",
  "version": "1.0.0",
  "description": "First Framework of Protractor with Type Script and cucumber",
  "main": "index.js",
  "scripts": {
    "test": "protractor tmp/config/configuration.js",
    "pretest": "tsc",
    "cucumbertest": "protractor config/config/CucumberConfiguration.js",
    "protractor": "./node_modules/protractor/built/cli.js",
    "webdriver-update": "./node_modules/.bin/webdriver-manager update"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@types/cucumber": "^6.0.0",
    "@types/jasmine": "^3.5.0",
    "@types/jasminewd2": "^2.0.8",
    "@types/node": "^12.12.21",
    "cucumber": "~6.0.5",
    "jasmine": "^3.5.0",
    "package.json": "^2.0.1",
    "protractor-cucumber-framework": "^6.2.0",
    "ts-node": "^8.5.4",
    "protractor": "^5.4.2",
    "typescript": "3.6.4"
  }
} 
{
  "compilerOptions": {
    "target": "es6",
    "module": "commonjs",
    "moduleResolution": "node",
    "inlineSourceMap": true,
    "declaration": false,
    "noImplicitAny": false,
    "outDir": "config",
    "skipLibCheck": true
  },
  "exclude": [
    "node_modules",
    "asyncAwait",
    "plugins.ts"
  ]
} 

这是一个typescript错误。您正在尝试运行typescript文件,或者某个typescript类型定义丢失

在您的配置文件中,我看到您指向的是
specs:[“../../../FeatureFiles/*.feature”]
,如果您没有在文件名的末尾指定扩展名,将拾取typescript文件以执行此语法“{”错误。请尝试在
specs:[“../../FeatureFiles/*.feature.js”之后添加.js

同时确保在执行测试时运行的是量角器js文件,而不是ts文件

如果这不起作用,请尝试在package.json中检查是否缺少量角器或cucumber的一些类型定义。

我找到了解决方案- 创建以下步骤解决了问题-

给定('我在第一页',函数(){

早些时候是-


给定(/^我在第一页$/,异步函数(回调){

Try require:['../StepDefs/*.ts'],您好,谢谢您的评论。我尝试过,但运气不佳。我从“量角器”中获得:(函数(导出、require、模块、文件名、目录名){import{browser、by、element};^SyntaxError:意外标记{