【问题标题】:How to rotate simulator using Swift code in xcode ui test如何在 xcode ui 测试中使用 Swift 代码旋转模拟器
【发布时间】:2017-02-03 18:44:44
【问题描述】:

我有一个场景,我必须在进行 xcode ui 测试时旋转我的模拟器。

为了旋转模拟器,我使用下面的代码

UIDevice.currentDevice().orientation
let value = UIInterfaceOrientation.LandscapeLeft.rawValue
UIDevice.currentDevice().setValue(value, forKey: "orientation")

但它不起作用。

在 xcode ui 测试中使用 Swift 代码旋转模拟器有什么解决方案吗?

【问题讨论】:

标签: ios swift xcode xctest xcode-ui-testing


【解决方案1】:

你试过了吗?

斯威夫特 2.x

XCUIDevice.sharedDevice().orientation = .LandscapeLeft  
XCUIDevice.sharedDevice().orientation = .Portrait  

斯威夫特 3.0

XCUIDevice.shared().orientation = .landscapeLeft
XCUIDevice.shared().orientation = .portrait

斯威夫特 5.x

XCUIDevice.shared.orientation = .landscapeLeft
XCUIDevice.shared.orientation = .portrait

【讨论】:

  • Np 很高兴为您提供帮助 @user6633897
  • @Rashwan 如果我想在控制台中打印模拟器的状态?
  • 意味着如果我将模拟器旋转到纵向模式,它将打印纵向以及 lndscape
  • 试试print(XCUIDevice.shared().orientation)@iDeveloper
【解决方案2】:

斯威夫特 4:

XCUIDevice.shared.orientation = .landscapeLeft
XCUIDevice.shared.orientation = .portrait

【讨论】:

  • @BijenderSinghShekhawat 是模拟设备,需要导入XCTest
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-01-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-08-14
相关资源
最近更新 更多