XCUITest - 打开 iOS 设置并更改 date/time
XCUITest - Open iOS settings and change date/time
是否可以在 UI 测试中更改设备的 date/time 设置?
我可以打开“设置”应用,导航到“常规”>“日期和时间”,然后关闭 "Set Automatically" 按钮。但是,我找不到更改 pickerWheel 值的方法。
let settingsApp = XCUIApplication(bundleIdentifier: "com.apple.Preferences")
settingsApp.launch()
settingsApp.tables.cells["General"].tap()
settingsApp.tables.cells["Date & Time"].tap()
settingsApp.switches["Set Automatically"].tap()
// Change pickerWheel value?
有什么想法吗?有可能吗?
谢谢!
我用下面的代码来做:
// Here I format the Time to get the right format
var decomposedDateTime: [String] = Formatters.timeFormatter.string(from: date)
.replacingOccurrences(of: ":", with: " ")
.split(separator: " ")
.map({String([=10=])})
// Then I format the Day and add it at first
decomposedDateTime.insert(Formatters.datePickerFormatter.string(from: date), at: 0)
// Update picker wheels accordingly
for i in 0...(decomposedDateTime.count - 1) {
settingsApp.pickerWheels.element(boundBy: i).adjust(toPickerWheelValue: decomposedDateTime[i])
}
这是我的格式化程序
static let timeFormatter: DateFormatter = {
let f = DateFormatter()
f.dateStyle = .none
f.timeStyle = .short
return f
}()
static let datePickerFormatter: DateFormatter = {
let f = DateFormatter()
f.dateStyle = .medium
f.dateFormat = "MMM d"
return f
}()
是否可以在 UI 测试中更改设备的 date/time 设置?
我可以打开“设置”应用,导航到“常规”>“日期和时间”,然后关闭 "Set Automatically" 按钮。但是,我找不到更改 pickerWheel 值的方法。
let settingsApp = XCUIApplication(bundleIdentifier: "com.apple.Preferences")
settingsApp.launch()
settingsApp.tables.cells["General"].tap()
settingsApp.tables.cells["Date & Time"].tap()
settingsApp.switches["Set Automatically"].tap()
// Change pickerWheel value?
有什么想法吗?有可能吗?
谢谢!
我用下面的代码来做:
// Here I format the Time to get the right format
var decomposedDateTime: [String] = Formatters.timeFormatter.string(from: date)
.replacingOccurrences(of: ":", with: " ")
.split(separator: " ")
.map({String([=10=])})
// Then I format the Day and add it at first
decomposedDateTime.insert(Formatters.datePickerFormatter.string(from: date), at: 0)
// Update picker wheels accordingly
for i in 0...(decomposedDateTime.count - 1) {
settingsApp.pickerWheels.element(boundBy: i).adjust(toPickerWheelValue: decomposedDateTime[i])
}
这是我的格式化程序
static let timeFormatter: DateFormatter = {
let f = DateFormatter()
f.dateStyle = .none
f.timeStyle = .short
return f
}()
static let datePickerFormatter: DateFormatter = {
let f = DateFormatter()
f.dateStyle = .medium
f.dateFormat = "MMM d"
return f
}()