-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.php
66 lines (53 loc) · 2.38 KB
/
test.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
<?php
// php composer.phar require facebook/webdriver
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Facebook\WebDriver\WebDriverBy;
use Facebook\WebDriver\WebDriverExpectedConditions;
use PHPUnit\Framework\TestCase;
// composer global require phpunit/phpunit
class ToDoTest extends TestCase {
protected $driver;
public function setUp()
{
$capabilities = array(
"platform" => "LINUX",
"browserName" => "chrome",
"version" => "64.0.3282.140"
);
$host = "http://localhost:4444/wd/hub";
$this->driver = RemoteWebDriver::create($host, $capabilities);
}
public function testToDos()
{
try {
print "\nNavigating to URL\n";
$this->driver->get("http://crossbrowsertesting.github.io/todo-app.html");
sleep(3);
$this->driver->takeScreenshot('screenshot_' . time() . '.png');
print "Clicking Checkbox\n";
$this->driver->findElement(WebDriverBy::name("todo-4"))->click();
print "Clicking Checkbox\n";
$this->driver->findElement(WebDriverBy::name("todo-5"))->click();
$elems = $this->driver->findElements(WebDriverBy::className("done-true"));
$this->assertEquals(2, count($elems));
print "Entering Text\n";
$this->driver->findElement(WebDriverBy::id("todotext"))->sendKeys("Run your first Selenium test");
print "Adding todo to the list\n";
$this->driver->findElement(WebDriverBy::id("addbutton"))->click();
$spanText = $this->driver->findElement(WebDriverBy::xpath("/html/body/div/div/div/ul/li[6]/span"))->getText();
$this->assertEquals("Run your first Selenium test", $spanText);
print "Archiving old todos\n";
$this->driver->findElement(WebDriverBy::linkText("archive"))->click();
$elems = $this->driver->findElements(WebDriverBy::className("done-false"));
$this->assertEquals(4, count($elems));
// if we've made it this far, assertions have passed and we'll set the score to pass.
} catch (Exception $ex) {
// if we caught an exception along the way, an assertion failed and we'll set the score to fail.
print "Caught Exception: " . $ex->getMessage();
}
}
public function tearDown()
{
$this->driver->quit();
}
}