2017-01-14 3 views
0

나는 tableView 및 상세 vc와 함께 간단한 프로젝트를 가지고 있습니다. tableView에는 "cell (n)"텍스트가있는 20 개의 행이 표시되고 상세 뷰에는 셀이 눌린 레이블이 표시됩니다. 주어진 셀에 탭이 있다고 주장하고 싶습니다. 세부적인 VC 레이블의 tableView에서 텍스트를 찾습니다. 예를 들어, "셀 3"을 포함하는 셀 3을 탭하면 하드 코딩 대신이 텍스트를 가져오고,이 텍스트를 디테일 VC에서 찾을 수 있다고 주장합니다.XCUITest 예기치 않은 동작

func testCanNavigateToDetailVCWithTheTextFromCell() { 
    let labelInTableView = app.staticTexts["cell 3"] 

    labelInTableView.tap() 

    let labelInDetailVC = app.staticTexts[labelInTableView.label] 
    XCTAssertTrue(labelInDetailVC.exists) 
} 

이렇게 보입니다. 하지만 난이 작업을 수행 할 수 :이 문제 here

답변

1

으로 프로젝트를 설정

func testCanNavigateToDetailVCWithTheTextFromCellV2() { 
    let cell = app.tables.element.cells.element(boundBy: 3) //Get the third cell of the unique tableView 

    cell.tap() 

    let textFromPreviousCell = cell.staticTexts.element(boundBy: 0).label //Since is a "Basic" cell it only has one label. 
    //I will also want to set an accessilibtyIdentifier to the label and access it via cell.staticTexts["id"].label 
    let labelInDetailVC = app.staticTexts[textFromPreviousCell] 
    XCTAssertTrue(labelInDetailVC.exists) 
} 

문제는 당신이 그것을 도청 한 후 셀의 텍스트를 얻어내는 것이 목적입니다. 즉, 셀이 더 이상 화면에 표시되지 않습니다 (새 화면이 나타남). 라인 cell.tap()let textFromPreviousCell = cell.staticTexts.element(boundBy: 0).label의 순서를 변경하기 만하면됩니다. 아래 새 기능을 참조하십시오.

func testCanNavigateToDetailVCWithTheTextFromCellV2() { 
    let cell = app.tables.element.cells.element(boundBy: 3) //Get the third cell of the unique tableView 

    let textFromPreviousCell = cell.staticTexts.element(boundBy: 0).label //Since is a "Basic" cell it only has one label. 

    cell.tap() 

    let labelInDetailVC = app.staticTexts[textFromPreviousCell] 
    XCTAssertTrue(labelInDetailVC.exists) 
}