@@ -35,18 +35,22 @@ public class EdgeBase
35
35
36
36
public static void Setup ( TestContext context )
37
37
{
38
- // Cleanup leftover objects from previous test if exists
39
- TearDown ( ) ;
40
-
41
- // Launch the Edge browser app
42
- session = Utility . CreateNewSession ( CommonTestSettings . EdgeAppId ) ;
43
- session . Manage ( ) . Timeouts ( ) . ImplicitlyWait ( TimeSpan . FromSeconds ( 5 ) ) ;
44
- Assert . IsNotNull ( session ) ;
45
- Assert . IsNotNull ( session . SessionId ) ;
46
-
47
- // Initialize touch screen object
48
- touchScreen = new RemoteTouchScreen ( session ) ;
49
- Assert . IsNotNull ( touchScreen ) ;
38
+ // Launch Edge browser app if it is not yet launched
39
+ if ( session == null || touchScreen == null || ! Utility . CurrentWindowIsAlive ( session ) )
40
+ {
41
+ // Cleanup leftover objects from previous test if exists
42
+ TearDown ( ) ;
43
+
44
+ // Launch the Edge browser app
45
+ session = Utility . CreateNewSession ( CommonTestSettings . EdgeAppId ) ;
46
+ session . Manage ( ) . Timeouts ( ) . ImplicitlyWait ( TimeSpan . FromSeconds ( 5 ) ) ;
47
+ Assert . IsNotNull ( session ) ;
48
+ Assert . IsNotNull ( session . SessionId ) ;
49
+
50
+ // Initialize touch screen object
51
+ touchScreen = new RemoteTouchScreen ( session ) ;
52
+ Assert . IsNotNull ( touchScreen ) ;
53
+ }
50
54
51
55
// Track the Microsoft Edge starting page title to be used to initialize all test cases
52
56
System . Threading . Thread . Sleep ( 3000 ) ; // Sleep for 3 seconds
@@ -100,108 +104,28 @@ public void TestInit()
100
104
}
101
105
}
102
106
103
- protected RemoteWebElement GetOrphanedElement ( WindowsDriver < WindowsElement > remoteSession )
104
- {
105
- RemoteWebElement orphanedElement = null ;
106
-
107
- // Track existing opened Edge window(s) and only manipulate newly opened windows
108
- var previouslyOpenedEdgeWindows = remoteSession . WindowHandles ;
109
- var originalActiveWindowHandle = remoteSession . CurrentWindowHandle ;
110
-
111
- // Open a new window
112
- // The menu item names have changed between Windows 10 and the anniversary update
113
- // account for both combinations.
114
- try
115
- {
116
- remoteSession . FindElementByAccessibilityId ( "m_actionsMenuButton" ) . Click ( ) ;
117
- remoteSession . FindElementByAccessibilityId ( "m_newWindow" ) . Click ( ) ;
118
- }
119
- catch ( System . InvalidOperationException )
120
- {
121
- remoteSession . FindElementByAccessibilityId ( "ActionsMenuButton" ) . Click ( ) ;
122
- remoteSession . FindElementByAccessibilityId ( "ActionsMenuNewWindow" ) . Click ( ) ;
123
- }
124
-
125
- System . Threading . Thread . Sleep ( 3000 ) ; // Sleep for 3 second
126
- var multipleWindowHandles = remoteSession . WindowHandles ;
127
- Assert . IsTrue ( multipleWindowHandles . Count == previouslyOpenedEdgeWindows . Count + 1 ) ;
128
-
129
- // Ensure we get the newly opened window by removing other previously known windows from the list
130
- List < String > newlyOpenedEdgeWindows = new List < String > ( multipleWindowHandles ) ;
131
- foreach ( var previouslyOpenedEdgeWindow in previouslyOpenedEdgeWindows )
132
- {
133
- newlyOpenedEdgeWindows . Remove ( previouslyOpenedEdgeWindow ) ;
134
- }
135
- Assert . IsTrue ( newlyOpenedEdgeWindows . Count == 1 ) ;
136
-
137
- // Switch to new window and use the address edit box as orphaned element
138
- remoteSession . SwitchTo ( ) . Window ( newlyOpenedEdgeWindows [ 0 ] ) ;
139
- System . Threading . Thread . Sleep ( 1000 ) ; // Sleep for 1 second
140
- Assert . AreEqual ( newlyOpenedEdgeWindows [ 0 ] , remoteSession . CurrentWindowHandle ) ;
141
- orphanedElement = remoteSession . FindElementByAccessibilityId ( "addressEditBox" ) ;
142
- Assert . IsNotNull ( orphanedElement ) ;
143
-
144
- // Close the newly opened window and return to previously active window
145
- remoteSession . Close ( ) ;
146
- remoteSession . SwitchTo ( ) . Window ( originalActiveWindowHandle ) ;
147
- System . Threading . Thread . Sleep ( 1000 ) ; // Sleep for 1 second
148
-
149
- return orphanedElement ;
150
- }
151
-
152
- protected static RemoteWebElement GetStaleElement ( WindowsDriver < WindowsElement > remoteSession )
107
+ protected static RemoteWebElement GetStaleElement ( )
153
108
{
154
109
RemoteWebElement staleElement = null ;
155
110
156
- remoteSession . FindElementByAccessibilityId ( "addressEditBox" ) . SendKeys ( CommonTestSettings . MicrosoftUrl + OpenQA . Selenium . Keys . Enter ) ;
157
- System . Threading . Thread . Sleep ( 3000 ) ; // Sleep for 3 seconds
158
- var originalTitle = remoteSession . Title ;
111
+ session . FindElementByAccessibilityId ( "addressEditBox" ) . SendKeys ( CommonTestSettings . EdgeAboutTabsURL + OpenQA . Selenium . Keys . Enter ) ;
112
+ System . Threading . Thread . Sleep ( 2000 ) ; // Sleep for 2 seconds
113
+ var originalTitle = session . Title ;
159
114
Assert . AreNotEqual ( string . Empty , originalTitle ) ;
160
115
161
- // Navigate to GitHub page
162
- remoteSession . FindElementByAccessibilityId ( "addressEditBox" ) . SendKeys ( CommonTestSettings . GitHubUrl + OpenQA . Selenium . Keys . Enter ) ;
163
- System . Threading . Thread . Sleep ( 3000 ) ; // Sleep for 3 seconds
164
- Assert . AreNotEqual ( originalTitle , remoteSession . Title ) ;
116
+ // Navigate to Edge about:flags page
117
+ session . FindElementByAccessibilityId ( "addressEditBox" ) . SendKeys ( CommonTestSettings . EdgeAboutFlagsURL + OpenQA . Selenium . Keys . Enter ) ;
118
+ System . Threading . Thread . Sleep ( 2000 ) ; // Sleep for 2 seconds
119
+ Assert . AreNotEqual ( originalTitle , session . Title ) ;
165
120
166
- // Save a reference to Homepage web link on the GitHub page and navigate back to home
167
- staleElement = remoteSession . FindElementByName ( "Homepage ") ;
121
+ // Save a reference to Reset all flags button on the page and navigate back to home
122
+ staleElement = session . FindElementByAccessibilityId ( "ResetAllFlags ") ;
168
123
Assert . IsNotNull ( staleElement ) ;
169
- remoteSession . Navigate ( ) . Back ( ) ;
170
- System . Threading . Thread . Sleep ( 2000 ) ;
124
+ session . Navigate ( ) . Back ( ) ;
125
+ System . Threading . Thread . Sleep ( 1000 ) ;
171
126
Assert . AreEqual ( originalTitle , session . Title ) ;
172
127
173
128
return staleElement ;
174
129
}
175
-
176
- protected HttpWebResponse SendTouchPost ( String touchType , JObject requestObject )
177
- {
178
- var request = WebRequest . Create ( CommonTestSettings . WindowsApplicationDriverUrl + "/session/" + session . SessionId + "/touch/" + touchType ) ;
179
- request . Method = "POST" ;
180
- request . ContentType = "application/json" ;
181
-
182
- String postData = requestObject . ToString ( ) ;
183
- byte [ ] byteArray = Encoding . UTF8 . GetBytes ( postData ) ;
184
- request . ContentLength = byteArray . Length ;
185
- Stream dataStream = request . GetRequestStream ( ) ;
186
- dataStream . Write ( byteArray , 0 , byteArray . Length ) ;
187
- dataStream . Close ( ) ;
188
- return request . GetResponse ( ) as HttpWebResponse ;
189
- }
190
-
191
- public void ErrorTouchInvalidElement ( string touchType )
192
- {
193
- JObject enterRequestObject = new JObject ( ) ;
194
- enterRequestObject [ "element" ] = "InvalidElementId" ;
195
- HttpWebResponse response = SendTouchPost ( touchType , enterRequestObject ) ;
196
- Assert . Fail ( "Exception should have been thrown because there is no such element" ) ;
197
- }
198
-
199
- public void ErrorTouchInvalidArguments ( string touchType )
200
- {
201
- JObject enterRequestObject = new JObject ( ) ;
202
- HttpWebResponse response = SendTouchPost ( touchType , enterRequestObject ) ;
203
- session . Close ( ) ;
204
- Assert . Fail ( "Exception should have been thrown because there are insufficient arguments" ) ;
205
- }
206
130
}
207
131
}
0 commit comments