Skip to content

Commit

Permalink
rename helper classes
Browse files Browse the repository at this point in the history
  • Loading branch information
shamanec committed Aug 10, 2023
1 parent 50aebd3 commit 3215a16
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 45 deletions.
24 changes: 12 additions & 12 deletions xcuitest-sample-proj.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@
objects = {

/* Begin PBXBuildFile section */
FF4D5CB02A68033C00B52624 /* Elements.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF4D5CAF2A68033C00B52624 /* Elements.swift */; };
FF4D5CB02A68033C00B52624 /* Element.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF4D5CAF2A68033C00B52624 /* Element.swift */; };
FF79C1EC2A66F1B700BBC60A /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = FF79C1EB2A66F1B700BBC60A /* Assets.xcassets */; };
FF79C1EF2A66F1B700BBC60A /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = FF79C1EE2A66F1B700BBC60A /* Preview Assets.xcassets */; };
FF79C2032A66F1B700BBC60A /* SampleAppUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF79C2022A66F1B700BBC60A /* SampleAppUITests.swift */; };
FF79C27F2A66F3A000BBC60A /* XCUIElement+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF79C27E2A66F3A000BBC60A /* XCUIElement+Extensions.swift */; };
FF79C2812A66F45200BBC60A /* XCUIElementQuery+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF79C2802A66F45200BBC60A /* XCUIElementQuery+Extensions.swift */; };
FF79C2832A66F54E00BBC60A /* BaseTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF79C2822A66F54E00BBC60A /* BaseTest.swift */; };
FF79C2862A66F72200BBC60A /* TestConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF79C2852A66F72200BBC60A /* TestConstants.swift */; };
FF79C2892A66F9F500BBC60A /* Interactions.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF79C2882A66F9F500BBC60A /* Interactions.swift */; };
FF79C2892A66F9F500BBC60A /* Interaction.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF79C2882A66F9F500BBC60A /* Interaction.swift */; };
FF7C55402A6EF2DA00102A71 /* LaunchArgumentTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF7C553F2A6EF2DA00102A71 /* LaunchArgumentTests.swift */; };
FF844DB82A7C027C002A79EA /* App.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF844DB72A7C027C002A79EA /* App.swift */; };
FF86799B2A69699D00C4A1A7 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF86799A2A69699D00C4A1A7 /* AppDelegate.swift */; };
FF86799E2A696BDC00C4A1A7 /* CarouselItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF86799D2A696BDC00C4A1A7 /* CarouselItemView.swift */; };
FFED40FE2A714284005B0940 /* Sliders in Frameworks */ = {isa = PBXBuildFile; productRef = FFED40FD2A714284005B0940 /* Sliders */; };
FFEDF6402A7A7E1A0065A5E4 /* Alerts.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFEDF63F2A7A7E1A0065A5E4 /* Alerts.swift */; };
FFEDF6402A7A7E1A0065A5E4 /* Alert.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFEDF63F2A7A7E1A0065A5E4 /* Alert.swift */; };
FFEDF6422A7A965C0065A5E4 /* Logger.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFEDF6412A7A965C0065A5E4 /* Logger.swift */; };
FFF0348F2A6CFA6500A33E97 /* FirstScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFF0348E2A6CFA6500A33E97 /* FirstScreen.swift */; };
FFF034912A6CFA8B00A33E97 /* BaseScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFF034902A6CFA8B00A33E97 /* BaseScreen.swift */; };
Expand Down Expand Up @@ -52,7 +52,7 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
FF4D5CAF2A68033C00B52624 /* Elements.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Elements.swift; sourceTree = "<group>"; };
FF4D5CAF2A68033C00B52624 /* Element.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Element.swift; sourceTree = "<group>"; };
FF79C1E42A66F1B600BBC60A /* xcuitest-sample-proj.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "xcuitest-sample-proj.app"; sourceTree = BUILT_PRODUCTS_DIR; };
FF79C1EB2A66F1B700BBC60A /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
FF79C1EE2A66F1B700BBC60A /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
Expand All @@ -63,12 +63,12 @@
FF79C2802A66F45200BBC60A /* XCUIElementQuery+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "XCUIElementQuery+Extensions.swift"; sourceTree = "<group>"; };
FF79C2822A66F54E00BBC60A /* BaseTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseTest.swift; sourceTree = "<group>"; };
FF79C2852A66F72200BBC60A /* TestConstants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestConstants.swift; sourceTree = "<group>"; };
FF79C2882A66F9F500BBC60A /* Interactions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Interactions.swift; sourceTree = "<group>"; };
FF79C2882A66F9F500BBC60A /* Interaction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Interaction.swift; sourceTree = "<group>"; };
FF7C553F2A6EF2DA00102A71 /* LaunchArgumentTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LaunchArgumentTests.swift; sourceTree = "<group>"; };
FF844DB72A7C027C002A79EA /* App.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = App.swift; sourceTree = "<group>"; };
FF86799A2A69699D00C4A1A7 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
FF86799D2A696BDC00C4A1A7 /* CarouselItemView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CarouselItemView.swift; sourceTree = "<group>"; };
FFEDF63F2A7A7E1A0065A5E4 /* Alerts.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Alerts.swift; sourceTree = "<group>"; };
FFEDF63F2A7A7E1A0065A5E4 /* Alert.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Alert.swift; sourceTree = "<group>"; };
FFEDF6412A7A965C0065A5E4 /* Logger.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Logger.swift; sourceTree = "<group>"; };
FFF0348E2A6CFA6500A33E97 /* FirstScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FirstScreen.swift; sourceTree = "<group>"; };
FFF034902A6CFA8B00A33E97 /* BaseScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseScreen.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -192,9 +192,9 @@
FF79C2872A66F9E500BBC60A /* Helpers */ = {
isa = PBXGroup;
children = (
FF79C2882A66F9F500BBC60A /* Interactions.swift */,
FF4D5CAF2A68033C00B52624 /* Elements.swift */,
FFEDF63F2A7A7E1A0065A5E4 /* Alerts.swift */,
FF79C2882A66F9F500BBC60A /* Interaction.swift */,
FF4D5CAF2A68033C00B52624 /* Element.swift */,
FFEDF63F2A7A7E1A0065A5E4 /* Alert.swift */,
FFEDF6412A7A965C0065A5E4 /* Logger.swift */,
FF844DB72A7C027C002A79EA /* App.swift */,
);
Expand Down Expand Up @@ -376,12 +376,12 @@
buildActionMask = 2147483647;
files = (
FF79C2832A66F54E00BBC60A /* BaseTest.swift in Sources */,
FFEDF6402A7A7E1A0065A5E4 /* Alerts.swift in Sources */,
FFEDF6402A7A7E1A0065A5E4 /* Alert.swift in Sources */,
FFF034932A6CFEA200A33E97 /* SecondScreen.swift in Sources */,
FF79C2032A66F1B700BBC60A /* SampleAppUITests.swift in Sources */,
FFF034952A6D027B00A33E97 /* TabBar.swift in Sources */,
FF79C2892A66F9F500BBC60A /* Interactions.swift in Sources */,
FF4D5CB02A68033C00B52624 /* Elements.swift in Sources */,
FF79C2892A66F9F500BBC60A /* Interaction.swift in Sources */,
FF4D5CB02A68033C00B52624 /* Element.swift in Sources */,
FF844DB82A7C027C002A79EA /* App.swift in Sources */,
FFEDF6422A7A965C0065A5E4 /* Logger.swift in Sources */,
FFF0349B2A6D227100A33E97 /* XCUIApplication+Extensions.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import XCTest

class Alerts {
class Alert {
private static let app = BaseTest().getApp()
private static let springboard = BaseTest().getSpringboardApp()

Expand Down Expand Up @@ -35,7 +35,7 @@ class Alerts {

/// Handle application alert by element and targetting specific button
static func handleAppAlert(_ alert: XCUIElement, _ button: String) {
XCTAssertTrue(Elements.waitForElement(alert, TestConstants.Timeout.medium), "Alert element was not found")
XCTAssertTrue(Element.waitForElement(alert, TestConstants.Timeout.medium), "Alert element was not found")
var alertButton: XCUIElement
if button == "" {
alertButton = alert.buttons.firstMatch
Expand All @@ -45,7 +45,7 @@ class Alerts {
XCTAssertTrue(alertButton.exists, "No button with identifier: `\(button)` was found in the presented alert")
}
alertButton.tap()
Elements.waitForElementExistence(alert, TestConstants.Timeout.veryShort, false)
Element.waitForElementExistence(alert, TestConstants.Timeout.veryShort, false)
}

// MARK: - System alerts handling
Expand Down Expand Up @@ -75,7 +75,7 @@ class Alerts {

/// Handle system alert by element and targetting specific button
static func handleSystemAlert(_ alert: XCUIElement, _ button: String) {
Elements.waitForElementExistence(alert, TestConstants.Timeout.short, true)
Element.waitForElementExistence(alert, TestConstants.Timeout.short, true)
var alertButton: XCUIElement
if button == "" {
alertButton = alert.buttons.firstMatch
Expand All @@ -85,6 +85,6 @@ class Alerts {
XCTAssertTrue(alertButton.exists, "No button with identifier: `\(button)` was found in the presented alert")
}
alertButton.tap()
Elements.waitForElementExistence(alertButton, TestConstants.Timeout.veryShort, false)
Element.waitForElementExistence(alertButton, TestConstants.Timeout.veryShort, false)
}
}
20 changes: 10 additions & 10 deletions xcuitest-sample-projUITests/Helpers/App.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class App {
/// Put the AUT in the background
static func background() {
Logger.log("Putting application in the background")
Interactions.pressHomeButton()
Interaction.pressHomeButton()
// This assert did not work, probably I haven't coded the sample app properly
// But theoretically should work
//XCTAssert(app.wait(for: .runningBackground, timeout: TestConstants.Timeout.medium), "App was not put in the background")
Expand Down Expand Up @@ -60,31 +60,31 @@ class App {
let appIcon = springboard.icons[appName]

// Go to the initial springboard screen
Interactions.pressHomeButton()
Interaction.pressHomeButton()

// Wait for the Settings app icon to appear before swiping to search for the AUT
let settingsIcon = springboard.icons["Settings"]
if Elements.waitForElement(settingsIcon, 2) {
if Element.waitForElement(settingsIcon, 2) {
// Sleep for half a second after finding the settings button because sometimes it swipes before finishing transition to initial springboard screen
usleep(500_000) // 0.5 seconds
Interactions.performSwipeUntil(springboard, .left, 2, until: appIcon.exists && appIcon.isHittable)
Interaction.performSwipeUntil(springboard, .left, 2, until: appIcon.exists && appIcon.isHittable)
}
appIcon.press(forDuration: TestConstants.Timeout.veryShort)

let editHomeScreenAlert = springboard.alerts["Edit Home Screens"]
if Elements.waitForElement(editHomeScreenAlert, TestConstants.Timeout.second) {
Alerts.handleSystemAlert(editHomeScreenAlert, "OK")
if Element.waitForElement(editHomeScreenAlert, TestConstants.Timeout.second) {
Alert.handleSystemAlert(editHomeScreenAlert, "OK")
}

let deleteAppButton = springboard.icons[appName].buttons["DeleteButton"]
if Elements.waitForElement(deleteAppButton, TestConstants.Timeout.short) {
if Element.waitForElement(deleteAppButton, TestConstants.Timeout.short) {
deleteAppButton.tap()
} else {
XCTFail("Delete application button did not appear in 5 seconds")
}

Alerts.handleSystemAlert("Remove “\(appName)”?", "Delete App")
Alerts.handleSystemAlert("Delete “\(appName)”?", "Delete")
Interactions.pressHomeButton()
Alert.handleSystemAlert("Remove “\(appName)”?", "Delete App")
Alert.handleSystemAlert("Delete “\(appName)”?", "Delete")
Interaction.pressHomeButton()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import XCTest

class Elements {
class Element {
/// Validate the relative position of the first element to the second element
///
/// - Parameters:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import XCTest

class Interactions {
class Interaction {
/// Press the device home button
static func pressHomeButton() {
XCUIDevice.shared.press(.home)
Expand Down
38 changes: 22 additions & 16 deletions xcuitest-sample-projUITests/SampleAppUITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@ final class SampleAppUITests: BaseTest {
let thirdScreen = ThirdScreen()

func testGentleSwipeUntil() {
Interactions.performGentleSwipeUntil(firstScreen.carousel, .left, 5, until: firstScreen.carouselItems.element(matching: NSPredicate(format: "label CONTAINS[c] 'Item 10'")).exists)
Interaction.performGentleSwipeUntil(firstScreen.carousel, .left, 5, until: firstScreen.carouselItems.element(matching: NSPredicate(format: "label CONTAINS[c] 'Item 10'")).exists)
}

func testGenericSwipeUntil() {
Interactions.performSwipeUntil(firstScreen.carousel, .left, 3, until: firstScreen.carouselItems["Item 10"].exists)
Interaction.performSwipeUntil(firstScreen.carousel, .left, 3, until: firstScreen.carouselItems["Item 10"].exists)
}

func testElementToElementPositionPass() {
// This should pass
Elements.validateElementToElementPosition(firstScreen.carouselItems["Item 2"], firstScreen.carouselItems["Item 3"], .leftOf)
Element.validateElementToElementPosition(firstScreen.carouselItems["Item 2"], firstScreen.carouselItems["Item 3"], .leftOf)
}

func testElementToElementPositionFail() {
// This should fail
Elements.validateElementToElementPosition(firstScreen.carouselItems["Item 2"], firstScreen.carouselItems["Item 3"], .rightOf)
Element.validateElementToElementPosition(firstScreen.carouselItems["Item 2"], firstScreen.carouselItems["Item 3"], .rightOf)
}

func testGetLastMatchFromQuery() {
Expand All @@ -40,14 +40,14 @@ final class SampleAppUITests: BaseTest {
func testElementDisappearsSameScreen() {
XCTAssertTrue(firstScreen.disappearingButton.isVisible)
firstScreen.disappearingButton.tap()
Elements.waitForElementExistence(firstScreen.disappearingButton, 6, false)
Element.waitForElementExistence(firstScreen.disappearingButton, 6, false)
XCTAssertFalse(firstScreen.disappearingButton.isVisible)
}

func testElementDisappearsSameScreen2() {
XCTAssertTrue(firstScreen.disappearingButton.isVisible)
firstScreen.disappearingButton.tap()
Elements.waitForElementExistenceAlt(firstScreen.disappearingButton, 6, false)
Element.waitForElementExistenceAlt(firstScreen.disappearingButton, 6, false)
XCTAssertFalse(firstScreen.disappearingButton.isVisible)
}

Expand All @@ -61,9 +61,9 @@ final class SampleAppUITests: BaseTest {
tabBar.openSecondPage()
let elements = secondScreen.loadingElements
// Wait for 10 seconds to have 5 elements, should pass
Elements.waitUntilTableFilled(elements, 5, TestConstants.Timeout.medium)
Element.waitUntilTableFilled(elements, 5, TestConstants.Timeout.medium)
// Should fail because only 5 in total will be loaded
Elements.waitUntilTableFilled(elements, 6, TestConstants.Timeout.short)
Element.waitUntilTableFilled(elements, 6, TestConstants.Timeout.short)
}

func testTypeText() {
Expand Down Expand Up @@ -102,7 +102,7 @@ final class SampleAppUITests: BaseTest {
tabBar.openThirdPage()
// Tap the text element, couldn't properly build triggering permissions with navigation ;D
thirdScreen.permissionState.tap()
Alerts.handleSystemAlert("OK")
Alert.handleSystemAlert("OK")
XCTAssertTrue(getSpringboardApp().alerts.count == 0)
XCTAssertEqual(thirdScreen.getPermissionState(), "Allowed")
}
Expand All @@ -113,30 +113,30 @@ final class SampleAppUITests: BaseTest {

func testSelectPickerWheelValue() {
XCTAssertEqual(firstScreen.pickerWheel.textFromValue, "None")
Elements.setPickerValue(firstScreen.pickerWheel, "Many")
Element.setPickerValue(firstScreen.pickerWheel, "Many")
XCTAssertEqual(firstScreen.pickerWheel.textFromValue, "Many")
}

func testSetSliderPosition() {
Elements.setSlider(firstScreen.slider, 0.8)
Element.setSlider(firstScreen.slider, 0.8)
print(firstScreen.slider.textFromValue)
}

func testCloseAppAlertWithAlertAndButtonName() {
firstScreen.triggerAlertButton.tap()
Alerts.handleAppAlert(getApp().alerts.firstMatch, "Close")
Alert.handleAppAlert(getApp().alerts.firstMatch, "Close")
}

func testCloseAppAlertWithButtonName() {
firstScreen.triggerAlertButton.tap()
Alerts.handleAppAlert("Close")
Alert.handleAppAlert("Close")
firstScreen.triggerAlertButton.tap()
Alerts.handleAppAlert("Accept")
Alert.handleAppAlert("Accept")
}

func testCloseAppAlertAgnostic() {
firstScreen.triggerAlertButton.tap()
Alerts.handleAppAlert("")
Alert.handleAppAlert("")
}

func testElementFullyVisible() {
Expand All @@ -158,6 +158,12 @@ final class SampleAppUITests: BaseTest {
}

func testWaitForElementBySuppliedPredicate() {
Elements.waitForElementPredicate(firstScreen.carousel, 2, NSPredicate(format: "exists == false"))
Element.waitForElementPredicate(firstScreen.carousel, 2, NSPredicate(format: "exists == false"))
}

func testKoleo() {
sleep(2)
print(getApp().staticTexts["covered-element"].isHittable)
print(getApp().staticTexts["covering-element"].isHittable)
}
}

0 comments on commit 3215a16

Please sign in to comment.