Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/402.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何从cypress项目中读取JSON文件?_Javascript_Cypress - Fatal编程技术网

Javascript 如何从cypress项目中读取JSON文件?

Javascript 如何从cypress项目中读取JSON文件?,javascript,cypress,Javascript,Cypress,我从cypress automation开始,现在正在努力处理JSON文件 有人知道我如何读取JSON文件,比如位于../example/vehicle.JSON中的JSON文件吗 我知道cypress是JavaScript,但我在cypress项目中导入JQuery时也遇到了问题。我从未使用过cypress,在查看文档时,我认为这可以帮助您解决问题 cy.fixture(filePath) cy.fixture(filePath, encoding) cy.fixture(filePath,

我从cypress automation开始,现在正在努力处理JSON文件

有人知道我如何读取JSON文件,比如位于../example/vehicle.JSON中的JSON文件吗


我知道cypress是JavaScript,但我在cypress项目中导入JQuery时也遇到了问题。

我从未使用过cypress,在查看文档时,我认为这可以帮助您解决问题

cy.fixture(filePath)
cy.fixture(filePath, encoding)
cy.fixture(filePath, options)
cy.fixture(filePath, encoding, options)

请查看

以防这对任何人都有帮助,有一个很好的方法可以通过以下行实现这一点:

cy.readFile('path/to/file.json/txt/yaml')

据我所知,这将是访问json文件中存储的数据的“Cypress”方式

参考:

其中“user”是/fixtures/user.json

{
    "name": "username",
    "password": "password1234"
}

嘿Cypress geek我成功地使用了它

cy.fixture(profile.json).then((user) => {
        // Delay each keypress by 0.1 sec
        cy.get('#username').type(user.email, { delay: 100 }).should('have.value', user.email)
        cy.get('#password').type(user.password)
      })

非常感谢。这不完全是我想要的,但我能做到
cy.fixture(profile.json).then((user) => {
        // Delay each keypress by 0.1 sec
        cy.get('#username').type(user.email, { delay: 100 }).should('have.value', user.email)
        cy.get('#password').type(user.password)
      })