Created
December 13, 2012 18:46
-
-
Save jtarleton/4278629 to your computer and use it in GitHub Desktop.
Functional Web Tests using Selenium Framework / PHPUnit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Selenium Testing Requirements: | |
- phpunit 3.7+ | |
- Selenium test case extension to PHPUnit installed with pear: | |
~ pear install phpunit/Selenium_Test_Case | |
- Selenium server running on localhost:4444: | |
java -jar "selenium-server-standalone-2.25.0(1).jar" -v -debug | |
Usage: | |
- C:\Users\you\Desktop\Selenium_Tests>phpunit --log-junit output.xml -v FooWebTest.php | |
*/ | |
ini_set('memory_limit', '2G'); | |
require_once 'C:\Program Files\PHP\v5.3\ext\pear\PHPUnit\Extensions\SeleniumTestCase.php'; | |
class GenericWebTest extends PHPUnit_Extensions_SeleniumTestCase | |
{ | |
/** | |
* Set up | |
*/ | |
protected function setUp() | |
{ | |
$this->setBrowser("*firefoxchrome"); | |
$this->setBrowserUrl("http://www.domain.com/"); | |
$this->setSleep(2); | |
} | |
/* | |
* testGenericPage | |
*/ | |
public function testGenericPage() | |
{ | |
$this->doLogin($this->testUserName, $this->testUserPass); | |
$this->open("/page"); | |
$this->click("link=ClickMe"); | |
$this->waitForPageToLoad("10000"); | |
$this->open("/foo"); | |
$this->doLogout(); | |
} | |
/** | |
* login | |
*/ | |
private function doLogin($u, $p) | |
{ | |
$this->open("/login/"); | |
$this->type("name", $u); | |
$this->type("pass", $p); | |
$this->click("foo"); | |
$this->waitForPageToLoad("30000"); | |
$this->assertTextNotPresent('Invalid'); | |
$this->assertTrue( $this->isTextPresent("Foo") || $this->isTextPresent("Bar") ); | |
} | |
/** | |
* Logout | |
*/ | |
private function doLogout() | |
{ | |
$this->open("/logout"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment