Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/94.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何编写UI测试来测试单击UITableView中的第一个单元格时图像是否存在?_Ios_Swift_Uitest - Fatal编程技术网

Ios 如何编写UI测试来测试单击UITableView中的第一个单元格时图像是否存在?

Ios 如何编写UI测试来测试单击UITableView中的第一个单元格时图像是否存在?,ios,swift,uitest,Ios,Swift,Uitest,在我的故事板中有一个UITableView。它包含5个表视图单元格。 单击第一个单元格时,它将转到第二个UIView并显示相应的图像。如何对UITest部分进行编码以测试单击第一个单元格时图像是否显示?XCode 7有一个神奇的部分-UIRecording 首先选择testCase,然后像Gif一样开始录制 然后你会看到,为你创建UITest代码,在我的情况下,我得到 let app = XCUIApplication() app.tables/*@START_MENU_TOKEN@*/

在我的故事板中有一个
UITableView
。它包含5个表视图单元格。
单击第一个单元格时,它将转到第二个UIView并显示相应的图像。如何对UITest部分进行编码以测试单击第一个单元格时图像是否显示?

XCode 7有一个神奇的部分-UIRecording

首先选择testCase,然后像Gif一样开始录制

然后你会看到,为你创建UITest代码,在我的情况下,我得到

  let app = XCUIApplication()
  app.tables/*@START_MENU_TOKEN@*/.staticTexts["Hello"]/*[[".cells.staticTexts[\"Hello\"]",".staticTexts[\"Hello\"]"],[[[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/.tap()
  app.otherElements.containingType(.NavigationBar, identifier:"UIView").childrenMatchingType(.Other).element.childrenMatchingType(.Other).element.childrenMatchingType(.Other).element.childrenMatchingType(.Image).element.tap()
那么,我只需要一点零钱

    let app = XCUIApplication()
    app.tables.cells.elementBoundByIndex(0).tap()
    let imageView =  app.otherElements.containingType(.NavigationBar, identifier:"UIView").childrenMatchingType(.Other).element.childrenMatchingType(.Other).element.childrenMatchingType(.Other).element.childrenMatchingType(.Image)
    let count = imageView.images.count
    XCTAssert(count != 0)
因此,主要有两个步骤

  • 让我们为您创建代码
  • 进行一些更改,例如添加断言、按索引查询等
然后跑