microsoft / playwright

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
https://playwright.dev
Apache License 2.0
65.79k stars 3.58k forks source link

Question: while reading dynamically created json file inside playwright test and iterate thru json file, seeing an error. #18655

Closed InduKrish closed 1 year ago

InduKrish commented 1 year ago

while reading dynamically created json file inside playwright test and iterate thru json file, seeing an error. TypeError: Cannot perform 'get' on a proxy that has been revoked. Can you please check the below code and clarify what is causing the issue and please recommend if there are any better solutions?


const { promises: fsPromise } = require("fs");
async function loadData() {
    return await fsPromise.readFile("./json/accrual.json", "utf8")
}

test.only("Navigate to Bidding awarding Page", async ({page}) => {
        await actor.attemptsTo(Click.on('Text', /Bidding & Awarding/));
        await actor.attemptsTo(Click.on('Text', /Accruals/));

        await actor.attemptsTo(RetrieveFirstRow.getFirstRow('paged-table-CrewMemberVacationAccruals'));

        loadData().then(async results => {
            let accrual = JSON.parse(results)
            console.log("bidding value is:", accrual)

            for (const data of accrual) {

                console.log("row no" + data.row)
                console.log("row no" + data.originalAccrualDays)
                console.log("row no" + data.adjustedAccrualDays)
                console.log("row no" + data.adjustmentComment)
                await actor.attemptsTo(ClickKebab.on('KebabMenu', 'paged-table-CrewMemberVacationAccruals', data.row));

                await actor.asks(ValidatePageTitleContent.toContainText('header-update-CrewMemberVacationAccrualUpdate', 'Update Accrual'))

                await actor.asks(Elements.notToBe.enabled(/Original Accrual/));
                await actor.asks(Elements.toBe.visible(/Adjusted Accrual/));
                await actor.asks(Elements.toBe.visible(/Comment/));

                await actor.asks(Elements.to.containText('originalAccruedDays', data.originalAccrualDays));
                await actor.asks(Elements.to.containText('adjustedAccruedDays', data.adjustedAccrualDays));
                await actor.asks(Elements.to.containText('adjustmentComment', data.adjustmentComment));
                await actor.attemptsTo(Click.on('Id', 'button-text-modal-save'));

            }

        }).catch(err => {
            console.log(err);
        })

    })
})
``` javascript

<img width="1781" alt="Screen Shot 2022-11-08 at 12 45 08 PM" src="https://user-images.githubusercontent.com/113629123/200649894-28bcbb4e-a3e6-4e5d-83e5-5605b596a570.png">

TypeError: Cannot perform 'get' on a proxy that has been revoked
    at BrowseTheWeb.clickKebab (/Users/x273092/Documents/git/bidandaward/ui/cbna-test-integration-cbna/test-ui/playwright/tests/web/abilities/BrowseTheWeb.js:238:41)
    at ClickKebab.performAs (/Users/x273092/Documents/git/bidandaward/ui/cbna-test-integration-cbna/test-ui/playwright/tests/web/actions/ClickKebab.js:16:46)
    at /Users/x273092/Documents/git/bidandaward/ui/cbna-test-integration-cbna/test-ui/playwright/node_modules/@testla/screenplay/lib/screenplay/Actor.js:67:73
    at /Users/x273092/Documents/git/bidandaward/ui/cbna-test-integration-cbna/test-ui/playwright/tests/crewplanner/bidding.awarding.spec.js:77:17
  Slow test file: [chromium] › tests/crewplanner/bidding.awarding.spec.js (24s)
  Consider splitting slow test files to speed up parallel execution
yury-s commented 1 year ago

You've missed await before loadData().then(async results => { so the test ends without waiting for .then( callback to finish. Changing the code like this should fix the issue (please file a new bug and link to this one if it doesn't):


        const results = await loadData();
            let accrual = JSON.parse(results)
            console.log("bidding value is:", accrual)

            for (const data of accrual) {

                console.log("row no" + data.row)
                console.log("row no" + data.originalAccrualDays)
                console.log("row no" + data.adjustedAccrualDays)
                console.log("row no" + data.adjustmentComment)
                await actor.attemptsTo(ClickKebab.on('KebabMenu', 'paged-table-CrewMemberVacationAccruals', data.row));

                await actor.asks(ValidatePageTitleContent.toContainText('header-update-CrewMemberVacationAccrualUpdate', 'Update Accrual'))

                await actor.asks(Elements.notToBe.enabled(/Original Accrual/));
                await actor.asks(Elements.toBe.visible(/Adjusted Accrual/));
                await actor.asks(Elements.toBe.visible(/Comment/));

                await actor.asks(Elements.to.containText('originalAccruedDays', data.originalAccrualDays));
                await actor.asks(Elements.to.containText('adjustedAccruedDays', data.adjustedAccrualDays));
                await actor.asks(Elements.to.containText('adjustmentComment', data.adjustmentComment));
                await actor.attemptsTo(Click.on('Id', 'button-text-modal-save'));

            }
InduKrish commented 1 year ago

Awesome, Thank you so much.