Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This is an example of how to use XCTContext.runActivity method in page object patter for XCUITest. This allows to get nice reports with Allure in the future.
class LoginPage {
func login(with userName: String, and password: String): SomeOtherPage {
return XCTContext.runActivity("Login as existing user") {
this.enter(userName: userName)
this.enter(password: password)
this.submit()
return new SomeOtherPage(app: this.app);
}
}
func enter(userName: String): LoginPage {
return XCTContext.runActivity("Enter '\(userName)' user name) {
this.userNameField.sendKeys(userName)
return this;
})
}
func enter(password: String): LoginPage {
return XCTContext.runActivity("Enter '\(password)' password) {
this.passwordField.sendKeys(password)
return this;
})
}
func submit() {
XCTContext.runActivity("Tap 'Submit' button") {
this.submitButton.tap()
})
}
}
class LoginTest {
func testSuccesfullLogin() {
let user = XCTContext.runActivity("Given a new user", {
return UserGenerator.generate(.newUser)
})
let someOtherPage = XCTContext.runActivity("When i enter valid credentials and submit them", {
return new LoginPage().login(with: user.userName, and: user.password)
})
XCTContext.runActivity("I expect to be logged in and see 'SomeOtherPage' ", {
XCTAssertTrue(someOtherPage.title.exists)
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.