以编程方式(“在PHP内")运行PHPUnit Selenium测试用例 [英] Run a PHPUnit Selenium test case programatically ("within PHP")

查看:72
本文介绍了以编程方式(“在PHP内")运行PHPUnit Selenium测试用例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在"PHP内"运行测试,而不是使用"phpunit"命令?示例:

How can I run a test "within PHP" instead of using the 'phpunit' command? Example:

<?php
require_once 'PHPUnit/Extensions/SeleniumTestCase.php';
class MySeleniumTest extends PHPUnit_Extensions_SeleniumTestCase {

    protected function setUp() {
        $this->setBrowser("*firefox");
        $this->setBrowserUrl("http://example.com/");
    }

    public function testMyTestCase() {
        $this->open("/");
        $this->click("//a[@href='/contact/']");
    }

}

$test = new MySeleniumTest();
//I want to run the test and get information about the results so I can store them in the database, send an email etc.
?>

还是我必须将测试写入文件,通过system()/exec()调用phpunit并解析输出? :(

Or do I have to write the test to a file, invoke phpunit via system()/exec() and parse the output? :(

推荐答案

只需使用然后,您需要像 SeleniumTestCase那样进行设置:

$driver = new PHPUnit_Extensions_SeleniumTestCase_Driver;
$driver->setName($browser['name']);
$driver->setBrowser($browser['browser']);
$driver->setHost($browser['host']);
$driver->setPort($browser['port']);
$driver->setTimeout($browser['timeout']);
$driver->setHttpTimeout($browser['httpTimeout']);

然后:

$driver->open('/');
$driver->click("//a[@href='/contact/']");

这篇关于以编程方式(“在PHP内")运行PHPUnit Selenium测试用例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆