Skip to content

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

@picones

Description

@picones

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;
    },

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions