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

Configure screenshots_dir in code, expose savedScreenshots #148

Open
tacman opened this issue Apr 3, 2024 · 3 comments
Open

Configure screenshots_dir in code, expose savedScreenshots #148

tacman opened this issue Apr 3, 2024 · 3 comments

Comments

@tacman
Copy link

tacman commented Apr 3, 2024

I want to use this awesome library to navigate my site and save screenshots, not necessarily as part of a functional test, but just a regular app.

final class AppScreenshotsCommand extends InvokableServiceCommand
{
    use PantherTestCaseTrait;
    use HasBrowser;

    public function __invoke(
        IO $io,
    ): void {
        $browser = $this->pantherBrowser(['screenshot_dir' => './screenshots']);
        $browser->visit('/')
            ->wait(4000) // wait for css??
            ->takeScreenshot('homepage.jpg');
        dd($browser->getSavedScreenshots());

How can I set the screenshot_dir in my console command? The above does not work, $options is different in that call.

Also, to get the screenshots at the end, I needed to add a getter to the PantherBrowser.php, would you accept a PR for that?

    public function getSavedScreenshots(): array
    {
        return $this->savedScreenshots;
    }

I am trying to use this to solve the problem of creating screenshots requiring authenticated users, e.g.

Spomky-Labs/pwa-bundle#134

@tacman
Copy link
Author

tacman commented Apr 3, 2024

There's probably a more elegant way, but I fixed the directory like this:

        $_SERVER['BROWSER_SCREENSHOT_DIR'] = './screenshots';
        $browser = $this->pantherBrowser();

@kbond
Copy link
Member

kbond commented Apr 9, 2024

$_SERVER['BROWSER_SCREENSHOT_DIR'] = './screenshots';

Yeah, that's the way currently. The env var options got a bit out of control as I added features - I'd like to normalize this at some point.

I needed to add a getter to the PantherBrowser.php, would you accept a PR for that?

Yep, sure!

tacman added a commit to tacman/zenstruck-browser that referenced this issue Jun 10, 2024
@tacman
Copy link
Author

tacman commented Sep 5, 2024

Hmm, I'm doing something wrong, even waiting 8 seconds I'm not seeing any of the css applied.

FWIW, I'm in dev and using assetmapper.

        $_SERVER['BROWSER_SCREENSHOT_DIR'] = './screenshots';
        $_SERVER['PANTHER_CHROME_ARGUMENTS'] = "--disable-dev-shm-usage --window-size=600,800 --no-sandbox --headless --hide-scrollbars";

        $browser = $this->pantherBrowser();
        $browser->visit('/')
            ->wait(8000)
            ->takeScreenshot('homepage.jpg');

homepage

symfony open:local works quickly and as expected:

image

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

No branches or pull requests

2 participants