Skip to content

Instantly share code, notes, and snippets.

@colinfwren
Created December 8, 2024 21:22
Show Gist options
  • Save colinfwren/0ce7766b017d0a3e1e3d50bbdfbb15db to your computer and use it in GitHub Desktop.
Save colinfwren/0ce7766b017d0a3e1e3d50bbdfbb15db to your computer and use it in GitHub Desktop.
Nesting POMs for things like tabs
import XCTest
class tab1POM {
let app: XCUIApplication
init(app: XCUIApplication) {
self.app = app
}
func pressTheButton() {
self.app.buttons["Button on first tab"].tap()
XCTAssertTrue(app.staticTexts["Button pressed"].exists)
}
}
class tab2POM {
let app: XCUIApplication
init(app: XCUIApplication) {
self.app = app
}
func pressTheButton() {
self.app.buttons["Button on second tab"].tap()
XCTAssertTrue(app.staticTexts["Button pressed"].exists)
}
}
class ExamplePOM {
let app: XCUIApplication
let tab1Pom: Tab1POM
let tab2Pom: Tab2POM
init(app: XCUIApplication) {
self.app = app
self.tab1Pom = Tab1POM(app: app)
self.tab2Pom = Tab2POM(app: app)
}
func pressTheButtonOnFirstTab() {
self.app.buttons["Tab 1"].tap()
self.tab1Pom.pressTheButton()
}
func pressTheButtonOnSecondTab() {
self.app.buttons["Tab 2"].tap()
self.tab1Pom.pressTheButton()
}
}
final class ATest: XCTestCase {
var app: XCUIApplication!
var examplePom: ExamplePOM!
override func setUpWithError() throws {
continueAfterFailure = false
app = XCUIApplication()
app.launch()
examplePom = ExamplePOM(app: app)
}
@MainActor
func testAThing() {
examplePom.pressTheButtonOnFirstTab()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment