@@ -28,7 +28,7 @@ class SimpleLocationAppUITests: XCTestCase {
2828 }
2929
3030 func testMexicoLocation( ) {
31- let SauceEUDefaultLocation = " 52.535 , 13.264 "
31+ let SauceEUDefaultLocation = " 52.527 , 13.395 "
3232 let SauceUSDefaultLocation = " 37.78, -122.397 "
3333 let SauceUSOtherDefaultLocation = " 37.39, -121.962 "
3434 let UITestDefaultLocation = " 19.435, -99.136 "
@@ -65,7 +65,7 @@ class SimpleLocationAppUITests: XCTestCase {
6565 }
6666 XCTAssertTrue ( locationTextElement. exists, " locationText does not exist " )
6767 NSLog ( " \( locationTextElement. debugDescription) " )
68- var locationText = locationTextElement. value as! String
68+ let locationText = locationTextElement. value
6969
7070 //Take screenshot
7171 self . takeScreenshot ( )
@@ -75,57 +75,19 @@ class SimpleLocationAppUITests: XCTestCase {
7575 NSLog ( " SauceUSOtherDefaultLocation %@ " , SauceUSOtherDefaultLocation)
7676 NSLog ( " UITestDefaultLocation %@ " , UITestDefaultLocation)
7777
78- var assertMessage = String ( format: " Current Location %@ is not equal to expected locations. " , locationText)
79- var locationConditional = SauceEUDefaultLocation == locationText || SauceUSDefaultLocation == locationText || UITestDefaultLocation == locationText || SauceUSOtherDefaultLocation == locationText
80- takeScreenshot ( )
81-
82- if ( !locationConditional) { //Run everything again
83-
84- addUIInterruptionMonitor ( withDescription: " Location Services " ) { ( alert) -> Bool in
85- let alertQuery = alert. buttons. matching ( NSPredicate ( format: " label BEGINSWITH %@ " , " Allow " ) )
86- if ( alertQuery. count > 0 ) {
87- let alertElement = alertQuery. element ( boundBy: 0 )
88- let isAlertPresent = alertElement. waitForExistence ( timeout: 10 )
89-
90- if ( isAlertPresent) {
91- self . takeScreenshot ( )
92- alertElement. tap ( )
93- }
94- }
95- return true
96- }
97-
98- XCUIApplication ( ) . tap ( ) // need to interact with the app again for the handler to fire
99-
100-
101- // Uncomment to print Application's element hierarchy
102- NSLog ( " \( app. debugDescription) " )
103- var locationTextElement = app. otherElements [ " locationText " ]
104-
105- // Needed for iOS 13 compatability
106- if ( !locationTextElement. exists) {
107- locationTextElement = app. textViews. element ( matching: NSPredicate ( format: " identifier = %@ " , " locationText " ) )
108- self . takeScreenshot ( )
78+ if let location = locationText {
79+ let locationTextString = location as! String
80+ let assertMessage = String ( format: " Current Location %@ is not equal to expected locations. " , locationTextString)
81+ let locationConditional = SauceEUDefaultLocation == locationTextString || SauceUSDefaultLocation == locationTextString || UITestDefaultLocation == locationTextString || SauceUSOtherDefaultLocation == locationTextString
10982
110- }
111- XCTAssertTrue ( locationTextElement. exists, " locationText does not exist " )
112- NSLog ( " \( locationTextElement. debugDescription) " )
113- locationText = locationTextElement. value as! String
114-
115- self . takeScreenshot ( )
83+ XCTAssert ( locationConditional, assertMessage)
84+ }
11685
117- NSLog ( " SauceEUDefaultLocation: %@ " , SauceEUDefaultLocation)
118- NSLog ( " SauceUSDefaultLocation %@ " , SauceUSDefaultLocation)
119- NSLog ( " SauceUSOtherDefaultLocation %@ " , SauceUSOtherDefaultLocation)
120- NSLog ( " UITestDefaultLocation %@ " , UITestDefaultLocation)
121-
122- assertMessage = String ( format: " Current Location %@ is not equal to expected locations. " , locationText)
123- locationConditional = SauceEUDefaultLocation == locationText || SauceUSDefaultLocation == locationText || UITestDefaultLocation == locationText || SauceUSOtherDefaultLocation == locationText
124- self . takeScreenshot ( )
86+ else {
87+ XCTFail ( " locationText was nil! " )
12588 }
12689
12790
128- XCTAssert ( locationConditional, assertMessage)
12991
13092
13193 }
0 commit comments