Open AndriusCTR opened 5 years ago
I don't use Panther, but it looks like it's described in this section of the documentation: https://github.com/symfony/panther#improve-performances-by-having-a-persistent-web-server-running
@alexislefebvre I believe that @AndriusCTR is talking about the actual instance of the chrome browser that's running, rather than Symfony's web server.
I'm also experiencing the same issue with each test taking a long time to start up a new instance of the chromedriver process and then an instance of chrome itself. Would be good to know if there was any way around this.
I had the same issue and when I was creating a test case to demonstrate what's going on, I found a workaround.
I'm using Panther to run a set of smoke tests with an authenticated user. My browser stays open, but sessions gets dropped randomly, I'm not sure why. I added a login step at the beginning of each test case, which does nothing if the user is already logged in, but fills the login form if the user is logged out. Voila.
Here is the method that I'm calling immediately after fetching the Panther client instance. It relies on the fact that unauthenticated users get redirected to the login page automatically. It's not the fastest way to do it (I'm yet to work out how to pre-authenticate the user), but it does work.
protected static function login(Client $client, string $email = 'admin@phpunit')
{
// Users that are already logged in will be redirected to /
$crawler = $client->request('GET', '/login');
// So if the current URL ends with /login, the user was not redirected, meaning the user needs to log in again
if (preg_match('~/login$~', $client->getWebDriver()->getCurrentURL())) {
$form = $crawler->selectButton('Sign in')->form(['email' => $email, 'password' => 'password']);
$client->submit($form);
$client->waitFor('#user-menu-button');
}
}
Is there a way to reuse the same (loaded) chrome instance/session when loading several pages in a row (loop)?
So that you wouldn't have to load full browser into memory for each web page?
Thanks