Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timeouts caused by checking for results on page when results exist inside an iframe #45

Open
picones opened this issue Oct 20, 2022 · 1 comment

Comments

@picones
Copy link

picones commented Oct 20, 2022

This is ultimately more of a question than anything else, but could potentially be an issue.

When initially running LTS against our LMS, many of the tests failed due to a timeout while waiting for this action in getResults inside lts/lib/helpers.js: await page.waitForSelector("#result");

When looking at the content manually in a browser, however, I found that the element the tests were searching for was present, but it was inside an iframe. For whatever reason, puppeteer wasn't finding any elements within the iframe on the page.

I modified the getResults function to this implementation which waits for the iframe, then gets the frame and checks it for the results element. If that fails, it reverts back to the original implementation and checks the main page for the results element, and if that fails, it reports the exception.

The question is -- was that OK to do, or should the original implementation not have had any issues with finding the results, and if it does then that's a problem with our LMS? I always have to assume that getting tests to pass by changing details of the test is not typically the right thing to do.

Below is my implementation of the getResult function, complete with wonky try/catch inside a catch 😅

getResult: async () => {
        let resultElement;

        const frameElement = await page.waitForSelector("iframe"),
            frame = await frameElement.contentFrame();

        try {
            resultElement = await frame.waitForSelector("#result");
        }
        catch (ex) {
            try {
                resultElement = await page.waitForSelector("#result");
            }
            catch (ex2) {
                throw new Error(`Failed to get result from content:\n Outer Ex: ${ex};\n\t inner ex: ${ex2}`);
            }
        }

        const jsonString = await resultElement.evaluate(el => el.textContent);

        let result;

        try {
            result = JSON.parse(jsonString);
        }
        catch (ex) {
            throw new Error(`Failed to parse JSON from string: '${jsonString}'`);
        }

        return result;
    },
@picones
Copy link
Author

picones commented Oct 20, 2022

An addition -- I also noticed that we were timing out on the test for content 003-launchMethod-OwnWindow, even with my changes. Loading and launching the content manually resulted in this result:
image

So I think this is another case where helpers.js would need to be updated to check for a popup window as well (again - assuming my changes were correct in the first place).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant