Symfony 5-PhpUnit Panther:此版本的ChromeDriver仅支持Chrome版本80

时间:2020-07-27 12:21:02

标签: php symfony selenium-chromedriver phpunit

我正在尝试将Panther与PhpUnit一起使用,看起来还可以,但是当我尝试登录这样的用户时

        $client = static::createPantherClient();

        /** @var User $user */
        $user = $this->getSuperAdminAccount();

        $session = self::$container->get('session');

        $token = new UsernamePasswordToken($user, null, 'main', $user->getRoles());
        $session->set('_security_main', serialize($token));
        $session->save();

        $cookie = new Cookie($session->getName(), $session->getId());
        $client->getCookieJar()->set($cookie);

然后启动测试,出现以下错误:

Facebook\WebDriver\Exception\SessionNotCreatedException : session not created: This version of ChromeDriver only supports Chrome version 80

我有最新的chrome版本:

enter image description here

但是Panther不允许使用与我们的Chrome版本关联的chromeDriver。所以我真的不知道我能做什么

2 个答案:

答案 0 :(得分:1)

这是我的配置:

composer show symfony/panther                  
name     : symfony/panther
descrip. : A browser testing and web scraping library for PHP and Symfony.
keywords : e2e, scraping, selenium, symfony, testing, webdriver
versions : * v0.7.1

symfony / panther的0.7.1版本具有chromedriver 80. *,这就是问题所在。

存在一个未解决的问题: https://github.com/symfony/panther/issues/356

我们需要更新的版本

编辑: 开发人员环境的临时解决方法:

CHROME_MAIN_VERSION=`google-chrome-stable --version | sed -E 's/(^Google Chrome |\.[0-9]+ )//g'`
CHROMEDRIVER_VERSION=`curl -s "https://chromedriver.storage.googleapis.com/LATEST_RELEASE_$CHROME_MAIN_VERSION"`
curl "https://chromedriver.storage.googleapis.com/${CHROMEDRIVER_VERSION}/chromedriver_linux64.zip" -O
unzip chromedriver_linux64.zip -d ./${projectpath}/vendor/symfony/panther/chromedriver-bin
mv ./${projectpath}/vendor/symfony/panther/chromedriver-bin/chromedriver ./${projectpath}/vendor/symfony/panther/chromedriver-bin/chromedriver_linux64

答案 1 :(得分:0)

对于遇到同样错误的人,我就是这样做的:

  • PANTHER_CHROME_DRIVER_BINARY=./chromedriver中添加.env.test
  • 运行测试

如果您使用的是 Mac,您可能会注意到 “chromedriver” cannot be opened because the developer cannot be verified。 只需在您的系统偏好设置中启用它。