Replies: 5 comments 1 reply
-
It looks like you're not deserializing the |
Beta Was this translation helpful? Give feedback.
-
const groupCode = JSON.parse(JSON.stringify(require("../../data/groupCodes.json"))); i am already deserializing using JSON.parse, not sure why it is passed as string. |
Beta Was this translation helpful? Give feedback.
-
But you're storing it as a string in your JSON file: // groupCodes.json file
[
{
"code":"03",
"description" : "/NEW HIRE/"
// ↑↑ string ↑↑
}
] |
Beta Was this translation helpful? Give feedback.
-
groupCodes.json [ const groupCode = JSON.parse(JSON.stringify(require("../../data/groupCodes.json")));
groupCode.forEach(data =>
{
test.only(`Group codes table with ${data.description}`, async ({
page, screen, within
}) => {
const table = await screen.findByTestId('nested-table-GroupCode')
const row = within(table).getByRole('row', {name: /NEW HIRE/})
const cell = within(row).getAllByRole('cell')
const activeStatus = await cell.nth(0).textContent();
console.log("Status is :" + activeStatus);
console.log("DATA :" + data.description);
// ↯ Invoke test helper ↯
await checkRow(screen, data.description);
await page.waitForTimeout(3000);
if (activeStatus == 'minus-circle') {
expect(await cell.nth(0).textContent()).toEqual("success")
} else {
expect(await cell.nth(0).textContent()).toEqual("minus-circle")
}
});
}); export async function checkRow(screen, name) {
const edit = await screen.findByTestId("Edit Aircraft Positions");
await edit.click();
const checkbox = await screen.queryByTestId('editable-nested-table-AircraftPosition')
// .within().getByRole('row', {name: /NEW HIRE/}).
.within().getByRole('row', {name: "/" +name +"/"}). --> want to pass json value after parsing here, can you please advise how to add a RegExp expression here after reading the json value
within().getByRole('cell', {name: /check/});
await checkbox.click();
const save = await screen.findByTestId("button-text-save-AircraftPosition");
await save.click();
} Output: not sure how to convert this to a RexExp --> /NEW HIRE/ , it always treats like a String. I am not sure if getByRole('row', {name: "/" +name +"/"}) converts always to a string, it hinders our progress. Can you please advise? |
Beta Was this translation helpful? Give feedback.
-
groupCodes.json Even after using RegexParser, it still fails, const groupCode = JSON.parse(JSON.stringify(require("../../data/groupCodes.json")));
const RegexParser = require('regex-parser');
groupCode.forEach(data =>
{
test.only(`Group codes table with ${data.description}`, async ({
page, screen, within
}) => {
const table = await screen.findByTestId('nested-table-GroupCode')
const row = within(table).getByRole('row', {name: /NEW HIRE/})
const cell = within(row).getAllByRole('cell')
const activeStatus = await cell.nth(0).textContent();
console.log("Status is :" + activeStatus);
console.log("DATA :" + data.description);
const config = JSON.parse('{"description" : "/NEW HIRE/"}'); --> added json string manually and tried, fails as well
// await checkRow(screen, RegexParser(config.description)); --> it fails,
await checkRow(screen, RegexParser(data.description)); ---> it still fails.
await page.waitForTimeout(3000);
if (activeStatus == 'minus-circle') {
expect(await cell.nth(0).textContent()).toEqual("success")
} else {
expect(await cell.nth(0).textContent()).toEqual("minus-circle")
}
});
}); |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
When running parameterized tests using the JSON file or csv file, or from array, see the following error
proxy.click: TestingLibraryElementError: Unable to find an accessible element with the role "row" and name "/NEW HIRE/",
Can you please advise why it throws an error while reading from json or csv file.
// await checkRow(screen, /NEW HIRE/);---> this RegExp works when passed directly, trying to read the same from json or csv file.
await checkRow(screen, "/" + data.description + "/"); ---> string concat also resulted in the same error, Screenshot is attached,
JSON file:
groupCodes.json file
[
{
"code":"03",
"description" : "/NEW HIRE/"
}
]
groupCodes.csv file:
"code","description"
"03","/NEW HIRE/"
CSV file:
helper method:
Beta Was this translation helpful? Give feedback.
All reactions