Forgive a beginners question. I am learning JS to help with my Cypress automation skills - this may be a bad solution and I'm happy to learn a better way.
Given a json file versions.json
{
"cypress": "1.1.0",
"playwright": "1.1.0",
"seleniumJava": "1.1.0",
"geb": "1.1.0",
"postman": "1.1.0"
}
I need to iterate through each url, visit the relevant release page and get the latest tool version.
My specific question is, how do I pass the tool from the tools array so I can interpolate it into here:
let version = data.{tool}version;
...to allow cypress to know which tool version to get?
//env vars to get the relevant urls here
const urls = [cypressBaseUrl, playwrightBaseUrl, seleniumJavaBaseUrl, gebBaseUrl, postmanBaseUrl]
const tools = ["cypress", "playwright", "seleniumJava", "geb", "postman"]
it("Gets the latest release versions", () => {
urls.forEach(function (url) {
tools.forEach(function (tool) {
cy.readFile('cypress/fixtures/versions.json').then((data) => {
let version = data.{tool}version; //how do I pass each tool here?
let updated
cy.visit(url)
cy.get('div.nuxt-content')//refactor to work for all tools
.first('h2')
.then(txt => {
const versionTxt = txt.find("h2").text()//get latest version
versionTxt = version
cy.writeFile('cypress/fixtures/versions.json', {
tool: versionTxt
})
})
})
})
})
})
})