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 

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);
    }
}
?>

你可能感兴趣的:(php)