forked from octobercms/october
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUiTestCase.php
91 lines (73 loc) · 2.5 KB
/
UiTestCase.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
class UiTestCase extends PHPUnit_Extensions_SeleniumTestCase
{
protected function setUp()
{
/*
* Look for selenium configuration
*/
if (file_exists($seleniumEnv = __DIR__.'/../selenium.php'))
require_once $seleniumEnv;
/*
* Configure selenium
*/
if (!defined('TEST_SELENIUM_URL'))
return $this->markTestSkipped('Selenium skipped');
if (defined('TEST_SELENIUM_HOST')) $this->setHost(TEST_SELENIUM_HOST);
if (defined('TEST_SELENIUM_PORT')) $this->setPort(TEST_SELENIUM_PORT);
if (defined('TEST_SELENIUM_BROWSER')) $this->setBrowser(TEST_SELENIUM_BROWSER);
$this->setBrowserUrl(TEST_SELENIUM_URL);
}
//
// OctoberCMS Helpers
//
protected function signInToBackend()
{
$this->open('backend');
$this->type("name=login", TEST_SELENIUM_USER);
$this->type("name=password", TEST_SELENIUM_PASS);
$this->click("//button[@type='submit']");
$this->waitForPageToLoad("30000");
}
/**
* Similar to the native getConfirmation() function
*/
protected function getSweetConfirmation($expectedText = null, $clickOk = true)
{
$this->waitForElementPresent("xpath=(//div[@class='sweet-alert showSweetAlert visible'])[1]");
if ($expectedText) {
$this->verifyText("//div[@class='sweet-alert showSweetAlert visible']//h4", $expectedText);
}
$this->verifyText("//div[@class='sweet-alert showSweetAlert visible']//button[@class='confirm btn btn-primary']", "OK");
if ($clickOk) {
$this->click("xpath=(//div[@class='sweet-alert showSweetAlert visible']//button[@class='confirm btn btn-primary'])[1]");
}
}
//
// Selenium helpers
//
protected function waitForElementPresent($target, $timeout = 60)
{
for ($second = 0; ; $second++) {
if ($second >= $timeout)
$this->fail('timeout');
try {
if ($this->isElementPresent($target)) break;
}
catch (Exception $e) {}
sleep(1);
}
}
protected function waitForElementNotPresent($target, $timeout = 60)
{
for ($second = 0; ; $second++) {
if ($second >= $timeout)
$this->fail('timeout');
try {
if (!$this->isElementPresent($target)) break;
}
catch (Exception $e) {}
sleep(1);
}
}
}