-
Notifications
You must be signed in to change notification settings - Fork 379
/
testBuilder.class.php
179 lines (158 loc) · 5.7 KB
/
testBuilder.class.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<?php
/*
* This class help building a selenium HTML test file for PPA.
**/
class TestBuilder {
private $code;
/**
* Constructor
* @param $serverDesc The server['desc'] conf param to which we are writing this test file for.
* @param $title The title of the HTML test page
* @param $desc The top description on the HTML test page
*/
public function __construct($serverDesc, $title, $desc) {
$this->title = $title;
$this->servDesc = $serverDesc;
/*$this->fd = fopen($this->file, 'w');
fprintf($this->fd, '%s', "<html>\n<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">
<title>$title</title>
</head>
<body>
<table cellpadding=\"1\" cellspacing=\"1\" border=\"1\">
<thead>
<tr><td rowspan=\"1\" colspan=\"3\">$desc</td></tr>
</thead><tbody>"
);*/
$this->code = "<html>\n<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">
<title>$title</title>
</head>
<body>
<table cellpadding=\"1\" cellspacing=\"1\" border=\"1\">
<thead>
<tr><td rowspan=\"1\" colspan=\"3\">$desc</td></tr>
</thead><tbody>";
}
/**
* Write the test file, close it,
* append the test file to the TestSuite.html file and destroy itself
* @param $testfile The path to the test file to create
* @param $testsuite_file The path to the TestSuite.html file
*/
public function writeTests($testfile, $testsuite_file) {
file_put_contents($testfile, $this->code);
$str = "<tr>\n<td><a href=\"{$this->servDesc}/".
basename($testfile) ."\">[{$this->servDesc}] {$this->title}</a></td>\n</tr>\n";
file_put_contents($testsuite_file, $str, FILE_APPEND);
}
/**
* Add a selenium test to the file
* @param $action the selenium action (first column)
* @param $selector the selector to select the object to work on (second column)
* @param $value (optional) the expected (or not) value (third column)
*/
public function test($action, $selector, $value='') {
$this->code .= "<tr>\n<td>$action</td>\n<td>$selector</td>\n<td>$value</td>\n</tr>\n";
}
public function addComment($c) {
$this->code .= "<tr>\n<th colspan=\"3\">{$c}</th>\n</tr>\n";
}
/**
* Add steps to login on PPA using the given credentials
* @param $u The username to use
* @param $p The password to use
*/
public function login($u, $p) {
global $webUrl, $data;
$this->addComment("Login as {$u}");
$this->test('open', "{$webUrl}/intro.php");
$this->select('language', 'English');
$this->test('open', "{$webUrl}/login.php?server={$data->conn->host}&subject=server");
$this->test('type', "//input[@name='loginUsername']", $u);
$this->test('type', "//input[@id='loginPassword']", $p);
$this->test('clickAndWait', 'loginSubmit');
$this->test('assertText', "//div[@class='topbar']/descendant::span[@class='username']", $u);
}
/**
* Add steps to logout from the server
*/
public function logout() {
global $lang;
$this->addComment("Logout");
$this->test('clickAndWait', "//div[@class='trail']/descendant::tr/td[1]/a/span[@class='label' and text()='phpPgAdmin']");
$this->test('clickAndWait', "link={$lang['strservers']}");
$this->test('clickAndWait', "//tr/td/a[text()='{$this->servDesc}']/../../td/a[text()='{$lang['strlogout']}']");
$this->test('assertText', "//p[@class='message']",
sprintf($lang['strlogoutmsg'], $this->servDesc)
);
}
/**
* Add a selenium type test to the file
* @param $selector the selector to select the object to work on (second column)
* @param $value (optional) the expected (or not) value (third column)
*/
public function type($selector, $value) {
$this->test('type', $selector, $value);
}
/**
* Add a selenium select test to the file
* @param $selector the selector to select the object to work on (second column)
* @param $value (optional) the expected (or not) value (third column)
*/
public function select($selector, $value) {
$this->test('select', $selector, $value);
}
/**
* Add a selenium addSelection test to the file
* @param $selector the selector to select the object to work on (second column)
* @param $value (optional) the expected (or not) value (third column)
*/
public function addSelection($selector, $value) {
$this->test('addSelection', $selector, $value);
}
/**
* Add a selenium click test to the file
* @param $selector the selector to select the object to work on (second column)
*/
public function click($selector) {
$this->test('click', $selector);
}
/**
* Add a selenium check test to the file
* @param $selector the selector to select the object to work on (second column)
*/
public function check($selector) {
$this->test('check', $selector);
}
/**
* Add a selenium uncheck test to the file
* @param $selector the selector to select the object to work on (second column)
*/
public function uncheck($selector) {
$this->test('uncheck', $selector);
}
/**
* Add a selenium clickAndWait est to the file
* @param $selector the selector to select the object to work on (second column)
*/
public function clickAndWait($selector) {
$this->test('clickAndWait', $selector);
}
/**
* Add a selenium assertText test to the file
* @param $selector the selector to select the object to work on (second column)
* @param $value (optional) the expected (or not) value (third column)
*/
public function assertText($selector, $value) {
$this->test('assertText', $selector, $value);
}
/**
* Add a selenium assertErrorOnNext test to the file
* @param $msg the selenium error message expected
*/
public function assertErrorOnNext($msg) {
$this->test('assertErrorOnNext', $msg);
}
}
?>