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

Screenshots cropped when test fails within an iframe #715

Closed
alecpl opened this issue Jan 13, 2020 · 7 comments
Closed

Screenshots cropped when test fails within an iframe #715

alecpl opened this issue Jan 13, 2020 · 7 comments

Comments

@alecpl
Copy link

alecpl commented Jan 13, 2020

  • Dusk Version: 5.8.1
  • Laravel Version: 5.8
  • PHP Version: 7.4.1
  • Facebook/WebDriver 1.7.1
  • Chromium 79 on Linux

Description:

When a test within an iframe fails the screenshot is cropped. It looks like it contains the main window, but resized to the size of an iframe. Or maybe it loads the main page into the iframe and makes screenshot of that.

Steps To Reproduce:

Create a page with an iframe which is e.g. 50% of the screen. and a failing assertion inside withinFrame method.

@browner12
Copy link
Contributor

did this start happening recently?

I'm curious if maybe my auto-resizing PR has something to do with this.

#704

Could you try adding this to your test, and see if it still happens?

$browser->disableFitOnFailure();

@alecpl
Copy link
Author

alecpl commented Jan 14, 2020

Regression confirmed. It works if I use v5.6.3 or disableFitOnFailure.

@driesvints
Copy link
Member

@browner12 I don't see how that pr could cause this? It's a totally opt-in feature?

@browner12
Copy link
Contributor

You can opt to $browser->fitContent() whenever you want, but with the linked PR we now automatically resize the browser when a failure occurs.

You can opt out of it globally by overriding the Browser and setting fitOnFailure to false, or you can opt out of it on a per-test basis using $browser->disableFitOnFailure().

The underlying ->fitContent() method works by finding the <body> tag and calculating its width and height. The iframe must have another body tag that is being selected instead of the root body tag.

I was under the assumption that $this->driver->findElementWebDriverBy::tagName('body')) found the first matching element, because that's what the docs say they do, but apparently not.

I think I can debug and fix this rather quickly so we don't have to revert the PR. I'll get back to you ASAP.

@driesvints
Copy link
Member

I think I can debug and fix this rather quickly so we don't have to revert the PR. I'll get back to you ASAP.

Perfect 👍

@browner12
Copy link
Contributor

I have run some tests, and the existing code seems to be behaving fine with one or even multiple <iframe>s in the view. It is correctly finding the parent <body> tag and calculating dimensions based on that.

Here's the simplified view I used:

<html>
<body>
    <iframe id="one" src="https://laravel.com" height="300px" width="700px"></iframe>
    <iframe id="two" src="https://laravel.com" height="500px" width="200px"></iframe>
</body>
</html>

and the Dusk test I used:

public function testExample()
{
    $this->browse(function (Browser $browser) {
        $browser->visit('/test');

        $body = $browser->driver->findElement(WebDriverBy::tagName('body'));

        echo "\r\n" . 'Width: ' . $body->getSize()->getWidth();
        echo "\r\n" . 'Height: ' . $body->getSize()->getHeight();

        $browser->fitContent()
                ->screenshot('test')
                ->with('#one', function ($firstIframe) {
                    $firstIframe->assertSee('laravel');
                })
                ->assertSee('dne');
    });
}

@alecpl could you please share your View and Test so we can see if there's anything unique to your code?

@alecpl
Copy link
Author

alecpl commented Jan 14, 2020

As I said my code uses withinFrame().

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

Successfully merging a pull request may close this issue.

3 participants