【问题标题】:How to fix 'TypeError: Cannot read property 'fn' of undefined" and 'Unable to require Taiko"如何修复“TypeError:无法读取未定义的属性‘fn’”和“无法要求 Taiko”
【发布时间】:2019-08-14 15:17:07
【问题描述】:

尝试使用 taiko 运行 Gauge 以自动化一些 Web 测试。 sudo gauge run specs 抛出两个类型错误和“无法要求 Taiko”

Taiko、nodejs、npm 已安装并且工作正常。仪表似乎大部分都很好。 gauge init js 工作。 我尝试将 .spec 文件移动到不同的目录,并移动 taiko 和 nodejs,没有任何区别。

复制,安装所有必要的东西:

gauge init js

gauge run specs

应该运行 'init' 创建的 .spec 文件

实际上输出太长而无法包含,但会根据要求显示。 错误:

1)

Unable to require module 'taiko' in /home/harry/tests/step_implementation.js
Trace: Error: Cannot find module 'taiko'
Require stack:
- /home/harry/tests/step_implementation.js

2)

const { openBrowser,write, closeBrowser, goto, press, text, focus, inputField, toRightOf } = require('taiko');

^
TypeError: Cannot destructure property `openBrowser` of 'undefined' or 'null'.

3)

new Test(step.fn, parameters, timeout).run().then(

^
TypeError: Cannot read property 'fn' of undefined

4)

[Gauge]
Connection to runner with Pid 15653 lost. The runner probably quit unexpectedly.

【问题讨论】:

标签: javascript node.js ubuntu getgauge


【解决方案1】:

你应该检查你的 node_modules 一次。当您的 node_modules 中没有 taiko 时,就会发生这种错误。 当您执行 gauge init js 时,它会添加到您的本地 node_modules 中。可能出了点问题,所以我猜 Taiko 不在你的 node_modules 中尝试运行 npm install --save taiko。这可能会解决您的问题。谢谢。

【讨论】:

    【解决方案2】:

    什么是文件,上下文,操作系统>.. 原因是因为名字被破坏了......

    未定义是某些符号恕我直言的字符集不匹配的结果...

    【讨论】:

      【解决方案3】:

      Trace: Error: Cannot find module 'taiko' 完全告诉你 taiko 没有安装,运行npm i taiko 再试一次。

      【讨论】: