1
+ 'use strict'
1
2
import { NightwatchBrowser } from 'nightwatch'
2
3
import EventEmitter from 'events'
3
4
@@ -80,29 +81,27 @@ class switchEnvironment extends EventEmitter {
80
81
}
81
82
browser
82
83
. execute ( function ( xpath ) {
83
- const element = document . evaluate ( xpath , document , null , XPathResult . FIRST_ORDERED_NODE_TYPE , null ) . singleNodeValue
84
- if ( element ) {
85
- const event = new MouseEvent ( 'mouseover' , { 'view' : window , 'bubbles' : true , 'cancelable' : true } )
86
- element . dispatchEvent ( event )
87
- }
88
- } ,
89
- [ submenuXPath ]
90
- )
84
+ const element = document . evaluate ( xpath , document , null , XPathResult . FIRST_ORDERED_NODE_TYPE , null ) . singleNodeValue
85
+ if ( element ) {
86
+ const event = new MouseEvent ( 'mouseover' , { 'view' : window , 'bubbles' : true , 'cancelable' : true } )
87
+ element . dispatchEvent ( event )
88
+ }
89
+ } ,
90
+ [ submenuXPath ]
91
+ )
91
92
. useCss ( )
92
- . waitForElementVisible (
93
- `body .dropdown-menu.show [data-id="dropdown-item-${ providerName } "]` ,
94
- 5000 ,
95
- undefined ,
96
- false ,
97
- ( result ) => {
98
- if ( result . status === 0 ) {
93
+ . isPresent ( {
94
+ selector : `body .dropdown-menu.show [data-id="dropdown-item-${ providerName } "]` ,
95
+ suppressNotFoundErrors : true ,
96
+ timeout : 2000
97
+ } , ( inPortal ) => {
98
+ if ( inPortal . value ) {
99
99
clickAndMaybeWait ( browser , `body .dropdown-menu.show [data-id="dropdown-item-${ providerName } "]` , providerName , shouldWait )
100
100
onDone ( )
101
101
} else {
102
102
tryOne ( i + 1 )
103
103
}
104
- }
105
- )
104
+ } )
106
105
} )
107
106
}
108
107
tryOne ( 0 )
@@ -133,19 +132,21 @@ class switchEnvironment extends EventEmitter {
133
132
. perform ( ( done ) => {
134
133
this . api . isPresent ( { selector : `[data-id="selected-provider-${ provider } "]` , suppressNotFoundErrors : true , timeout : 1000 } , ( result ) => {
135
134
if ( result . value ) return done ( )
136
-
135
+
137
136
this . api . click ( '[data-id="settingsSelectEnvOptions"] button' )
138
-
139
- attemptSelect ( this . api , provider , returnWhenInitialized , ( ) => {
140
- waitForSelectedOrModal ( this . api , provider , 10000 , ( ok ) => {
141
- if ( ok ) {
142
- return done ( )
143
- } else {
144
- this . api . assert . fail ( `Environment "${ provider } " could not be selected or found in the dropdown.` )
145
- done ( )
146
- }
137
+ . waitForElementVisible ( 'body .dropdown-menu.show' , 3000 )
138
+ . perform ( ( ) => {
139
+ attemptSelect ( this . api , provider , returnWhenInitialized , ( ) => {
140
+ waitForSelectedOrModal ( this . api , provider , 10000 , ( ok ) => {
141
+ if ( ok ) {
142
+ return done ( )
143
+ } else {
144
+ this . api . assert . fail ( `Environment "${ provider } " could not be selected or found in the dropdown.` )
145
+ done ( )
146
+ }
147
+ } )
148
+ } )
147
149
} )
148
- } )
149
150
} )
150
151
} )
151
152
. perform ( ( ) => this . emit ( 'complete' ) )
@@ -154,4 +155,4 @@ class switchEnvironment extends EventEmitter {
154
155
}
155
156
}
156
157
157
- module . exports = switchEnvironment
158
+ module . exports = switchEnvironment
0 commit comments