kif-framework / KIF

Keep It Functional - An iOS Functional Testing Framework
Other
6.2k stars 909 forks source link

[Question/Help] How to write E2E UI Integrations tests? #1282

Closed mahabaleshwarhnr closed 1 month ago

mahabaleshwarhnr commented 1 year ago

Hello Folks I am exploring KIF for one of my project. Thanks for interesting library. I have read the readme and able to add KIF SPM in my project. I am facing some challenges while writing end to end Integration tests. I mean fetching data from an API to asserting the same after it displaying in UI.

func testShouldDisplayBlogList() throws {
        let tableView = tester().waitForView(withAccessibilityIdentifier: "blogPostTableView") as! UITableView
        let cell = tester().waitForCell(at: IndexPath(row: 0, section: 0), inTableViewWithAccessibilityIdentifier: "blogPostTableView", at: .top)
        let contentConfiguration = cell!.contentConfiguration as? UIListContentConfiguration
        XCTAssertEqual(tableView.numberOfSections, 1)
        XCTAssertEqual(tableView.numberOfRows(inSection: 0), 100)
        XCTAssertEqual(contentConfiguration?.text, "Hello World")
        XCTAssertNotNil(contentConfiguration?.secondaryText, "Lorem")
  }
mahabaleshwarhnr commented 1 year ago

@dostrander @phatmann can anyone help me here?

dostrander commented 1 year ago

@mahabaleshwarhnr

I find difficulty in mocking object before invoking test or beforeAll. is there any way to pass launching arguments like in XCUITests?

There isn't a specific way for launch arguments baked into KIF you will need to find a way to either create your own variable that is only in KIF tests or some other way.

is there any detail document on each API level? For example I want to know more about absence view.

The header docs for each API is the best documentation we have here. In general I think they are pretty good but the next best is the code itself.

How to wait for tableview until it get loaded? For example I want to test number of rows and sections. I tried below approach and works fine. Is there any better approach?

I think that's fine. You could also use the delegate if you'd like but either way works. In general though we advise to just "wait" for an accessibility label/value and up the timeout for that call if needed

How to disable animation in KIF

No specific way to KIF, you could use [UIView setAnimationsEnabled:NO]; but that messes up some code paths like viewWillAppear:animated which will pass in NO for the animated variable