admin管理员组文章数量:1352168
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": "[email protected]",
"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
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": "[email protected]",
"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
Share
Improve this question
edited Sep 21, 2017 at 9:15
onetwo12
2,4395 gold badges24 silver badges35 bronze badges
asked Sep 21, 2017 at 7:27
danio900409danio900409
2652 gold badges6 silver badges24 bronze badges
1
-
1
browser.params[0].UserName assuming
browser.params = [ { "UserName": "[email protected]", "Password": "tests123" } ]
– mplungjan Commented Sep 21, 2017 at 7:28
2 Answers
Reset to default 6You 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": "[email protected]",
"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);
My Test was also failing with json file then i converted my datafile into ts file like below
export const DataForSearch =
{
Login:
{
CorrectCreds: { username: '[email protected]', password: 'tests123' }
}
};
then use this in my test case like
import {DataForSearch } from "../DataLogin"
const using = require("jasmine-data-provider");
describe("Login Page", () => {
using(DataForSearch.Login, (data: any, alldesc: any) => {
it("Login", () => {
element(by.name('username')).sendKeys(data.username);
element(by.name('password')).sendKeys(data.password);
})
})
})
you can try typescript file, if you still facing issue.If you face any issue let me know
本文标签: javascriptEach key must be a number of string got undefined protractorStack Overflow
版权声明:本文标题:javascript - Each key must be a number of string; got undefined protractor - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743875880a2554314.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论