Skip to content

Instantly share code, notes, and snippets.

@azakordonets
Created April 25, 2018 14:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save azakordonets/0dd3d2268bf3eba1675f343442bb887e to your computer and use it in GitHub Desktop.
Save azakordonets/0dd3d2268bf3eba1675f343442bb887e to your computer and use it in GitHub Desktop.
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