Created
April 25, 2018 14:42
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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