Skip to content

Commit b8f49d0

Browse files
committed
MQE-349:[PageObjects] Need to add customized function for conditional click
- add supporting logic for conditional click behavior - add conditionalClick schema to test xsd
1 parent a81ce7d commit b8f49d0

File tree

5 files changed

+66
-16
lines changed

5 files changed

+66
-16
lines changed

src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,6 @@ public function _getCurrentUri()
9999
return Uri::retrieveUri($url);
100100
}
101101

102-
/**
103-
* Returns an array of Elements.
104-
*
105-
* @param string $locator
106-
* @return array
107-
*/
108-
public function findElement($locator)
109-
{
110-
return $this->_findElements($locator);
111-
}
112-
113102
/**
114103
* Login Magento Admin with given username and password.
115104
*
@@ -285,6 +274,32 @@ public function scrollToTopOfPage()
285274
$this->executeJS('window.scrollTo(0,0);');
286275
}
287276

277+
/**
278+
* Conditional click for an area that should be visible
279+
*
280+
* @param string $selector
281+
* @param string dependentSelector
282+
* @param bool $visible
283+
*/
284+
public function conditionalClick($selector, $dependentSelector, $visible)
285+
{
286+
$el = $this->_findElements($dependentSelector);
287+
if (sizeof($el) > 1) {
288+
throw new \Exception("more than one element matches selector " . $selector);
289+
}
290+
291+
$clickCondition = null;
292+
if ($visible) {
293+
$clickCondition = !empty($el) && $el[0]->isDisplayed();
294+
} else {
295+
$clickCondition = empty($el) || !$el[0]->isDisplayed();
296+
}
297+
298+
if ($clickCondition) {
299+
$this->click($selector);
300+
}
301+
}
302+
288303
/**
289304
* Override for _failed method in Codeception method. Adds png and html attachments to allure report
290305
* following parent execution of test failure processing.

src/Magento/FunctionalTestingFramework/Test/Objects/ActionObject.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
class ActionObject
2121
{
2222
const DATA_ENABLED_ATTRIBUTES = ["userInput", "parameterArray"];
23+
const SELECTOR_ENABLED_ATTRIBUTES = ['selector', 'dependentSelector'];
2324
const MERGE_ACTION_ORDER_AFTER = 'after';
2425
const ACTION_ATTRIBUTE_URL = 'url';
2526
const ACTION_ATTRIBUTE_SELECTOR = 'selector';
@@ -189,15 +190,20 @@ public function resolveReferences()
189190
*/
190191
private function resolveSelectorReferenceAndTimeout()
191192
{
192-
if (!array_key_exists(ActionObject::ACTION_ATTRIBUTE_SELECTOR, $this->actionAttributes)) {
193+
$actionAttributeKeys = array_keys($this->actionAttributes);
194+
$relevantSelectorAttributes = array_intersect($actionAttributeKeys, ActionObject::SELECTOR_ENABLED_ATTRIBUTES);
195+
196+
if (empty($relevantSelectorAttributes)) {
193197
return;
194198
}
195199

196-
$selector = $this->actionAttributes[ActionObject::ACTION_ATTRIBUTE_SELECTOR];
200+
foreach ($relevantSelectorAttributes as $selectorAttribute) {
201+
$selector = $this->actionAttributes[$selectorAttribute];
197202

198-
$replacement = $this->findAndReplaceReferences(SectionObjectHandler::getInstance(), $selector);
199-
if ($replacement) {
200-
$this->resolvedCustomAttributes[ActionObject::ACTION_ATTRIBUTE_SELECTOR] = $replacement;
203+
$replacement = $this->findAndReplaceReferences(SectionObjectHandler::getInstance(), $selector);
204+
if ($replacement) {
205+
$this->resolvedCustomAttributes[$selectorAttribute] = $replacement;
206+
}
201207
}
202208
}
203209

src/Magento/FunctionalTestingFramework/Test/etc/sampleCest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<click selector="" mergeKey=""/>
2222
<clickWithLeftButton selector="" mergeKey=""/>
2323
<clickWithRightButton selector="" mergeKey=""/>
24+
<conditionalClick mergeKey="" selector="" dependentSelector="" visible="true" />
2425
<closeTab mergeKey=""/>
2526
<dontSee userInput="" selector="" mergeKey=""/>
2627
<dontSeeCheckboxIsChecked selector="" mergeKey=""/>

src/Magento/FunctionalTestingFramework/Test/etc/testSchema.xsd

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
<xs:element type="clickWithRightButtonType" name="clickWithRightButton" minOccurs="0" maxOccurs="unbounded"/>
8585
<xs:element type="closeAdminNotificationType" name="closeAdminNotification" minOccurs="0" maxOccurs="unbounded"/>
8686
<xs:element type="closeTabType" name="closeTab" minOccurs="0" maxOccurs="unbounded"/>
87+
<xs:element type="conditionalClickType" name="conditionalClick" minOccurs="0" maxOccurs="unbounded"/>
8788
<xs:element type="createDataType" name="createData" minOccurs="0" maxOccurs="unbounded"/>
8889
<xs:element type="deleteDataType" name="deleteData" minOccurs="0" maxOccurs="unbounded"/>
8990
<xs:element type="dontSeeType" name="dontSee" minOccurs="0" maxOccurs="unbounded"/>
@@ -352,6 +353,19 @@
352353
</xs:extension>
353354
</xs:simpleContent>
354355
</xs:complexType>
356+
<xs:complexType name="conditionalClickType">
357+
<xs:simpleContent>
358+
<xs:extension base="xs:string">
359+
<xs:attribute type="xs:string" name="selector"/>
360+
<xs:attribute type="xs:string" name="dependentSelector" />
361+
<xs:attribute type="xs:boolean" name="visible"/>
362+
<xs:attribute type="xs:string" name="mergeKey" use="required"/>
363+
<xs:attribute type="xs:boolean" name="remove" default="false"/>
364+
<xs:attribute type="xs:string" name="before"/>
365+
<xs:attribute type="xs:string" name="after"/>
366+
</xs:extension>
367+
</xs:simpleContent>
368+
</xs:complexType>
355369
<xs:complexType name="createDataType">
356370
<xs:choice minOccurs="0" maxOccurs="unbounded">
357371
<xs:element type="requiredEntityType" name="required-entity" minOccurs="0" maxOccurs="unbounded"/>

src/Magento/FunctionalTestingFramework/Util/TestGenerator.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,8 @@ private function generateStepsPhp($stepsObject, $stepsData, $hookObject = false)
348348
$value = null;
349349
$button = null;
350350
$parameter = null;
351+
$dependentSelector = null;
352+
$visible = null;
351353

352354
if (isset($customActionAttributes['returnVariable'])) {
353355
$returnVariable = $customActionAttributes['returnVariable'];
@@ -450,6 +452,15 @@ private function generateStepsPhp($stepsObject, $stepsData, $hookObject = false)
450452
$parameter = $this->wrapWithDoubleQuotes($customActionAttributes['parameter']);
451453
}
452454

455+
456+
if (isset($customActionAttributes['dependentSelector'])) {
457+
$dependentSelector = $this->wrapWithDoubleQuotes($customActionAttributes['dependentSelector']);
458+
}
459+
460+
if (isset($customActionAttributes['visible'])) {
461+
$visible = $customActionAttributes['visible'];
462+
}
463+
453464
switch ($actionName) {
454465
case "createData":
455466
$entity = $customActionAttributes['entity'];
@@ -757,6 +768,9 @@ private function generateStepsPhp($stepsObject, $stepsData, $hookObject = false)
757768
// TODO: Need to fix xml parser to allow parsing html.
758769
$testSteps .= $this->wrapFunctionCall($actor, $actionName, $html);
759770
break;
771+
case "conditionalClick":
772+
$testSteps .= $this->wrapFunctionCall($actor, $actionName, $selector, $dependentSelector, $visible);
773+
break;
760774
default:
761775
if ($returnVariable) {
762776
$testSteps .= $this->wrapFunctionCallWithReturnValue(

0 commit comments

Comments
 (0)