-
Notifications
You must be signed in to change notification settings - Fork 57
/
SampleTest.php
76 lines (64 loc) · 2.4 KB
/
SampleTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
require_once 'WebDriver.php';
require_once 'WebDriver/Driver.php';
require_once 'WebDriver/MockDriver.php';
require_once 'WebDriver/WebElement.php';
require_once 'WebDriver/MockElement.php';
require_once 'WebDriver/FirefoxProfile.php';
require_once 'WebDriver/NoSuchElementException.php';
require_once 'WebDriver/StaleElementReferenceException.php';
require_once 'WebDriver/ElementNotVisibleException.php';
class SampleTest extends PHPUnit_Framework_TestCase {
protected $driver;
public function setUp() {
// If you want to set preferences in your Firefox profile
$fp = new WebDriver_FirefoxProfile();
$fp->set_preference("capability.policy.default.HTMLDocument.compatMode", "allAccess");
// Choose one of the following
// For tests running at Sauce Labs
// $this->driver = WebDriver_Driver::InitAtSauce(
// "my-sauce-username",
// "my-sauce-api-key",
// "WINDOWS",
// "firefox",
// "10",
// array(
// 'firefox_profile' => $fp->get_profile()
// ));
// $sauce_job_name = get_class($this);
// $this->driver->set_sauce_context("name", $sauce_job_name);
// For a mock driver (for debugging)
// $this->driver = new WebDriver_MockDriver();
// define('kFestDebug', true);
// For a local driver
$this->driver = WebDriver_Driver::InitAtLocal("4444", "firefox");
}
// Forward calls to main driver
public function __call($name, $arguments) {
if (method_exists($this->driver, $name)) {
return call_user_func_array(array($this->driver, $name), $arguments);
} else {
throw new Exception("Tried to call nonexistent method $name with arguments:\n" . print_r($arguments, true));
}
}
public function test() {
$this->set_implicit_wait(5000);
$this->load("http://seleniumhq.org/");
$this->assert_title("Selenium - Web Browser Automation");
$this->get_element("css=h2")->assert_text("What is Selenium?");
$this->get_element("id=q")->send_keys("webdriver");
$this->get_element("id=submit")->click();
$first_result = $this->get_element("css=a.gs-title")->get_text();
}
public function tearDown() {
if ($this->driver) {
if ($this->hasFailed()) {
$this->driver->set_sauce_context("passed", false);
} else {
$this->driver->set_sauce_context("passed", true);
}
$this->driver->quit();
}
parent::tearDown();
}
}