繁体   English   中英

如何使用 API 调用实现 XCUITest

[英]How to implement XCUITest with API Calls

我是 XCUITest 框架的新手。 我需要调用 API https://restcountries.eu/rest/v2/all获取国家列表并显示在 UITableView 上,因为用户将在下一个国家/地区名称上单击任何基于国家/地区的标志现在工作正常我想实现 XCUITest 为此我添加了 function

 [![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() 应用程序正在崩溃

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


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


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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM