简体   繁体   English

如何使用 API 调用实现 XCUITest

[英]How to implement XCUITest with API Calls

I am new to XCUITest framework.我是 XCUITest 框架的新手。 I need to call an API https://restcountries.eu/rest/v2/all getting list of countries and showing in UITableView now as user will click on any cell based on country name next screen will have country name and country flag every thing is working fine now I wanted to implement XCUITest for that I have added function我需要调用 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()
           }
      }
}

at app.launch() app is getting crashed在 app.launch() 应用程序正在崩溃

You can make requests with URLSession and access data with JSONEncoder.您可以使用 URLSession 发出请求并使用 JSONEncoder 访问数据。


If you want to test your table (while changing its data), use unit tests.如果您想测试您的表(同时更改其数据),请使用单元测试。 If you want to test how interaction with this table affects other UI Elements, use UI tests.如果您想测试与此表的交互如何影响其他 UI 元素,请使用 UI 测试。 For a better understanding about testing in Xcode watch these videos:为了更好地了解 Xcode 中的测试,请观看以下视频:


You did not provide the error text of app launching crash, but I think you tried to use XCTest UI testing APIs in a unit test target.您没有提供应用程序启动崩溃的错误文本,但我认为您尝试在单元测试目标中使用 XCTest UI 测试 API。

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

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