forked from ezsystems/PlatformUIBundle
/
CommonActions.php
420 lines (382 loc) · 13.2 KB
/
CommonActions.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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
<?php
/**
* File containing the Common Functions for context class PlatformUI.
*
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
* @version //autogentag//
*/
namespace EzSystems\PlatformUIBundle\Features\Context\SubContext;
use EzSystems\BehatBundle\Helper\EzAssertion;
trait CommonActions
{
/**
* @Given I clicked on/at (the) :link link
* @When I click on/at (the) :link link
*
* Click a link with text ':link'
*/
public function iClickAtLink($link)
{
$this->clickElementByText($link, 'a');
}
/**
* @Given I clicked on/at (the) :button button
* @When I click on/at (the) :button button
*
* Clicks the button identified by ':button'
*/
public function iClickAtButton($button)
{
$this->clickElementByText($button, 'button');
}
/**
* @When I fill in :field with :value
* @When I set :field as empty
*
* Spin function make it possible to retry in case of failure
*/
public function fillFieldWithValue($field, $value = '')
{
$fieldNode = $this->spin(
function () use ($field) {
$fieldNode = $this->getSession()->getPage()->findField($field);
if ($fieldNode == null) {
throw new \Exception('Field not found');
}
return $fieldNode;
}
);
$this->spin(
function () use ($fieldNode, $field, $value) {
// make sure any autofocus elements don't mis-behave when setting value
$fieldNode->blur();
usleep(10 * 1000);
$fieldNode->focus();
usleep(10 * 1000);
// setting value on pre-filled inputs can cause issues, clearing before
$fieldNode->setValue('');
$fieldNode->setValue($value);
// verication that the field was really filled in correctly
$this->sleep();
$check = $this->getSession()->getPage()->findField($field)->getValue();
if ($check != $value) {
throw new \Exception('Failed to set the field value: ' . $check);
}
return true;
}
);
}
/**
* @Then I (should) see :title title/topic
*/
public function iSeeTitle($title)
{
$page = $this->getSession()->getPage();
$this->spin(
function () use ($title, $page) {
$titleElements = $page->findAll('css', 'h1, h2, h3');
foreach ($titleElements as $titleElement) {
$elementText = $titleElement->getText();
if ($elementText == $title) {
return $titleElement;
}
}
throw new \Exception("Title '$title' not found");
}
);
}
/**
* @Then I should see a :label input field
*/
public function seeInputField($label)
{
$field = $this->getSession()->getPage()->findField($label);
if (!$field) {
throw new \Exception("Field '$label' not found");
}
}
/**
* @Given I checked :label checkbox
* @When I check :label checkbox
*
* Toggles the value for the checkbox with name ':label'
*/
public function checkOption($option)
{
$fieldElements = $this->getXpath()->findFields($option);
EzAssertion::assertElementFound($option, $fieldElements, null, 'checkbox');
// this is needed for the cases where are checkboxes and radio's
// side by side, for main option the radio and the extra being the
// checkboxes values
if (strtolower($fieldElements[0]->getAttribute('type')) !== 'checkbox') {
$value = $fieldElements[0]->getAttribute('value');
$fieldElements = $this->getXpath()->findXpath("//input[@type='checkbox' and @value='$value']");
EzAssertion::assertElementFound($value, $fieldElements, null, 'checkbox');
}
$fieldElements[0]->check();
}
/**
* @Given I click (on) the logo
* Clicks on the PlatformUI logo
*/
public function clickLogo()
{
$page = $this->getSession()->getPage();
$selector = '.ez-logo a';
$page->find('css', $selector)->click();
}
/**
* @Given I click (on) the tab :tab
* Clicks on a PlatformUI tab
*
* @param string $tab Text of the element to click
*/
public function clickTab($tab)
{
$this->clickElementByText($tab, '.ez-tabs-label a[href]');
}
/**
* @Given I click (on) the navigation zone :zone
* Click on a PlatformUI menu zone
*
* @param string $zone Text of the element to click
*/
public function clickNavigationZone($zone)
{
$this->clickElementByText($zone, '.ez-zone-name');
$this->waitWhileLoading();
// Clicking navigation zone triggers load of first item,
// we must wait before interacting with the page (see EZP-25128)
// this method sleeps for a default amount (see EzSystems\PlatformUIBundle\Features\Context\PlaformUI)
$this->sleep();
}
/**
* @Given I click on the :button button number :index
* Click on a PlatformUI button
*
* @param string $button Text of the element to click
* @param string $index WHAT IS THIS?!
*/
public function clickButtonWithIndex($button, $index)
{
$this->clickElementByText($button, 'button', $index);
}
/**
* @Given I click (on) the navigation item :item
* Click on a PlatformUI sub-menu option
*
* @param string $item Text of the element to click
*/
public function clickNavigationItem($item)
{
$this->clickElementByText($item, '.ez-navigation-item');
$this->waitWhileLoading();
}
/**
* @Given I click (on) the discovery bar button :button
* Click on a PlatformUI discovery bar
*
* @param string $button Text of the element to click
*/
public function clickDiscoveryBar($button)
{
$this->clickElementByText($button, '.ez-view-discoverybarview .ez-action', '.action-label');
$this->waitWhileLoading();
}
/**
* @Given I click (on) the action bar button :button
* Click on a PlatformUI action bar
*
* @param string $button Text of the element to click
*/
public function clickActionBar($button)
{
$this->clickElementByText($button, '.ez-actionbar-container .ez-action', '.action-label');
$this->waitWhileLoading();
}
/**
* @Given I click (on) the edit action bar button :button
* Click on a PlatformUI edit action bar
*
* @param string $button Text of the element to click
*/
public function clickEditActionBar($button)
{
$this->clickElementByText($button, '.ez-editactionbar-container .ez-action', '.action-label');
$this->waitWhileLoading();
}
/**
* @Then :path content item does not exists
* @Then :path content item doesn't exists
* @Then the content item :path was removed
* @Then the content item :path was sent to trash
* Explores the finder of the UDW, verify the desired element doesn't exist and close the UDW.
*
* @param string $path The content browse path such as 'Content1/Content2/ContentIWantToClick'
*/
public function thereIsNoContent($path)
{
$this->clickNavigationItem('Content structure');
$this->dontSeeBrowsePath($path);
$this->cancelSelection();
}
/**
* @Then :path content item exists
* @Then the content item :path was not removed
* @Then the content item :path was not sent to trash
* @Then the content item was moved to :path
* @Then the content item was copied to :path
* Explores the finder of the UDW, find the desired element and close the UDW.
*
* @param string $path The content browse path such as 'Content1/Content2/ContentIWantToClick'
*/
public function thereIsAContent($path)
{
$this->clickNavigationItem('Content structure');
$this->clickOnBrowsePath($path);
$this->confirmSelection();
}
/**
* @Given I click (on) the content type :contentType
* Click on a PlatformUI side menu content type
*
* @param string $contentType Text of the element to click
*/
public function clickContentType($contentType)
{
$this->clickElementByText($contentType, '.ez-contenttypeselector-types .ez-selection-filter-item ');
$this->waitWhileLoading();
}
/**
* @Given I create a content of content type :type with:
*/
public function iCreateContentType($type, TableNode $fields)
{
$this->clickNavigationZone('Platform');
$this->iClickAtLink('Content structure');
$this->clickActionBar('Create a content');
$this->clickContentType($type);
foreach ($fields as $fieldArray) {
$keys = array_keys($fieldArray);
for ($i = 0; $i < count($keys); ++$i) {
$this->fillFieldWithValue($keys[$i], $fieldArray[$keys[$i]]);
}
}
}
/**
* @When I select the :path folder in the Universal Discovery Widget
*/
public function selectFromUniversalDiscovery($path)
{
// wait while UDW is hidden...
$this->waitWhileLoading('.is-universaldiscovery-hidden');
$node = $this->findWithWait('.ez-view-universaldiscoveryview');
$node = $this->findWithWait('.ez-view-universaldiscoveryfinderview .ez-ud-finder-explorerlevel', $node);
$this->openFinderExplorerPath($path, $node);
}
/**
* @Given I am on :name full view
*/
public function onFullView($name)
{
$path = $this->getBasicContentManager()->getContentPath($name);
$this->goToContentWithPath($path);
}
/**
* Opens a content in PlatformUi.
*/
public function goToContentWithPath($path)
{
$this->clickNavigationZone('Content');
$this->clickNavigationItem('Content structure');
$this->clickOnBrowsePath($path);
$this->confirmSelection();
}
/**
* @Then I am on the :name location view
*/
public function onLocationView($name)
{
// little info about content in platformUI,
// for now only verifies if the title matches
$this->waitWhileLoading();
$this->iSeeTitle($name);
}
/**
* @Then I see Content :contentName of type :contentType
*/
public function contentExists($contentName, $contentType)
{
$contentId = $this->getLocationId();
$content = $this->getContentManager()->loadContentWithLocationId($contentId);
$contentInfo = $content->contentInfo;
$contentTypeName = $this->getContentManager()->getContentType($content);
Assertion::assertEquals($contentName, $contentInfo->name, 'Content has wrong name');
Assertion::assertEquals($contentType, $contentTypeName, 'Content has wrong type');
}
/**
* @Then I am notified that :message
*/
public function iSeeNotification($message)
{
$this->sleep();
$result = $this->getElementByText($message, '.ez-notification-text');
if (!$result) {
throw new \Exception("The notification with message '$message' was not shown");
}
}
/**
* @Then I am not notified that :message
*/
public function iDoNotSeeNotification($message)
{
try {
$this->iSeeNotification($message);
} catch (\Exception $e) {
return;
}
throw new \Exception("Unexpected notification shown with message '$message'");
}
/**
* @Then I should see elements with the following names:
*/
public function iSeeElements(TableNode $elements)
{
foreach ($elements as $element) {
$found = false;
$name = array_values($element)[0];
$found = $this->getElementByText($name, '.ez-selection-filter-item');
Assertion::assertNotNull($found, "Element: $name not found");
}
}
/**
* @Then I should see (an) element :element with (an) file :file
*/
public function iSeeElementFile($element, $file)
{
$url = $this->getFileUrl($element, '.ez-fieldview-label');
$fileContentActual = file_get_contents($url);
$file = rtrim(
realpath($this->getMinkParameter('files_path')),
DIRECTORY_SEPARATOR
) . DIRECTORY_SEPARATOR . $file;
$fileContentExpected = file_get_contents($file);
Assertion::assertEquals($fileContentActual, $fileContentExpected);
}
/**
* @Then /^I should be on the dashboard$/
*/
public function iShouldBeOnTheDashboard()
{
$this->waitWhileLoading();
$this->findWithWait('.ez-dashboard-content');
}
/**
* @Given /^I am redirected to a location view$/
*/
public function iHaveBeenRedirectedToALocationView()
{
$this->assertSession()->elementExists('css', '.ez-mainviews .ez-view-locationviewview');
}
}