Skip to content

Commit d36c457

Browse files
committed
Fixes for the new workflows in j4
1 parent 8be3499 commit d36c457

File tree

2 files changed

+68
-12
lines changed

2 files changed

+68
-12
lines changed

src/ElementIsVisibleTrait.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
/**
3+
* @package JoomlaBrowser
4+
*
5+
* @copyright Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved.
6+
* @license GNU General Public License version 2 or later; see LICENSE.txt
7+
*/
8+
9+
namespace Joomla\Browser;
10+
11+
use Facebook\WebDriver\Remote\RemoteWebDriver;
12+
use Facebook\WebDriver\Remote\RemoteWebElement;
13+
use Facebook\WebDriver\WebDriverBy;
14+
15+
/**
16+
* Trait ElementIsVisibleTrait Based on the blog post below
17+
*
18+
* @see https://maslosoft.com/blog/2018/04/04/codeception-acceptance-check-if-element-is-visible/
19+
*/
20+
trait ElementIsVisibleTrait {
21+
22+
/**
23+
* Checks if an element is visible on the page
24+
*
25+
* @param string $element The element to check if it's visible
26+
*
27+
* @return bool
28+
*/
29+
public function haveVisible($element)
30+
{
31+
/** @var \Codeception\Actor $I */
32+
$I = $this;
33+
$value = false;
34+
$I->executeInSelenium(function(RemoteWebDriver $webDriver)use($element, &$value)
35+
{
36+
try
37+
{
38+
$element = $webDriver->findElement(WebDriverBy::cssSelector($element));
39+
$value = $element instanceof RemoteWebElement;
40+
}
41+
catch (\Exception $e)
42+
{
43+
// Swallow exception silently
44+
}
45+
});
46+
return $value;
47+
}
48+
}

src/JoomlaBrowser.php

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
*/
2121
class JoomlaBrowser extends WebDriver
2222
{
23+
use ElementIsVisibleTrait;
24+
2325
/**
2426
* The module required fields, to be set in the suite .yml configuration file.
2527
*
@@ -287,16 +289,18 @@ public function installJoomlaRemovingInstallationFolder()
287289
{
288290
$this->installJoomla();
289291

290-
// TODO: This will not show in stable mode. Tests need to handle this accordingly
291-
$this->debug('Removing Installation Folder');
292-
$this->click(['id' => 'removeInstallationFolder']);
292+
if (!$this->haveVisible('#removeInstallationFolder'))
293+
{
294+
$this->debug('Removing Installation Folder');
295+
$this->click(['id' => 'removeInstallationFolder']);
293296

294-
// Accept the confirmation alert
295-
$this->seeInPopup('Are you sure you want to delete?');
296-
$this->acceptPopup();
297+
// Accept the confirmation alert
298+
$this->seeInPopup('Are you sure you want to delete?');
299+
$this->acceptPopup();
297300

298-
// Wait until the installation folder is gone and the "customize installation" box has been removed
299-
$this->waitForElementNotVisible(['id' => 'installAddFeatures']);
301+
// Wait until the installation folder is gone and the "customize installation" box has been removed
302+
$this->waitForElementNotVisible(['id' => 'installAddFeatures']);
303+
}
300304

301305
$this->debug('Joomla is now installed');
302306
$this->click(['button' => "Complete & Open Admin"]);
@@ -343,11 +347,15 @@ public function installJoomlaMultilingualSite($languages = array())
343347
$this->click(['link' => 'Next']);
344348

345349
$this->waitForText('Congratulations! Joomla! is now installed.', $this->config['timeout'], ['xpath' => '//h2']);
346-
$this->debug('Removing Installation Folder');
347-
$this->click(['xpath' => "//input[@value='Remove \"installation\" folder']"]);
348350

349-
// @todo https://github.com/joomla-projects/joomla-browser/issues/45
350-
$this->wait(2);
351+
if (!$this->haveVisible('#removeInstallationFolder'))
352+
{
353+
$this->debug('Removing Installation Folder');
354+
$this->click(['xpath' => "//input[@value='Remove \"installation\" folder']"]);
355+
356+
// Wait until the installation folder is gone and the "customize installation" box has been removed
357+
$this->waitForElementNotVisible(['id' => 'installAddFeatures']);
358+
}
351359

352360
$this->debug('Joomla is now installed');
353361
$this->see('Congratulations! Joomla! is now installed.', ['xpath' => '//h2']);

0 commit comments

Comments
 (0)