Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/457.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 如何将json数据存储到Cypress中的变量_Javascript_Cypress_Cypress Cucumber Preprocessor - Fatal编程技术网

Javascript 如何将json数据存储到Cypress中的变量

Javascript 如何将json数据存储到Cypress中的变量,javascript,cypress,cypress-cucumber-preprocessor,Javascript,Cypress,Cypress Cucumber Preprocessor,我正在尝试从json文件中获取员工ID,格式如下,在Cypress中,但返回错误如下 无法读取null的属性“name” 如何检索用户名“Devin Miller”的员工id?请帮忙 { "data": [ { "role": "Software Engineer", "organization": "Google", "name"

我正在尝试从json文件中获取员工ID,格式如下,在Cypress中,但返回错误如下
无法读取null的属性“name”

如何检索用户名“Devin Miller”的员工id?请帮忙

{
  "data": [
    {
      "role": "Software Engineer",
      "organization": "Google",
      "name": "Remi Arsenault",
      "emplyeeID":"526321",
      "project": "Stadia"
    },
    {
      "role": "Data Analyst",
      "organization": "Google",
      "emplyeeID": "526322",
      "name": "Devin Miller",
      "project": "Stadia"
    }
  ]
}

下面是我的代码

export function GetUserData(employeeName){     
    cy
      .fixture('users')
      .its('data')
      .then((users) => {     
        Users = users.find(user => user.name === employeeName);
      })
  }

export var Users = null;

现在,如果我尝试执行以下操作,则返回错误

var employeeID = Users["Remi Arsenault"].emplyeeID

我认为您对异步与snyc代码有一些不好的期望

此外,为了访问夹具数据,您可以尝试使用此选项,而不是
。其('data)

cy.fixture('users')。然后((usersJson)=>{
让foundUser=usersJson.data.find(user=>user.name==='Remi Arsenault');
让emloyeid=foundUser.employeeID
…[“你想做的任何事情都可以进入then回调中。”
});

我认为您对异步与snyc代码有一些不好的期望

此外,为了访问夹具数据,您可以尝试使用此选项,而不是
。其('data)

cy.fixture('users')。然后((usersJson)=>{
让foundUser=usersJson.data.find(user=>user.name==='Remi Arsenault');
让emloyeid=foundUser.employeeID
…[“你想做的任何事情都可以进入then回调中。”
});