Can I fetch test data from JSON file to page object file in protractor

protractor

Solution

A simple require statement will do to include a json file into your PageObject.

// The require statement will import your JSON file into the json variable
var json = require('path/to/json/file.json');

// Now you can access data from your json file as usual:
var users = json.users;   //Example 1
var data = json['data'];  //Example 2

Problem

Im working on protractor and I have created one test data (JSON) file for my project, also I'm using Page Object for my script. Sometime I need test data into my Page object file to identify the object on my screen once it is created. I have multiple objects with same css locator, and I want to identify specific one with data i inserted using JSON. I'm using 'cssContainingText' locator to identify the object but unable to get the data directly from JSON. Can anybody help me with solution? I don't know how to call data file (JSON) from page object file.

Original source