My current task involves creating a script with a list of websites and corresponding amounts in a JSON format:
{
"URL": [{
"https://testing.com/en/p/-12332423/": "999"
}, {
"https://testing.com/en/p/-123456/": "123"
},
{
"https://testing.com/en/p/-456436346/": "422"
}
]
}
The structure is Link: Amount.
Currently, my goal is to open each website and input the specified amount. For example, opening
https://testing.com/en/p/-12332423/
with an amount of 999
Once this is completed, I move on to the next site, such as
https://testing.com/en/p/-123456/
with an amount of 123
, and so forth.
Thus far, I have only been able to make one page work using:
{
"URL": "https://testing.com/en/p/-12332423/"
}
with the following code:
const userData = require('../globalContent.json');
describe('Add To Cart', function () {
it('Open Product URL', (done) => {
browser.driver
.then(() => browser.waitForAngularEnabled(false))
.then(() => browser.manage().window().maximize())
.then(() => browser.get(userData.URL))
.then(() => done());
});
//Hardcoded to write 999
it('Enter 999 Items', function (done) {
browser.driver
.then(() => utils.presenceOf(element(by.id('amount'))))
.then(() => element(by.id('amount')).clear())
.then(() => utils.sendKeys(element(by.id('amount')), "999"))
.then(() => done());
});
After completing the process for a specific site, I want to redirect to another designated site, such as:
it('Finished all sites', (done) => {
browser.driver
.then(() => browser.waitForAngularEnabled(false))
.then(() => browser.manage().window().maximize())
.then(() => browser.get("https://finished.com"))
.then(() => done());
});
I am uncertain about the efficiency of using a dictionary-based list for linking websites to amounts. I welcome any suggestions for improvement but ultimately aim to loop through each site and enter the corresponding amount.
Open first link from JSON list dictionary -> Add amount -> Open second link from JSON -> Add amount -> Repeat until all sites are processed -> Redirect to new page https://finished.com
Given the information at hand, how can I achieve this?