【问题标题】:iOS Automation - Selecting a photo from Camera RolliOS 自动化 - 从相机胶卷中选择一张照片
【发布时间】:2018-02-16 08:34:50
【问题描述】:

我正在 XCode 中编写 UI 自动化测试,需要从我的应用程序中弹出的相机胶卷屏幕中选择一张照片。我在网上查看,但似乎找不到有关如何执行此操作的任何信息。有谁知道这是否可行?

【问题讨论】:

标签: ios xcode automation xctest xcuitest


【解决方案1】:

另一个 StackOverflow 问题的代码不起作用,所以我自己想通了。点击照片本身不起作用,但点击照片的坐标位置似乎可以正常工作。

let image = Page.app.collectionViews.children(matching: .cell).element(boundBy: 0)
let coord:XCUICoordinate = image.coordinate(withNormalizedOffset: CGVector.init(dx: 0.0, dy: 0.0))
coord.tap()

【讨论】:

  • 您的答案中的 Page 对象是什么?
  • 这很好用!因为我在用于测试的设备上有很多照片,所以我需要再次点按两次。
【解决方案2】:

用于选择图像的 Swift 4+ 自动化

//Title For Photos
XCTAssertTrue(XCUIApplication().navigationBars.otherElements["Photos"].waitForExistence(timeout: 5))
        
//Check if Moments is visible on the view
XCTAssertTrue(XCUIApplication().otherElements.tables.cells["Moments"].waitForExistence(timeout: 5))
        
//Click on Moments to see the image collection list
XCUIApplication().otherElements.tables.cells["Moments"].tap()
        
//Checking for "Photo, Portrait, August 08, 2012, 11:29 PM" exist
XCTAssertTrue(XCUIApplication().otherElements.collectionViews.cells["Photo, Landscape, August 08, 2012, 8:52 PM"].waitForExistence(timeout: 5))
        
//Clicking on "Photo, Portrait, August 08, 2012, 11:29 PM"
XCUIApplication().otherElements.collectionViews.cells["Photo, Landscape, August 08, 2012, 8:52 PM"].tap()

【讨论】:

  • 你的问题是什么?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-11-26
  • 1970-01-01
  • 1970-01-01
  • 2016-07-04
相关资源
最近更新 更多