@@ -4,23 +4,20 @@ import {
4
4
MENUITEM_NO_A11Y_LABEL_COMPONENT ,
5
5
HOMEPAGE_MENU_BUTTON ,
6
6
MENUITEM_TEST_COMPONENT ,
7
- MENUPOPOVER_TEST_COMPONENT ,
8
7
MENUITEM_DISABLED_COMPONENT ,
9
8
MENUITEM_FOURTH_COMPONENT ,
10
9
MENU_CALLBACK_RESET_BUTTON ,
11
10
MENUITEM_CALLBACK_LABEL ,
12
11
} from '../consts' ;
13
12
import { BasePage , By } from '../../common/BasePage' ;
14
- import { Keys , Attribute , AttributeValue } from '../../common/consts' ;
15
-
16
- /* This enum gives the spec file an EASY way to interact with SPECIFIC UI elements on the page.
17
- * The spec file should import this enum and use it when wanting to interact with different elements on the page. */
18
- export const enum MenuComponentSelector {
19
- MenuTrigger = 0 , //this._primaryComponent
20
- FirstMenuItem ,
21
- SecondMenuItem ,
22
- ThirdMenuItem ,
23
- FourthMenuItem ,
13
+ import { Keys } from '../../common/consts' ;
14
+
15
+ /** Allows a caller to get specific menu items using .getMenuItem() */
16
+ export const enum MenuItem {
17
+ First ,
18
+ Second ,
19
+ Third ,
20
+ Fourth ,
24
21
}
25
22
26
23
class MenuPageObject extends BasePage {
@@ -35,32 +32,51 @@ class MenuPageObject extends BasePage {
35
32
*/
36
33
async openMenu ( ) : Promise < void > {
37
34
if ( ! ( await this . menuIsExpanded ( ) ) ) {
38
- await this . clickItem ( MenuComponentSelector . MenuTrigger ) ;
35
+ await this . click ( this . _menuTrigger ) ;
39
36
await this . waitForMenuToOpen ( ) ;
40
37
}
41
38
}
42
39
43
40
async closeMenu ( ) : Promise < void > {
44
41
if ( await this . menuIsExpanded ( ) ) {
45
- await this . sendKey ( MenuComponentSelector . FirstMenuItem , Keys . ESCAPE ) ;
46
- await this . waitForCondition ( async ( ) => ( await this . menuIsExpanded ( ) ) === false , 'The Menu did not close.' , this . waitForUiEvent , 500 ) ;
42
+ await this . sendKeys ( this . getMenuItem ( MenuItem . First ) , [ Keys . ESCAPE ] ) ;
43
+ await this . waitForMenuToClose ( ) ;
47
44
}
48
45
}
49
46
50
- async waitForMenuToOpen ( ) : Promise < boolean > {
51
- await this . waitForCondition ( async ( ) => await this . menuIsExpanded ( ) , 'The Menu did not open.' , this . waitForUiEvent , 500 ) ;
47
+ /* Waits for menuitems to be visible. This is a separate method from openMenu() because we test multiple ways of opening the menu (mouse + keyboard). */
48
+ async waitForMenuToOpen ( errorMsg ?: string ) : Promise < boolean > {
49
+ await this . waitForCondition (
50
+ async ( ) => await this . menuIsExpanded ( ) ,
51
+ errorMsg ?? 'The Menu did not open: It looks like the MenuItems failed to display.' ,
52
+ this . waitForUiEvent ,
53
+ 500 ,
54
+ ) ;
52
55
return await this . menuIsExpanded ( ) ;
53
56
}
54
57
58
+ /* Same as above -> Just waits for menuitems to not be visible. */
59
+ async waitForMenuToClose ( errorMsg ?: string ) : Promise < boolean > {
60
+ await this . waitForCondition (
61
+ async ( ) => ! ( await this . menuIsExpanded ( ) ) ,
62
+ errorMsg ?? 'The Menu did not close: It looks like the MenuItems are still displayed.' ,
63
+ this . waitForUiEvent ,
64
+ 500 ,
65
+ ) ;
66
+ return ! ( await this . menuIsExpanded ( ) ) ;
67
+ }
68
+
69
+ /* If the first item is displayed, then it's safe to say that the rest of the menu is expanded. */
55
70
async menuIsExpanded ( ) : Promise < boolean > {
56
- const menuItem = await this . _firstMenuItem ;
71
+ const menuItem = await this . getMenuItem ( MenuItem . First ) ;
57
72
if ( menuItem . error ) {
58
73
// Not displayed because the item can't be found by appium
59
74
return false ;
60
75
}
61
76
return await menuItem . isDisplayed ( ) ;
62
77
}
63
78
79
+ /* Waits for the onClick callback of menu item 1 to fire. */
64
80
async waitForItemCallbackToFire ( timesFired : number ) : Promise < void > {
65
81
await this . waitForCondition (
66
82
async ( ) => await this . itemOnClickHasFired ( timesFired ) ,
@@ -70,57 +86,27 @@ class MenuPageObject extends BasePage {
70
86
) ;
71
87
}
72
88
89
+ /* When menu item 1 is clicked, it increments a counter variable in the test component page, which is displayed in a text box. Incrementing a counter within a label
90
+ * allows us to test whether the onClick() callback fires for click and keypress inputs across individual test cases without having to close the menu and reset the
91
+ * label per case (as you see in the button + checkbox tests). This decreases test time and improves performance for this spec. */
73
92
async itemOnClickHasFired ( timesFired : number ) : Promise < boolean > {
74
- return ( await ( await this . _callbackLabel ) . getText ( ) ) . includes ( timesFired . toString ( ) ) ;
75
- }
76
-
77
- async componentIsFocused ( selector : MenuComponentSelector ) : Promise < boolean > {
78
- const component = await this . getMenuComponentSelector ( selector ) ;
79
- return ( await this . getElementAttribute ( component , Attribute . IsFocused ) ) === AttributeValue . true ;
80
- }
81
-
82
- async getMenuExpandCollapseState ( ) : Promise < AttributeValue > {
83
- return ( await this . getElementAttribute ( await this . _primaryComponent , Attribute . ExpandCollapseState ) ) as AttributeValue ;
84
- }
85
-
86
- async getMenuItemAccessibilityLabel ( componentSelector : MenuComponentSelector ) : Promise < string > {
87
- return await this . getElementAttribute ( await this . getMenuComponentSelector ( componentSelector ) , Attribute . AccessibilityLabel ) ;
88
- }
89
-
90
- async getMenuAccessibilityRole ( ) : Promise < string > {
91
- return await this . getElementAttribute ( await By ( MENUPOPOVER_TEST_COMPONENT ) , Attribute . AccessibilityRole ) ;
92
- }
93
-
94
- async getMenuItemAccessibilityRole ( ) : Promise < string > {
95
- return await this . getElementAttribute ( await this . _firstMenuItem , Attribute . AccessibilityRole ) ;
96
- }
97
-
98
- /* Sends a Keyboarding command on a specific UI element */
99
- async sendKey ( menuComponentSelector : MenuComponentSelector , key : string ) : Promise < void > {
100
- await ( await this . getMenuComponentSelector ( menuComponentSelector ) ) . addValue ( key ) ;
101
- }
102
-
103
- // Renaming this function until Menu tests are refactored to use BasePage methods.
104
- async clickItem ( selector : MenuComponentSelector ) : Promise < void > {
105
- await ( await this . getMenuComponentSelector ( selector ) ) . click ( ) ;
106
- }
107
-
108
- /* Returns the correct WebDriverIO element from the Button Selector */
109
- async getMenuComponentSelector ( menuComponentSelector : MenuComponentSelector ) : Promise < WebdriverIO . Element > {
110
- switch ( menuComponentSelector ) {
111
- case MenuComponentSelector . MenuTrigger :
112
- return await this . _primaryComponent ;
113
- case MenuComponentSelector . FirstMenuItem :
114
- return await this . _firstMenuItem ;
115
- case MenuComponentSelector . SecondMenuItem :
116
- return await this . _secondMenuItem ;
117
- case MenuComponentSelector . ThirdMenuItem :
118
- return await this . _thirdMenuItem ;
119
- case MenuComponentSelector . FourthMenuItem :
120
- return await this . _fourthMenuItem ;
93
+ return ( await ( await this . _callbackLabel ) . getText ( ) ) === `onClick fired ${ timesFired } times` ;
94
+ }
95
+
96
+ async getMenuItem ( item : MenuItem ) : Promise < WebdriverIO . Element > {
97
+ switch ( item ) {
98
+ case MenuItem . First :
99
+ return await By ( MENUITEM_TEST_COMPONENT ) ;
100
+ case MenuItem . Second :
101
+ return await By ( MENUITEM_DISABLED_COMPONENT ) ;
102
+ case MenuItem . Third :
103
+ return await By ( MENUITEM_NO_A11Y_LABEL_COMPONENT ) ;
104
+ case MenuItem . Fourth :
105
+ return await By ( MENUITEM_FOURTH_COMPONENT ) ;
121
106
}
122
107
}
123
108
109
+ /* Closes the menu and resets the counter to 0 on the test page. */
124
110
async resetTest ( ) {
125
111
// Both escape on the menu trigger to hard dismiss menu and click callback reset to reset focus
126
112
await this . closeMenu ( ) ;
@@ -138,26 +124,10 @@ class MenuPageObject extends BasePage {
138
124
return MENU_TESTPAGE ;
139
125
}
140
126
141
- get _primaryComponent ( ) {
127
+ get _menuTrigger ( ) {
142
128
return By ( MENUTRIGGER_TEST_COMPONENT ) ;
143
129
}
144
130
145
- get _firstMenuItem ( ) {
146
- return By ( MENUITEM_TEST_COMPONENT ) ;
147
- }
148
-
149
- get _secondMenuItem ( ) {
150
- return By ( MENUITEM_DISABLED_COMPONENT ) ;
151
- }
152
-
153
- get _thirdMenuItem ( ) {
154
- return By ( MENUITEM_NO_A11Y_LABEL_COMPONENT ) ;
155
- }
156
-
157
- get _fourthMenuItem ( ) {
158
- return By ( MENUITEM_FOURTH_COMPONENT ) ;
159
- }
160
-
161
131
get _pageButton ( ) {
162
132
return By ( HOMEPAGE_MENU_BUTTON ) ;
163
133
}
0 commit comments