Selenium PHPUnit在ubuntu命令行上传递变量

时间:2011-11-04 12:13:40

标签: selenium command-line phpunit

我正在尝试使用命令行将变量传递给Selenium PHPUnit脚本。 查看PHPUnit帮助文档:

我们可以使用XML或PHP配置文件提供变量,但理想情况下我想在不使用外部文件的情况下传递变量。 我之所以这样做是因为我希望能够修改Timeout值而无需修改我的自定义config.php文件。

phpunit --help
PHPUnit 3.6.0 by Sebastian Bergmann.

Usage: phpunit [switches] UnitTest [UnitTest.php]
       phpunit [switches] <directory>

  --log-junit <file>        Log test execution in JUnit XML format to file.
  --log-tap <file>          Log test execution in TAP format to file.
  --log-json <file>         Log test execution in JSON format.

  --coverage-html <dir>     Generate code coverage report in HTML format.
  --coverage-clover <file>  Write code coverage data in Clover XML format.
  --coverage-php <file>     Serialize PHP_CodeCoverage object to file.
  --coverage-text <file>    Generate code coverage report in text format.

  --testdox-html <file>     Write agile documentation in HTML format to file.
  --testdox-text <file>     Write agile documentation in Text format to file.

  --filter <pattern>        Filter which tests to run.
  --group ...               Only runs tests from the specified group(s).
  --exclude-group ...       Exclude tests from the specified group(s).
  --list-groups             List available test groups.

  --loader <loader>         TestSuiteLoader implementation to use.
  --printer <printer>       TestSuiteListener implementation to use.
  --repeat <times>          Runs the test(s) repeatedly.

  --tap                     Report test execution progress in TAP format.
  --testdox                 Report test execution progress in TestDox format.

  --colors                  Use colors in output.
  --stderr                  Write to STDERR instead of STDOUT.
  --stop-on-error           Stop execution upon first error.
  --stop-on-failure         Stop execution upon first error or failure.
  --stop-on-skipped         Stop execution upon first skipped test.
  --stop-on-incomplete      Stop execution upon first incomplete test.
  --strict                  Run tests in strict mode.
  -v|--verbose              Output more verbose information.

  --skeleton-class          Generate Unit class for UnitTest in UnitTest.php.
  --skeleton-test           Generate UnitTest class for Unit in Unit.php.

  --process-isolation       Run each test in a separate PHP process.
  --no-globals-backup       Do not backup and restore $GLOBALS for each test.
  --static-backup           Backup and restore static attributes for each test.
  --syntax-check            Try to check source files for syntax errors.

  --bootstrap <file>        A "bootstrap" PHP file that is run before the tests.
  -c|--configuration <file> Read configuration from XML file.
  --no-configuration        Ignore default configuration file (phpunit.xml).
  --include-path <path(s)>  Prepend PHP's include_path with given path(s).
  -d key[=value]            Sets a php.ini value.

  -h|--help                 Prints this usage information.
  --version                 Prints the version and exits.

  --debug                   Output debugging information.

1 个答案:

答案 0 :(得分:2)

使用-d设置PHP的一个配置值,并使用bootstrap.php文件中的ini_get()进行读取。使用define()将其传递给您的测试。这是一个确定的黑客,但它适用于您的超时情况。

作为测试,我使用max_execution_time作为转移点。如果您使用相同的东西,那么您将要重置它,以便PHPUnit如果花费太长时间就不会被杀死。 ;)

// bootstrap.php

$timeout = ini_get('max_execution_time');
set_time_limit(0); // run forever

使用-d传递所需的超时时间。

phpunit -d max_execution_time=5000

更新:我首先尝试使用一个简化的设置my_test_timeout,但价值并没有通过。 PHP或PHPUnit必须阻止不在INI文件中的值,或者PHP根本不支持。鉴于INI文件可以具有特定于PHP无法提前知道的模块的值,我想知道您是否可以将自定义设置添加到php.ini以使其工作。值得一试,以避免破坏其他有用的设置。另外,它可能允许您使用字符串和其他类型。