Synpress无法使用Cy.AcceptmetAmaskAscess(不是函数)
我正在尝试使用synpress,但是我无法理解如何求解,
TypeError: cy.acceptMetamaskAccess is not a function
让我分享相关代码*(我主要遵循本教程 https://medium.com/andamp/how-to-to-to-setup-setup-setup-synpress-synpress-for-for-wen3-dapp, -Frontend-test-automation-with-metamask-733968966684a )
*如果缺少某物,请让我知道
package.json:
{
"devDependencies": {
"@testing-library/cypress": "^8.0.2",
"cypress": "^9.7.0"
},
"scripts": {
"cypress:open": "cypress open",
"test": "env-cmd -f .env npx synpress run -cf synpress.json --config supportFile='tests/support/index.js'",
"test:watch": "env-cmd -f .env npx synpress open -cf synpress.json"
},
"dependencies": {
"@synthetixio/synpress": "^1.2.0",
"env-cmd": "^10.1.0"
}
}
我如何配置我的synpress.json
{
"baseUrl": "https://dappify.com/",
"userAgent": "synpress",
"retries": { "runMode": 0, "openMode": 0 },
"integrationFolder": "tests/integration",
"screenshotsFolder": "screenshots",
"videosFolder": "videos",
"video": true,
"chromeWebSecurity": true,
"viewportWidth": 1366,
"viewportHeight": 850,
"component": {
"componentFolder": ".",
"testFiles": "**/*spec.{js,jsx,ts,tsx}"
},
"env": {
"coverage": false
},
"defaultCommandTimeout": 30000,
"pageLoadTimeout": 30000,
"requestTimeout": 30000,
"supportFile": "tests/support/index.js"
}
简单测试,
describe('Test User Login', () => {
it('Connects with Metamask', () => {
cy.visit('https://dappify.com')
cy.contains('Sign').click();
cy.contains('Confirm').click();
cy.contains('Connect Wallet').click();
cy.contains('Metamask').click();
cy.switchToMetamaskWindow();
cy.acceptMetamaskAccess().should("be.true");
})
})
我不了解为什么cy cy cy .AcceptMetAmaskAsccess()
不是一个函数,我可以在这里找到它: https://github.com/synthetixio/synpress/synpress/blob/master/support/support/index.d.t.ts
我如何使用此index.d.d.ts.d.ts < /代码>文件?
**解决方案**
Fody的答案很有帮助!让我总结所需的步骤:
- 内部
支持
文件夹您需要一个index.js
ins index.js
import './commands'
import "@synthetixio/synpress/support";
如果要添加自定义函数,文件到支持
在commands.js
中也是如此:
import "@testing-library/cypress/add-commands";
// here go(es) your custom function(s)
I'm trying to use Synpress, but I fail to understand how to solve
TypeError: cy.acceptMetamaskAccess is not a function
Let me share the relevant code* (I mostly followed this tutorial https://medium.com/andamp/how-to-setup-synpress-for-wen3-dapp-frontend-test-automation-with-metamask-73396896684a)
*if something is missing, please let me know
package.json:
{
"devDependencies": {
"@testing-library/cypress": "^8.0.2",
"cypress": "^9.7.0"
},
"scripts": {
"cypress:open": "cypress open",
"test": "env-cmd -f .env npx synpress run -cf synpress.json --config supportFile='tests/support/index.js'",
"test:watch": "env-cmd -f .env npx synpress open -cf synpress.json"
},
"dependencies": {
"@synthetixio/synpress": "^1.2.0",
"env-cmd": "^10.1.0"
}
}
How I configured my synpress.json
{
"baseUrl": "https://dappify.com/",
"userAgent": "synpress",
"retries": { "runMode": 0, "openMode": 0 },
"integrationFolder": "tests/integration",
"screenshotsFolder": "screenshots",
"videosFolder": "videos",
"video": true,
"chromeWebSecurity": true,
"viewportWidth": 1366,
"viewportHeight": 850,
"component": {
"componentFolder": ".",
"testFiles": "**/*spec.{js,jsx,ts,tsx}"
},
"env": {
"coverage": false
},
"defaultCommandTimeout": 30000,
"pageLoadTimeout": 30000,
"requestTimeout": 30000,
"supportFile": "tests/support/index.js"
}
Simple test
describe('Test User Login', () => {
it('Connects with Metamask', () => {
cy.visit('https://dappify.com')
cy.contains('Sign').click();
cy.contains('Confirm').click();
cy.contains('Connect Wallet').click();
cy.contains('Metamask').click();
cy.switchToMetamaskWindow();
cy.acceptMetamaskAccess().should("be.true");
})
})
I don't understand why cy.acceptMetamaskAccess()
is not a function, I can find it here: https://github.com/synthetixio/synpress/blob/master/support/index.d.ts
How can I use the functions listed in this index.d.ts
file?
** Solution **
Answer by Fody was helpful! Let me summarise the steps needed:
- inside
support
folder you need anindex.js
inside index.js
import './commands'
import "@synthetixio/synpress/support";
If you want to add custom functions add this file to support
too
inside commands.js
:
import "@testing-library/cypress/add-commands";
// here go(es) your custom function(s)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
解开Synpress结构有点困难。通常,使用插件库会导入支持组件,并将库的自定义命令添加到您的测试中。
文章说
这使我认为最后一个参数是在自定义中带来的,命令。
如果您已经尝试过,则以下是命令定义,可以尝试在规格的顶部添加它。
It's a bit hard to untangle the Synpress structure. Usually with a plugin library you import a support component and that adds the library's custom commands to your test.
The article says
which makes me think the last parameter is bringing in the custom commands.
If you already tried that, the following is the command definition, you can try adding it at the top of your spec.
在命令示例中给出设置参数
:
这对我有用。
Give set parameter in command
Example:
This worked for me.