Each key must be a number of string; got undefined

2019-03-03 10:30发布

I am trying to read data from json file but I have some trouble. How can I get items from a json file to individual items?

My json file:

[
 {
  "UserName": "test@test.en",
  "Password": "tests123"
 }
]

My method:

element(by.name('username')).sendKeys(browser.params.UserName);
element(by.name('password')).sendKeys(browser.params.Password);

as a result i get

Failed: each key must be a number of string; got undefined

1条回答
Lonely孤独者°
2楼-- · 2019-03-03 11:25

You are passing an array of object and not an object, thus, you have to be precise in your variable.

Either directly pass an object

{
  "UserName": "test@test.en",
  "Password": "tests123"
}

Or specify the index in the array

element(by.name('username')).sendKeys(browser.params[0].UserName);
element(by.name('password')).sendKeys(browser.params[0].Password);
查看更多
登录 后发表回答