2
2
3
3
namespace Magento \AcceptanceTestFramework \Test \Objects ;
4
4
5
+ use Magento \AcceptanceTestFramework \PageObject \Page \Page ;
6
+ use Magento \AcceptanceTestFramework \PageObject \Section \Section ;
7
+
5
8
class ActionObject
6
9
{
7
10
private $ mergeKey ;
8
11
private $ type ;
9
12
private $ actionAttributes = [];
10
13
private $ linkedAction ;
11
14
private $ orderOffset = 0 ;
15
+ private $ resolvedCustomAttributes = [];
16
+ private $ timeout ;
12
17
13
18
public function __construct ($ mergeKey , $ type , $ actionAttributes , $ linkedAction = null , $ order = 0 )
14
19
{
@@ -37,11 +42,13 @@ public function getType()
37
42
* the tag <seeNumberOfElements selector="value1" expected="value2" mergeKey=""/> has 3 attributes,
38
43
* only 2 of which are specific to the 'seeNumberOfElements' tag. As a result this function would
39
44
* return the array would return [selector => value1, expected => value2]
45
+ * The returned array is also the merged result of the resolved and normal actions, giving
46
+ * priority to the resolved actions (resolved selector instead of section.element, etc).
40
47
* @return array
41
48
*/
42
49
public function getCustomActionAttributes ()
43
50
{
44
- return $ this ->actionAttributes ;
51
+ return array_merge ( $ this ->actionAttributes , $ this -> resolvedCustomAttributes ) ;
45
52
}
46
53
47
54
public function getLinkedAction ()
@@ -53,4 +60,46 @@ public function getOrderOffset()
53
60
{
54
61
return $ this ->orderOffset ;
55
62
}
56
- }
63
+
64
+ public function getTimeout ()
65
+ {
66
+ return $ this ->timeout ;
67
+ }
68
+
69
+ /**
70
+ * Resolves all references
71
+ */
72
+ public function resolveReferences ()
73
+ {
74
+ if (empty ($ this ->resolvedCustomAttributes )){
75
+ $ this ->resolveSelectorReference ();
76
+ $ this ->resolveUrlReference ();
77
+ }
78
+ }
79
+
80
+ /**
81
+ * Checks if selector is an attribute, and if the selector refers to a defined section.
82
+ * If not, assume selector is CSS/xpath literal and leave it be.
83
+ */
84
+ private function resolveSelectorReference ()
85
+ {
86
+ if (array_key_exists ('selector ' , $ this ->actionAttributes )
87
+ and array_key_exists (strtok ($ this ->actionAttributes ['selector ' ], '. ' ), Section::getSection ()) ) {
88
+ list ($ section , $ element ) = explode ('. ' , $ this ->actionAttributes ['selector ' ]);
89
+ $ this ->resolvedCustomAttributes ['selector ' ] = Section::getElementLocator ($ section , $ element );
90
+ $ this ->timeout = Section::getElementTimeOut ($ section , $ element );
91
+ }
92
+ }
93
+
94
+ /**
95
+ * Checks if url is an attribute, and if the url given is a defined page.
96
+ * If not, assume url is literal and leave it be.
97
+ */
98
+ private function resolveUrlReference ()
99
+ {
100
+ if (array_key_exists ('url ' , $ this ->actionAttributes )
101
+ and array_key_exists ($ this ->actionAttributes ['url ' ], Page::getPage ())) {
102
+ $ this ->resolvedCustomAttributes ['url ' ] = $ _ENV ['MAGENTO_BASE_URL ' ] . Page::getPageUrl ($ this ->actionAttributes ['url ' ]);
103
+ }
104
+ }
105
+ }
0 commit comments