【问题标题】:How to implement XCUITest with API Calls如何使用 API 调用实现 XCUITest
【发布时间】:2020-07-14 18:30:52
【问题描述】:

我是 XCUITest 框架的新手。我需要调用 API https://restcountries.eu/rest/v2/all 获取国家列表并现在显示在 UITableView 中,因为用户将单击基于国家名称的任何单元格下一个屏幕将具有国家名称和国家标志,一切正常现在我想实现 XCUITest,因为我已经添加了功能

 [![enter image description here][1]][1]

func testTheCountryListAndAllScreen() {
app.launch()
let countryListTableView = self.app.tables["CountryList"]
XCTAssertTrue(countryListTableView.exists, "Country list have data")
let countryListCell = countryListTableView.cells
 if countryListCell.count > 0 {
     for cell in 0..<countryListCell.count {
          let countryCell = countryListCell.element(boundBy: cell)
           countryCell.tap()
           self.app.buttons.staticTexts["Move to info page"].tap()
           self.app.navigationBars.buttons.element(boundBy: 0).tap()
           self.app.navigationBars.buttons.element(boundBy: 0).tap()
           }
      }
}

在 app.launch() 应用程序正在崩溃

【问题讨论】:

    标签: ios swift xcode-ui-testing xcuitest


    【解决方案1】:

    您可以使用 URLSession 发出请求并使用 JSONEncoder 访问数据。


    如果您想测试您的表(同时更改其数据),请使用单元测试。如果您想测试与此表的交互如何影响其他 UI 元素,请使用 UI 测试。要更好地了解 Xcode 中的测试,请观看以下视频:


    您没有提供应用启动崩溃的错误文本,但我认为您尝试在单元测试目标中使用 XCTest UI 测试 API。

    【讨论】:

    • 我在 testTheCountryListAndAllScreen() 线程 1 中收到此错误:致命错误:在隐式展开可选值时意外发现 nil
    • 我已经进行了 api 调用并在 Tableview 中显示了它,现在我必须为它做 UITesting
    猜你喜欢
    • 1970-01-01
    • 2017-11-22
    • 2018-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-22
    • 2018-08-12
    • 2017-02-01
    相关资源
    最近更新 更多