0

I'm new to XCUITest. I would like to get some suggestions on how to design 'page' (actually more like screen) object XCUITest.

Is there any open-source project that give samples to reference?

I'm thinking to create a screen folder to put all the screen objects there to hold methods and locators for each screen. Create a test folder to put the actual test cases. And also create a lib folder to put the common methods there.

I was wondering 2 things: 1. How XCUITest reference the files in different folders, how can one test file import methods from 2 different screen files? 2. I'm also thinking to create a data file (acting like .json file). Should I set it as .swift file? and how to make my test call that?

many thanks!

user10252638
  • 111
  • 4

1 Answers1

1
  1. You need not import files from different folders which reside in a same target. They can be used directly without importing.
  2. Refer Reading in a JSON File Using Swift to read from json files.

For page object design

AppNameUITests/Screens/Screen1.swift

class Screen1 {
    var app: XCUIApplication

    init(app: XCUIApplication) {
        self.app = app
    }

    var element1: XCUIElement {
        return app.buttons.firstMatch
    }

    var element2: [XCUIElement] {
        return app.textFields.allElementsBoundByIndex
    }

    func method1() -> Int {
        element1.click()
        return element2.count
    }
}

AppNameUITests/Tests/TestSuite1.swift

class TestSuite1: XCTestCase {

    override func setUp() {
        // launch application and pre-conditions for the test case
    }

    override func tearDown() {
        // clean up steps and terminate the application
    }

    func testMethod1() {
        let app = XCUIApplication()
        let screen1Obj = Screen1(app: app)

        XCTAssertTrue(screen1Obj.method1() == 5, "Test failed.")
    }
}