Skip to content

Commit

Permalink
updated signature for element exists to configure timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladimir Espinola committed Jun 21, 2024
1 parent 9bc2e76 commit a581154
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
3 changes: 2 additions & 1 deletion Example/CreativeUITest/CreativeUITest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ final class CreativeUITest: XCTestCase, BaseXCTestCase {
clearCookies()
resetUserDefaults()

XCUIApplication().terminate()
XCUIApplication().activate()

super.tearDown()
}
Expand Down Expand Up @@ -65,6 +65,7 @@ final class CreativeUITest: XCTestCase, BaseXCTestCase {
HomePage.tapOnPushMeToCreative()

CreativePage
.addDelay(seconds: 1)
.tapOnPrivacyLink()
.addDelay(seconds: 5)

Expand Down
19 changes: 9 additions & 10 deletions Example/CreativeUITest/Extensions/XCUIElement+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,24 @@

import XCTest

enum Timeout {
static var `default`: TimeInterval { 10 }
static var max: TimeInterval { 15 }
}

extension XCUIElement {
/// Verify element existence and then proceed with tapping on it
func tapOnElement() {
guard elementExists() else {
func tapOnElement(timeout: TimeInterval = Timeout.default) {
guard elementExists(timeout: timeout) else {
XCTFail("\(description) does not exists")
return
}
tap()
}

/// Verify element existence on the app view hierarchy
func elementExists() -> Bool {
elementExists(timeout: 15)
func elementExists(timeout: TimeInterval = Timeout.default) -> Bool {
waitForExistence(timeout: timeout)
}

func fillTextField(_ text: String) {
Expand All @@ -31,9 +36,3 @@ extension XCUIElement {
typeText(text)
}
}

fileprivate extension XCUIElement {
func elementExists(timeout: TimeInterval) -> Bool {
waitForExistence(timeout: timeout)
}
}
6 changes: 3 additions & 3 deletions Example/CreativeUITest/Pages/CreativePage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ struct CreativePage: Page {

@discardableResult
static func tapOnCloseCreative() -> Self.Type {
closeButton.tapOnElement()
closeButton.tapOnElement(timeout: Timeout.max)
return self
}

@discardableResult
static func fillEmailInput(text: String) -> Self.Type {
emailTextField.tapOnElement()
emailTextField.tapOnElement(timeout: Timeout.max)
emailTextField.fillTextField(text)
return self
}
Expand Down Expand Up @@ -49,7 +49,7 @@ struct CreativePage: Page {

@discardableResult
static func verifyPrivacyLinkExists() -> Self.Type {
XCTAssertTrue(privacyLink.elementExists())
XCTAssertTrue(privacyLink.elementExists(timeout: Timeout.max))
return self
}
}
Expand Down
2 changes: 1 addition & 1 deletion Example/CreativeUITest/Pages/SMSPage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ struct SMSPage: Page {

@discardableResult
static func verifyPrefilledMessage(message: String) -> Self.Type {
if okButton.elementExists() {
if okButton.elementExists(timeout: 5) {
okButton.tapOnElement()
}

Expand Down

0 comments on commit a581154

Please sign in to comment.