获取错误无法读取属性'长度'当我用黄瓜框架运行我的量角器测试时,未定义

时间:2015-12-07 04:43:26

标签: cucumber automated-tests protractor

我最近开始使用黄瓜框架进行量角器研究。我创建了自己的第一个样本测试并得到了以下错误

  

[launcher]运行WebDriver [launcher]的1个实例错误:   TypeError:无法读取属性' length'未定义的       在Function.Configuration(/usr/local/lib/node_modules/cucumber/lib/cucumber/cli/configuration.js:8:11)       at /usr/local/lib/node_modules/protractor/lib/frameworks/cucumber.js:148:39       在Function.promise(/usr/local/lib/node_modules/protractor/node_modules/q/q.js:650:9)       at /usr/local/lib/node_modules/protractor/lib/frameworks/cucumber.js:147:14       在_fulfilled(/usr/local/lib/node_modules/protractor/node_modules/q/q.js:797:54)       at self.promiseDispatch.done(/usr/local/lib/node_modules/protractor/node_modules/q/q.js:826:30)       在Promise.promise.promiseDispatch(/usr/local/lib/node_modules/protractor/node_modules/q/q.js:759:13)       at /usr/local/lib/node_modules/protractor/node_modules/q/q.js:525:49       在flush(/usr/local/lib/node_modules/protractor/node_modules/q/q.js:108:17)       at doNTCallback0(node.js:417:9)[launcher]进程已退出,错误代码为100

我重新安装了黄瓜,但我仍然收到错误。有人可以帮我解决这个问题吗?

2 个答案:

答案 0 :(得分:3)

您使用的版本可能存在问题。

使用protractor --versionpackage.json时,我遇到了同样的问题。 (运行"cucumber": "~0.7.0",检查)

尝试将npm install文件更改为npm remove cucumber npm install --save-dev cucumber@0.7.0并再次运行protractor v3.x

根据Anmol的回复:

public static void main(String[] args) { String text = "Hi:" + " " + "My Name is Alex and my mail is alexmail@domain.com but you can reply to " + "alexreply@other.domain.com." + " a@mail.com" + " abcd@mail.com"; String emailPattern = "[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*" + " @[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})"; emailPattern = "(?<emailHead>[_A-Za-z0-9-\\+]{1,3})+?(?<replacementEmailPart>[_A-Za-z0-9-\\+]*)*?(?<emailTail>@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})){1}"; Pattern p = Pattern.compile(emailPattern); Matcher m = p.matcher(text); StringBuffer sb = new StringBuffer(); while (m.find()) { String replStr = m.group("replacementEmailPart"); if (replStr != null) { replStr = replStr.replaceAll("[_A-Za-z0-9-\\+]", "*"); } else { replStr = "****"; } m.appendReplacement(sb, m.group("emailHead") + replStr + m.group("emailTail")); } m.appendTail(sb); System.out.println(sb.toString()); }

如果您使用的是byte c= a+b;,请参阅此处https://angular.github.io/protractor/#/frameworks#using-cucumber

答案 1 :(得分:0)

将黄瓜升级到0.9.5时,我遇到了同样的问题:

Using the selenium server at http://localhost:4444/wd/hub
[launcher] Running 1 instances of WebDriver
[launcher] Error: TypeError: Cannot read property 'length' of undefined

所以,事实证明量角器不再嵌入黄瓜了,我必须在package.json中添加一行:

"protractor-cucumber-framework": "^0.6.0",

然后在我的protractor.conf中更新“framework”:

"framework": "custom", // "cucumber"

然后在我的protractor.conf中添加:

frameworkPath: "node_modules/protractor-cucumber-framework",

然后运行npm install,当您再次运行量角器测试时,TypeError将消失。