Javascript Cypress能否运行在Cypress文件夹外导入的测试文件?
我正在使用Cypress开发一个E2E测试框架,希望导入Cypress目录之外的规范文件(包含fixture、integration、plugins和support的目录)。当我开始一些初始测试以验证它是否能按预期工作时,我收到这些错误消息,指出错误源于我的测试代码,而不是Cypress。错误的原因是一个TypeError,声明:Javascript Cypress能否运行在Cypress文件夹外导入的测试文件?,javascript,npm,import,node-modules,cypress,Javascript,Npm,Import,Node Modules,Cypress,我正在使用Cypress开发一个E2E测试框架,希望导入Cypress目录之外的规范文件(包含fixture、integration、plugins和support的目录)。当我开始一些初始测试以验证它是否能按预期工作时,我收到这些错误消息,指出错误源于我的测试代码,而不是Cypress。错误的原因是一个TypeError,声明:无法读取未定义的属性“includes” 在这个问题上的互联网搜索并没有真正的帮助,因为似乎没有其他人有这种行为的问题(至少从我的角度来看)。即使当我将我选择作为导入的
无法读取未定义的属性“includes”
在这个问题上的互联网搜索并没有真正的帮助,因为似乎没有其他人有这种行为的问题(至少从我的角度来看)。即使当我将我选择作为导入的spec文件移动到cypress/integration/
中时,同样的问题仍然存在
在这一点上,我被这个问题的原因和解决方法难住了。有什么我遗漏的吗
以下是我在package.json(devdependences和main字段)中得到的内容:
在Cypress目录(Cypress/integration/RunE2ETest.spec.js)之外导入规范文件的我的规范:
Cypress文件夹(SteamHeader.spec)外的spec文件显示了我如何设置导入、导出:
import '../Cypress-E2E/BaseTest';
export default describe('Test Suite for ....' () => {
it('test example'), () => {
}
}
我的BaseTest的文件:
import default before('BaseSetup', () => {
cy.visit('/');
}
有关错误的详细信息:
导致错误的行(node_modules/global dirs/index.js:28:1):
堆栈跟踪:
We dynamically generated a new test to display this failure.
at getGlobalNpmrc (https://store.steampowered.com/__cypress/tests?p=cypress\integration\RunE2ETest.spec.js:86028:23)
at getNpmPrefix (https://store.steampowered.com/__cypress/tests?p=cypress\integration\RunE2ETest.spec.js:86064:30)
at Object.eval (https://store.steampowered.com/__cypress/tests?p=cypress\integration\RunE2ETest.spec.js:86072:32)
at Object.512._process (https://store.steampowered.com/__cypress/tests?p=cypress\integration\RunE2ETest.spec.js:86120:4)
at o (https://store.steampowered.com/__cypress/tests?p=cypress\integration\RunE2ETest.spec.js:1:265)
at eval (https://store.steampowered.com/__cypress/tests?p=cypress\integration\RunE2ETest.spec.js:1:316)
at Object.eval (https://store.steampowered.com/__cypress/tests?p=cypress\integration\RunE2ETest.spec.js:89116:20)
at Object.551.fs (https://store.steampowered.com/__cypress/tests?p=cypress\integration\RunE2ETest.spec.js:89130:4)
at o (https://store.steampowered.com/__cypress/tests?p=cypress\integration\RunE2ETest.spec.js:1:265)
at eval (https://store.steampowered.com/__cypress/tests?p=cypress\integration\RunE2ETest.spec.js:1:316)
at Object.eval (https://store.steampowered.com/__cypress/tests?p=cypress\integration\RunE2ETest.spec.js:70417:28)
at Object.425../fs (https://store.steampowered.com/__cypress/tests?p=cypress\integration\RunE2ETest.spec.js:70842:4)
at o (https://store.steampowered.com/__cypress/tests?p=cypress\integration\RunE2ETest.spec.js:1:265)
at eval (https://store.steampowered.com/__cypress/tests?p=cypress\integration\RunE2ETest.spec.js:1:316)
at Object.eval (https://store.steampowered.com/__cypress/tests?p=cypress\integration\RunE2ETest.spec.js:67474:12)
at Object.411../lib/cypress (https://store.steampowered.com/__cypress/tests?p=cypress\integration\RunE2ETest.spec.js:67503:4)
我们也经历了同样的错误。这是由导入cypress
模块引起的。我猜此模块不打算导入到浏览器中加载的文件中。这是否意味着您必须将库文件和测试脚本存储在cypress目录下?我删除了文件中要求导入的所有行,并将它们替换为require()。由于我使用cypress.json进行了设置,测试脚本至少能够加载URL,但我得到了相同的错误。我想将测试库包含在支持目录下的Cypress index.js中,得到相同的错误。尽管Cypress在前端自动化方面有很多优点,但它在Cypress目录中并不是很灵活。正如所料,我在Cypress目录中添加了POM和测试脚本后,它就按预期运行了。
import default before('BaseSetup', () => {
cy.visit('/');
}
26 |
27 | // Homebrew special case: `$(brew --prefix)/lib/node_modules/npm/npmrc`
> 28 | if (process.execPath.includes('/Cellar/node')) {
| ^
29 | const homebrewPrefix = process.execPath.slice(0, process.execPath.indexOf('/Cellar/node'));
30 | return path.join(homebrewPrefix, '/lib/node_modules/npm/npmrc');
31 | }
We dynamically generated a new test to display this failure.
at getGlobalNpmrc (https://store.steampowered.com/__cypress/tests?p=cypress\integration\RunE2ETest.spec.js:86028:23)
at getNpmPrefix (https://store.steampowered.com/__cypress/tests?p=cypress\integration\RunE2ETest.spec.js:86064:30)
at Object.eval (https://store.steampowered.com/__cypress/tests?p=cypress\integration\RunE2ETest.spec.js:86072:32)
at Object.512._process (https://store.steampowered.com/__cypress/tests?p=cypress\integration\RunE2ETest.spec.js:86120:4)
at o (https://store.steampowered.com/__cypress/tests?p=cypress\integration\RunE2ETest.spec.js:1:265)
at eval (https://store.steampowered.com/__cypress/tests?p=cypress\integration\RunE2ETest.spec.js:1:316)
at Object.eval (https://store.steampowered.com/__cypress/tests?p=cypress\integration\RunE2ETest.spec.js:89116:20)
at Object.551.fs (https://store.steampowered.com/__cypress/tests?p=cypress\integration\RunE2ETest.spec.js:89130:4)
at o (https://store.steampowered.com/__cypress/tests?p=cypress\integration\RunE2ETest.spec.js:1:265)
at eval (https://store.steampowered.com/__cypress/tests?p=cypress\integration\RunE2ETest.spec.js:1:316)
at Object.eval (https://store.steampowered.com/__cypress/tests?p=cypress\integration\RunE2ETest.spec.js:70417:28)
at Object.425../fs (https://store.steampowered.com/__cypress/tests?p=cypress\integration\RunE2ETest.spec.js:70842:4)
at o (https://store.steampowered.com/__cypress/tests?p=cypress\integration\RunE2ETest.spec.js:1:265)
at eval (https://store.steampowered.com/__cypress/tests?p=cypress\integration\RunE2ETest.spec.js:1:316)
at Object.eval (https://store.steampowered.com/__cypress/tests?p=cypress\integration\RunE2ETest.spec.js:67474:12)
at Object.411../lib/cypress (https://store.steampowered.com/__cypress/tests?p=cypress\integration\RunE2ETest.spec.js:67503:4)