简体   繁体   中英

How to implement XCUITest with API Calls

I am new to XCUITest framework. 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

 [![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

You can make requests with URLSession and access data with 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. For a better understanding about testing in Xcode watch these videos:


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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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