Each key must be a number of string; got undefined protractor

后端 未结 2 1363
臣服心动
臣服心动 2021-01-23 06:26

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:

[
 {
  \"UserNam         


        
相关标签:
2条回答
  • 2021-01-23 07:04

    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);
    
    0 讨论(0)
  • 2021-01-23 07:22

    My Test was also failing with json file then i converted my datafile into ts file like below

    export const DataForSearch =
    {
        Login:
        { 
            CorrectCreds: { username: 'test@test.en', 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

    0 讨论(0)
提交回复
热议问题