简单的 PHP Selenium 测试不起作用

发布于 2024-09-25 09:48:13 字数 958 浏览 0 评论 0原文

我在 PHP 中有以下 Selenium 测试:

<?php

require_once('PHPUnit/Extensions/SeleniumTestCase.php');

class Example extends PHPUnit_Extensions_SeleniumTestCase
{
  protected function setUp()
  {
    $this->setBrowser("*chrome");
    $this->setBrowserUrl("http://change-this-to-the-site-you-are-testing/");
  }

  public function testMyTestCase()
  {
    $this->open("/frontend_dev.php");
    try {
        $this->assertTrue($this->isTextPresent("Local Coupons"));
    } catch (PHPUnit_Framework_AssertionFailedError $e) {
        array_push($this->verificationErrors, $e->toString());
    }
  }
}

当我尝试运行它(通过运行“php filename.php”)时,我收到错误:

PHP Fatal error:  Class 'PHPUnit_Framework_TestCase' not found in /usr/share/php/PHPUnit/Extensions/SeleniumTestCase.php on line 60

这是有道理的,因为该类没有在任何地方定义,但为什么不呢?我安装了 PHPUnit。 PHPUnit 中不包含名为 PHPUnit_Framework_TestCase 的类,这似乎有点奇怪。有什么想法吗?

I have the following Selenium test in PHP:

<?php

require_once('PHPUnit/Extensions/SeleniumTestCase.php');

class Example extends PHPUnit_Extensions_SeleniumTestCase
{
  protected function setUp()
  {
    $this->setBrowser("*chrome");
    $this->setBrowserUrl("http://change-this-to-the-site-you-are-testing/");
  }

  public function testMyTestCase()
  {
    $this->open("/frontend_dev.php");
    try {
        $this->assertTrue($this->isTextPresent("Local Coupons"));
    } catch (PHPUnit_Framework_AssertionFailedError $e) {
        array_push($this->verificationErrors, $e->toString());
    }
  }
}

When I try to run it (by running "php filename.php") I get the error:

PHP Fatal error:  Class 'PHPUnit_Framework_TestCase' not found in /usr/share/php/PHPUnit/Extensions/SeleniumTestCase.php on line 60

Which makes sense because the class isn't defined anywhere, but why not? I installed PHPUnit. It seems a little weird that a class called PHPUnit_Framework_TestCase wouldn't be included with PHPUnit. Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心作怪 2024-10-02 09:48:13

您应该阅读 PHPUnit 命令行测试运行程序的文档。您也可以从命令行运行“phpunit --help”。我相信你会发现你需要运行类似的东西

phpunit path/to/filename.php

You should read the docs for PHPUnit for the command line test runner. You can also just run 'phpunit --help' from the command line. I believe you'll find that you need to instead run something like

phpunit path/to/filename.php
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文