title: Xcode7 | Xcode UI Tests | How to handle location service alert?
body: <p>I am writing UI Test Cases for one one of my app using the XCUIApplication, XCUIElement and XCUIElementQuery introduced in Xcode7/iOS 9.</p>
  
  <p>I have hit a road block. One of the screens in test case requires iOS's Location Services. As expected the user is prompted about allowing use of location service with alert titled: <code>Allow “App name” to access your location while you use the app?</code> with <code>Allow</code> &amp; <code>Don't Allow</code> buttons. </p>
  
  <p>Problem is or so it seems that since the alert is presented by OS itself it is not present in Application's element sub-tree.</p>
  
  <p>I have logged following:</p>
  
  <pre><code>print("XYZ:\(app.alerts.count)")//0
  var existence = app.staticTexts["Allow “App Name” to access your location while you use the app?"].exists
  print("XYZ:\(existence)")//false
  existence  = app.buttons["Allow"].exists
  print("XYZ:\(existence)") //false
  </code></pre>
  
  <p>Even UI recording generated similar code:</p>
  
  <pre><code>XCUIApplication().alerts["Allow “App Name” to access your location while you use the app?"].collectionViews.buttons["Allow"].tap()
  </code></pre>
  
  <p>I have not found any API that can get me past this problem. For example:</p>
  
  <ul>
  <li>Tap at a position on the screen</li>
  <li>Get alerts outside the app</li>
  </ul>
  
  <p>So how can I get past this? Is there a way to configure Test Targets so that Location Service Authorization is not required.</p>