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

Adjust the size of the window/screenshot #428

Closed
OskarStark opened this issue Feb 18, 2021 · 9 comments
Closed

Adjust the size of the window/screenshot #428

OskarStark opened this issue Feb 18, 2021 · 9 comments

Comments

@OskarStark
Copy link
Contributor

I tried sth like:

<?php

declare(strict_types=1);

namespace App\Tests\Acceptance\Util;

use Facebook\WebDriver\WebDriverDimension;
use Symfony\Component\Panther\Client as PantherClient;
use Symfony\Component\Panther\PantherTestCase;

class ScreenshotTestCase extends PantherTestCase
{
    protected static function createPantherClient(array $options = [], array $kernelOptions = [], array $managerOptions = []): PantherClient
    {
        $client = self::createPantherClient();

        $size = new WebDriverDimension(1400, 4000);
        $client->manage()->window()->maximize()->setSize($size);

        return $client;
    }
}

But the size of the screenshot doesn't change 🤔

@marco-kretz
Copy link

Hey there,

had the same problem. Just add --window-size=1400,900 as chrome arguments :)

@shadowc
Copy link
Contributor

shadowc commented Feb 19, 2021

Hey, I'm facing the same issue! Could you give us a code example of where chrome arguments go, @marco-kretz ? Thanks!

@marco-kretz
Copy link

I'm just using env-vars for this. That's what I have in my .env:

PANTHER_CHROME_ARGUMENTS="--disable-dev-shm-usage --window-size=1400,900 --no-sandbox --headless --hide-scrollbars"

@shadowc
Copy link
Contributor

shadowc commented Feb 19, 2021

Ahh, I see! Thank you! I'll try this!

@shadowc
Copy link
Contributor

shadowc commented Feb 19, 2021

That TOTALLY works! May be in the future we can configure these arguments somewhere within the panther client creation (or a panther.xml.dist file or similar in our projects!)

@marco-kretz
Copy link

That TOTALLY works! May be in the future we can configure these arguments somewhere within the panther client creation (or a panther.xml.dist file or similar in our projects!)

You can totally do that already :)

image

@shadowc
Copy link
Contributor

shadowc commented Feb 19, 2021

I see! May be this is not apparent from createPantherClient.

If I do:

$this->client = static::createPantherClient(
    ['external_base_uri' => 'https://localhost:8000'],
    ['HTTPS' => true],
    ['capabilities' => [
        'acceptInsecureCerts' => true,
    ]],
);

Because I want to use an external server with https, then I need to figure out how this translates to the createChromeClient signature.

@shadowc
Copy link
Contributor

shadowc commented Feb 19, 2021

From panther's source code:

if (static::CHROME === $browser) {
            self::$pantherClients[0] = self::$pantherClient = Client::createChromeClient(null, null, $managerOptions, self::$baseUri);
        } else {
            self::$pantherClients[0] = self::$pantherClient = Client::createFirefoxClient(null, null, $managerOptions, self::$baseUri);
        }

May be we need to accept browser arguments from within createPantherClient to make it more accessible?

@shadowc
Copy link
Contributor

shadowc commented Feb 19, 2021

It would appear by looking at the source code (if I'm not wrong) that if I call Client::createChromeClient I won't have started a WebServer (which I guess it's fine in my case, but not ALL cases) and I won't boot a kernel. What implications does this have for the test case?

ThomasLandauer added a commit to ThomasLandauer/panther that referenced this issue Apr 16, 2021
I haven't tested Chrome; it's taken from symfony#428 (which can be closed now IMO)
Firefox works for me; it's taken from https://stackoverflow.com/a/64374604/1668200
@dunglas dunglas closed this as completed Jul 12, 2021
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

4 participants