You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Fastlane/CircleCI上UI测试失败:新模拟器未设置定位

Fixing Location Update Failure in UI Tests on Fastlane/CircleCI

I’ve run into this exact frustrating issue before—when running UI tests via Fastlane on CircleCI, the fresh simulator instance spun up by Fastlane completely ignores the default location set in your Xcode schemes. This leaves your app stuck waiting for a location update right after you grant permissions, killing your test run. Here’s how I solved it:

Root Cause Breakdown

The default location you’ve configured in both your App and UI Test targets’ schemes only works when launching the simulator directly through the Xcode GUI. When Fastlane boots up a simulator via the command line, those scheme-level settings don’t carry over. The simulator starts with no location data at all, so your app never gets the trigger to move to the next screen.

Practical Solutions

1. Use Fastlane’s Built-in simulator_control Action

Fastlane has a dedicated action to set the simulator’s location explicitly. Drop this into your lane before running your UI tests:

simulator_control(
  command: "set_location",
  latitude: 37.7749, # Swap with your desired latitude
  longitude: -122.4194 # Swap with your desired longitude
)

This targets the exact simulator instance Fastlane is using, ensuring your app receives the location data it needs to proceed.

2. Set Location via Xcode Command Line Tools

If you’d rather avoid Fastlane-specific actions, you can run a shell command pre-test to set the location. First, grab your simulator’s UDID (Fastlane outputs this during setup, or you can use xcrun simctl list to find it), then run:

xcrun simctl location <SIMULATOR_UDID> set <LATITUDE> <LONGITUDE>

Example:

xcrun simctl location B0123456-7890-ABCD-EFGH-IJKLMNOPQRST set 37.7749 -122.4194

3. Hardcode Location Setup in Your UI Test Code

For the most reliable, environment-agnostic fix, set the location directly in your UI test class’s setup method. This ensures the location is set as soon as the app launches, no matter how the simulator is started:

import XCTest
import CoreLocation

class YourAppUITests: XCTestCase {
    override func setUp() {
        super.setUp()
        let app = XCUIApplication()
        app.launch()
        
        // Set your desired test location
        let testCoordinate = CLLocationCoordinate2D(latitude: 37.7749, longitude: -122.4194)
        app.setLocation(testCoordinate)
    }
}

Quick Verification

After implementing any of these fixes, rerun your Fastlane lane on CircleCI. Your app should receive the location update immediately after you grant permissions, letting the test flow to the next screen without getting stuck.

内容的提问来源于stack exchange,提问作者Nick Locking

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 07:32:31