Skip to content

[Pangolin] Deliver changes to mainline framework repo #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class SectionObjectHandler implements ObjectHandlerInterface
const TYPE = 'section';
const SUB_TYPE = 'element';
const ELEMENT_TYPE_ATTR = 'type';
const ELEMENT_LOCATOR_ATTR = 'locator';
const ELEMENT_SELECTOR_ATTR = 'selector';
const ELEMENT_TIMEOUT_ATTR = 'timeout';
const ELEMENT_PARAMETERIZED = 'parameterized';

Expand Down Expand Up @@ -102,14 +102,14 @@ private function initSectionObjects()
$elements = [];
foreach ($sectionData[SectionObjectHandler::SUB_TYPE] as $elementName => $elementData) {
$elementType = $elementData[SectionObjectHandler::ELEMENT_TYPE_ATTR];
$elementLocator = $elementData[SectionObjectHandler::ELEMENT_LOCATOR_ATTR];
$elementSelector = $elementData[SectionObjectHandler::ELEMENT_SELECTOR_ATTR];
$elementTimeout = $elementData[SectionObjectHandler::ELEMENT_TIMEOUT_ATTR] ?? null;
$elementParameterized = $elementData[SectionObjectHandler::ELEMENT_PARAMETERIZED] ?? false;

$elements[$elementName] = new ElementObject(
$elementName,
$elementType,
$elementLocator,
$elementSelector,
$elementTimeout,
$elementParameterized
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ElementObject
*
* @var string
*/
private $locator;
private $selector;

/**
* Section element timeout
Expand All @@ -51,15 +51,15 @@ class ElementObject
* ElementObject constructor.
* @param string $name
* @param string $type
* @param string $locator
* @param string $selector
* @param string $timeout
* @param bool $parameterized
*/
public function __construct($name, $type, $locator, $timeout, $parameterized)
public function __construct($name, $type, $selector, $timeout, $parameterized)
{
$this->name = $name;
$this->type = $type;
$this->locator = $locator;
$this->selector = $selector;
$this->timeout = $timeout;
$this->parameterized = $parameterized;
}
Expand All @@ -85,13 +85,13 @@ public function getType()
}

/**
* Getter for the locator of an element
* Getter for the selector of an element
*
* @return string
*/
public function getLocator()
public function getSelector()
{
return $this->locator;
return $this->selector;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,10 @@
</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute type="notEmptyType" name="locator" use="required">
<xs:attribute type="notEmptyType" name="selector" use="required">
<xs:annotation>
<xs:documentation>
Locator of the element. Use %s for placeholders for variables.
</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute type="notEmptyType" name="locatorVariables" use="optional">
<xs:annotation>
<xs:documentation>
Optional variable names separated by "," which are used to substitute %s in locator attribute.
Selector of the element.
</xs:documentation>
</xs:annotation>
</xs:attribute>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@
class ActionObject
{
const DATA_ENABLED_ATTRIBUTES = ["userInput", "parameterArray"];
const SELECTOR_ENABLED_ATTRIBUTES = ['selector', 'dependentSelector'];
const SELECTOR_ENABLED_ATTRIBUTES = ['selector', 'dependentSelector', "selector1", "selector2"];
const MERGE_ACTION_ORDER_AFTER = 'after';
const ACTION_ATTRIBUTE_URL = 'url';
const ACTION_ATTRIBUTE_SELECTOR = 'selector';
const ACTION_ATTRIBUTE_VARIABLE_REGEX_PARAMETER = '/\(.+\)/';
const ACTION_ATTRIBUTE_VARIABLE_REGEX_PATTERN = '/{{[\w.\[\]]+}}/';
const ACTION_ATTRIBUTE_VARIABLE_REGEX_NESTED = '/{{[\w.\[\]()\',${} ]+}}/';
const ACTION_ATTRIBUTE_VARIABLE_REGEX_PATTERN = '/{{[\w.\[\]()\',$ ]+}}/';

/**
* The unique identifier for the action
Expand Down Expand Up @@ -298,15 +297,7 @@ private function stripAndReturnParameters($reference)
*/
private function findAndReplaceReferences($objectHandler, $inputString)
{
//Determine if there are Parethesis and parameters. If not, use strict regex. If so, use nested regex.
preg_match_all(ActionObject::ACTION_ATTRIBUTE_VARIABLE_REGEX_PARAMETER, $inputString, $variableMatches);
if (empty($variableMatches[0])) {
$regex = ActionObject::ACTION_ATTRIBUTE_VARIABLE_REGEX_PATTERN;
} else {
$regex = ActionObject::ACTION_ATTRIBUTE_VARIABLE_REGEX_NESTED;
}
preg_match_all($regex, $inputString, $matches);

preg_match_all(ActionObject::ACTION_ATTRIBUTE_VARIABLE_REGEX_PATTERN, $inputString, $matches);
if (empty($matches[0])) {
return $inputString;
}
Expand All @@ -332,7 +323,7 @@ private function findAndReplaceReferences($objectHandler, $inputString)
throw new TestReferenceException("Could not resolve entity reference " . $inputString);
}
$parameterized = $obj->getElement($objField)->isParameterized();
$replacement = $obj->getElement($objField)->getLocator();
$replacement = $obj->getElement($objField)->getSelector();
$this->timeout = $obj->getElement($objField)->getTimeout();
break;
case (get_class($obj) == EntityDataObject::class):
Expand Down Expand Up @@ -383,24 +374,38 @@ private function matchParameterReferences($reference, $parameters)
{
preg_match_all('/{{[\w.]+}}/', $reference, $varMatches);
if (count($varMatches[0]) > count($parameters)) {
if (is_array($parameters)) {
$parametersGiven = implode(",", $parameters);
} elseif ($parameters == null) {
$parametersGiven = "NONE";
} else {
$parametersGiven = $parameters;
}
throw new TestReferenceException(
"Parameter Resolution Failed: Not enough parameters given for reference " .
$reference . ". Parameters Given: " . implode(",", $parameters)
$reference . ". Parameters Given: " . $parametersGiven
);
} elseif (count($varMatches[0]) < count($parameters)) {
throw new TestReferenceException(
"Parameter Resolution Failed: Too many parameters given for reference " .
$reference . ". Parameters Given: " . implode(",", $parameters)
$reference . ". Parameters Given: " . implode(", ", $parameters)
);
}

//Attempt to Resolve {{data}} references to actual output.
//If regex matched it means that it's either a 'StringLiteral' or $key.data$/$$key.data$$ reference.
//Else assume it's a normal {{data.key}} reference and recurse through findAndReplace
$resolvedParameters = [];
foreach ($parameters as $parameter) {
$resolvedParameters[] = $this->findAndReplaceReferences(
DataObjectHandler::getInstance(),
$parameter
);
preg_match_all("/[$'][\w.$]+[$']/", $parameter, $match);
if (!empty($match[0])) {
$resolvedParameters[] = ltrim(rtrim($parameter, "'"), "'");
} else {
$resolvedParameters[] = $this->findAndReplaceReferences(
DataObjectHandler::getInstance(),
'{{' . $parameter . '}}'
);
}
}

$resolveIndex = 0;
Expand Down