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.
In addition to @Tom's answer, you can assign the test data path to params
object of conf.js file and access it in any file just by using the variable name.
Look at below example config.js file.
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
capabilities: {
'browserName': 'chrome'
},
onPrepare: function () {
},
params: {
testdata: require('path/to/json/file.json')
}
}
And inside you pageObjects or Spec, You can access the data using browser.params.testdata.users
or whatever the name of testdata object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With