Describe('The Login', function () {
beforeEach(function () {
cy.readFile(Cypress.env('test')).as("user")});
it("Login", () => {
cy.get("@user").then((user) =>
cy.login(user.username, user.password))})
失败cypress / integration / login.spec.js ●登录页面›
ReferenceError: cy is not defined
at Object.<anonymous> (cypress/integration/login.spec.js:4:5)
at new Promise (<anonymous>)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
答案 0 :(得分:2)
要为@sai的答案添加一些上下文,以解决此eslint错误,我要做的就是安装eslint-plugin-cypress from here。
npm install eslint-plugin-cypress --save-dev
然后,在我的eslint配置中,我向我的extends数组添加了一行。
您的配置可以是.eslintrc.json或package.json中的“ eslintConfig”配置对象
{
"extends": [
"plugin:cypress/recommended"
]
}
答案 1 :(得分:0)
在本地测试,这应该对您有用。更改json文件的路径,然后使用自定义命令cy.login。在我的示例中,我只是将变量打印到控制台。
describe('The Login', () => {
beforeEach(() => {
cy.readFile('cypress/integration/test/test.json').as("user")});
it("Login", () => {
cy.get("@user").then((user) =>
cy.log(user.username, user.pass))
})
})
我的test.json是:
{
"username":"test@test.com",
"pass":"pass"
}
答案 2 :(得分:0)
问题与eslint有关 必须安装一些软件包并更新了eslintrc文件