How to make a automated testing for web applications

    As a developer of web application(assume PHP developer),sometimes we have to have a test to the logics code we have done ..In general,someone think of the first way is using PHPUnit.yes here is the purpose i write this article here.so ,how could use PHPUnit to have a test ??? here is some reference below:

Some utilities: 

    1. Selenium Server (Click here)

    2. WebDriver (Click here),it is used for driving the chrome browser by start a process.

    3. PHPUnit (Click here)

    4. The extension of PHPUnit Selenium..(for my instance,i use composer to install it ...."require-dev":{"phpunit/phpunit-selenium": ">=1.2"})

    5. Show Time (something amazing.)

Procedure:

    1. Start Selenium Server by executing command : java -Dwebdriver.chrome.driver=./chromedriver -jar selenium-server-standalone-xxx.jar (if an error occur,,maybe the version of java is to low in your local environment ,you need to install the lasted version)

    2. after finishing  above operations we can write some test cases.

    3, here is a simple sample 

<?php
namespace Home\Controller;

class WebTest extends \PHPUnit_Extensions_Selenium2TestCase
{
    protected function setUp()
    {
        $this->setBrowser('*chrome');
        $this->setBrowserUrl('http://base.domain.com');
    }

    public function testBanUser()
    {
        $this->url('/Auth/login.html');
        $username = $this->byName('username');
        $password = $this->byName('password');
        $btn = $this->byClassName('btn');
        
        $username->value('username');
        $password->value('password');
        $btn->click();
        
        $this->url('/home/user/listusers');
        
        $this->url('/home/user/info/id/1171708');
        
        $banClickId = $this->byId('user-info-status-ban');
        
        $banClickId->click();
        
        // wait for ajax finished
        sleep(5);
        
        $this->refresh();
        
        $banClickIdAgain = $this->byId('user-info-status-ban');
        
        $this->assertTrue('Banned' == $banClickIdAgain->text());
    }
    
    public function testFake()
    {
        $this->assertTrue(1 == 1);
    }
}
?>

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值