Php web测试工具simpletest使用

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/moeryang/article/details/56832170

1、simpletest 是一个php框架主要用来测试 WEB UI(也有单元测试功能)

2、下载地址
https://nchc.dl.sourceforge.net/project/simpletest/simpletest/simpletest_1.1/simpletest_1.1.0.tar.gz

3、简单使用方式

//包含文件
require_once('simpletest/unit_tester.php');
require_once('simpletest/web_tester.php');
require_once('simpletest/reporter.php');
//创建一个测试类
class TestOfSite extends WebTestCase
{
    function TestOfSite(){
        //$this->WebTestCase("This is test");
    }
    //测试方法
    function testSite()
    {
        //1、登录,提交表单
        $this->get('http://localhost/index.php/wxuser/login');
        $this->setField("nickname","侵晨");
        $this- 
        $this->setField("action","1");
        $this->setField("headerpic","1.jpg");
        $this->clickSubmitById("btnLogin");

        //2、获取首页信息
       // $this->restart();
        //$this->get('http://localhost/index.php/m/user/index');
        //$this->assertText('热销产品'); 

        //$this->clickLink()

        //3、修改资料表单
       $this->post('http://localhost/index.php/m/user/editInfo',array(
            "name"=>"杨默新",
            "email"=>"[email protected]",
            "mobile"=>"1370000",
            "sex"=>"男",
            "action"=>"1",

            ));
        $this->assertText("成功"); 
    }

}


header("Content-type: text/html; charset=utf-8");
$test = new TestOfSite();
$test->run(new HtmlReporter("utf-8"));//设置测试结果页面编码,不然显示乱码

缺点:
1、没办法完全模拟浏览器
2、有些HTML标签的值没法设置,只能设置form表单的值(还是没找到?)
3、没有自动录制测试步骤功能,做一个页面表单测试太繁琐了(之前vs 测试工具有)

猜你喜欢

转载自blog.csdn.net/moeryang/article/details/56832170
今日推荐