The Phpunit_selenium package is already included in the PHPUnit PHAR package
PHPUnit Official website: Https://phpunit.de/,:https://phar.phpunit.de/phpunit.phar
Install under Windows
Overall, installing PHAR under Windows and manually installing Composer under Windows is the same process:
Create a directory for the PHP binary executable file, for example C:\bin
Will C:\bin attached to the PATH environment variable (related help)
Download Https://phar.phpunit.de/phpunit.phar and save the file to C:\bin\phpunit.phar
Open the command line (for example, press Windows+r?). Input cmd? ENTER)
Set up Outsourcing batch processing script (finally get C:\bin\phpunit.cmd):
C:\users\username> CD C:\bin
c:\bin> echo @php "%~dp0phpunit.phar"%* > Phpunit.cmd
C:\bin> exit
Open a new command-line window to confirm that PHPUnit can be executed under any path:
C:\users\username> PHPUnit--version
PHPUnit x.y.z by Sebastian Bergmann and contributors.
(Note: If the execution fails, add the C:\bin path to the system environment variable path, e.g.)
The above installation method from PHPUnit official website, other platform installation methods please refer to the Official document Https://phpunit.de/manual/current/zh_cn/installation.html
Selenium Server is a test tool that allows you to write automated user interface tests for Web applications developed in any programming language on any HTTP Web site using any major browser.
Download the jar package for Selenium Server.
Then copy the Selenium-server-standalone-2.45.0.jar (note the version suffix) to the appropriate location, such as C:\bin
Run c:\bin> Java-jar Java-jar Selenium-server-standalone-2.45.0.jar to start the server side of the selenium server.
You can use the client/server-side protocol of Selenium server to send commands to it.
Phpunit_extensions_selenium2testcase test Cases can use the Webdriver API (partially implemented), before development, please download the corresponding browser Webdriver components, and put in C:\bin
Https://sites.google.com/a/chromium.org/chromedriver/downloads Chrome Browser
Https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver IE Browser
OSC login and Post test cases
<?phpclass OscTest extends PHPUnit_Extensions_Selenium2TestCase{ private $username; private $PSW; protected Function setup () { $this username = ' xxxxx '; // osc account $this->PSW = ' xxxxx '; // osc password // set test browser // $this->setdesiredcapabilities (Array ( // "Firefox_binary" => "D:\\program files\\mozilla firefox\\firefox.exe " // ); // $this->setbrowser (' Firefox '); $this->setdesiredcapabilities (Array ( "Webdriver.chrome.driver" => "C:\\bin\\chromedriver.exe" ); $this->setbrowser (' Chrome '); // $this->setseleniumserverrequeststimeout (180000) //ie run slower and need to set the time // $this->setdesiredcapabilities (Array ( // "Webdriver.ie.driver" => "C:\\bin\\iedriverserver.exe" // )); // $this Setbrowser (' IE '); // default page $this->setbrowserurl ('Https://www.oschina.net/home/login '); } public function testlogin () { // Setup Test page $this->url (' Https://www.oschina.net/home/login '); // input OSC account $this Byid (' F_email ')->value ($this->username); // Enter the OSC password $this->byid (' f_pwd ')->value ($this->psw); // $screenshot = $this->currentscreenshot (); file_put_contents ("F:\\screenshot1.png", $screenshot); // Login Submission $ This->byid (' Form_user ')->submit (); $screenshot = $this->currentscreenshot (); file_put_contents ("F:\\ Screenshot2.png ", $screenshot); // judgment $this->assertnotempty ($ This->title ()); // Click Post Blog $a 1 = $this->byclassname (' A1 ' ); $this->assertnotempty ($a 1); $a 1->click (); $this->waituntil (function ($testCase) { $url = $testCase->url (); if (Strpos ($url, ' New-blog ') !== false) { return TRUE; } }, 10000 ); // Set Blog title $this->byname (' title ')->value (' Phpunit-selenium automated test '); // Settings blog Body $script = "var ueditor = ue.geteditor (' wmd-input '); Ueditor.setcontent (' Phpunit-selenium Automated test Http://my.osChina.net/penngo ');return true; "; $result = $this->execute (Array ( ' script ' => $script, ' args ' => array () ); // Settings Blog category $this->select ($this->byid (' Blogcatalogselect ') ->selectoptionbylabel ("Software Engineering"); $screenshot = $this->currentscreenshot (); file_put_contents ("F:\\screenshot4.png", $screenshot); // blog $this->byid (' SAVE-BT ')-≫click (); $screenshot = $this->currentscreenshot (); file_put_contents ("F:\\screenshot5.png", $screenshot); // $this->assertnotequals ($new _blog, $this URL ()); }}?>
Run
In the Running
Screenshot1.png
Screenshot2.png
Screenshot4.png
Screenshot5.png
For the convenience of study, we provide accessories: Php_selenium.rar (including Phpunit.phar,selenium-server-standalone-2.45.0.jar,chromedriver, Iedriverserver)
Finally add: If someone uses some method to advertise the OSC, please @ sweet potato self-solve.
Phpunit-selenium Automated Testing Open source China account login and Post