Skip to content

Commit

Permalink
refactor: update I tests layout
Browse files Browse the repository at this point in the history
  • Loading branch information
bsorrentino committed Mar 22, 2024
1 parent 0d4307e commit e0d0a97
Show file tree
Hide file tree
Showing 6 changed files with 161 additions and 110 deletions.
22 changes: 21 additions & 1 deletion PlantUMLApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@
A0D3C65028984A10000838D7 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A0D3C64F28984A10000838D7 /* Assets.xcassets */; };
A0D3C65328984A10000838D7 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A0D3C65228984A10000838D7 /* Preview Assets.xcassets */; };
A0D3C65E28984A10000838D7 /* PlantUMLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A0D3C65D28984A10000838D7 /* PlantUMLTests.swift */; };
A0EA855F2BADDB3800800522 /* XCUIElement+Gesture.swift in Sources */ = {isa = PBXBuildFile; fileRef = A0EA855E2BADDB3800800522 /* XCUIElement+Gesture.swift */; };
A0EA85612BADDB9500800522 /* XCUIApplication+Tap.swift in Sources */ = {isa = PBXBuildFile; fileRef = A0EA85602BADDB9500800522 /* XCUIApplication+Tap.swift */; };
A0EA85632BADDBFA00800522 /* XCTestCase+Wait.swift in Sources */ = {isa = PBXBuildFile; fileRef = A0EA85622BADDBFA00800522 /* XCTestCase+Wait.swift */; };
A0EA85652BADDC5B00800522 /* EditorElement.swift in Sources */ = {isa = PBXBuildFile; fileRef = A0EA85642BADDC5B00800522 /* EditorElement.swift */; };
A0EA85672BADF6F200800522 /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = A0EA85662BADF6F200800522 /* Constants.swift */; };
A0F2B14229353C2D00A44481 /* SwiftUI+Rotate.swift in Sources */ = {isa = PBXBuildFile; fileRef = A0F2B14129353C2D00A44481 /* SwiftUI+Rotate.swift */; };
A0FB8F9C295616BF00910896 /* View+UIImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = A08AA78329561170004DE329 /* View+UIImage.swift */; };
/* End PBXBuildFile section */
Expand Down Expand Up @@ -112,6 +117,11 @@
A0D3C65428984A10000838D7 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
A0D3C65928984A10000838D7 /* PlantUMLTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = PlantUMLTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
A0D3C65D28984A10000838D7 /* PlantUMLTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlantUMLTests.swift; sourceTree = "<group>"; };
A0EA855E2BADDB3800800522 /* XCUIElement+Gesture.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "XCUIElement+Gesture.swift"; sourceTree = "<group>"; };
A0EA85602BADDB9500800522 /* XCUIApplication+Tap.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "XCUIApplication+Tap.swift"; sourceTree = "<group>"; };
A0EA85622BADDBFA00800522 /* XCTestCase+Wait.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "XCTestCase+Wait.swift"; sourceTree = "<group>"; };
A0EA85642BADDC5B00800522 /* EditorElement.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditorElement.swift; sourceTree = "<group>"; };
A0EA85662BADF6F200800522 /* Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = "<group>"; };
A0EF7AF128C40A6300660F09 /* PlantUMLKeyboard */ = {isa = PBXFileReference; lastKnownFileType = wrapper; path = PlantUMLKeyboard; sourceTree = "<group>"; };
A0F2B14129353C2D00A44481 /* SwiftUI+Rotate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SwiftUI+Rotate.swift"; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -154,8 +164,12 @@
A00729B929DB2A9D00D73D1A /* PlantUMLAppUITests */ = {
isa = PBXGroup;
children = (
A0C5C2E22A0FD12C0038C889 /* XCTestCase+LineEditor.swift */,
A0EA855E2BADDB3800800522 /* XCUIElement+Gesture.swift */,
A0C5C2E32A0FD12C0038C889 /* XCUIElement+TextField.swift */,
A0C5C2E22A0FD12C0038C889 /* XCTestCase+LineEditor.swift */,
A0EA85602BADDB9500800522 /* XCUIApplication+Tap.swift */,
A0EA85622BADDBFA00800522 /* XCTestCase+Wait.swift */,
A0EA85642BADDC5B00800522 /* EditorElement.swift */,
A00729BA29DB2A9D00D73D1A /* PlantUMLAppUITests.swift */,
A04FE0482AA26B8000210EFC /* PlantUML.xctestplan */,
A00729BC29DB2A9D00D73D1A /* PlantUMLAppUITestsLaunchTests.swift */,
Expand Down Expand Up @@ -234,6 +248,7 @@
A07493852BAB74590025B3C9 /* Deprecated */,
A07493832BAB04A00025B3C9 /* Representable */,
A07493822BAB04280025B3C9 /* Observable */,
A0EA85662BADF6F200800522 /* Constants.swift */,
A0C0C3272B5D95DD00CE66A2 /* Errors.swift */,
A0C0C3492B5DA7A200CE66A2 /* ActivityView.swift */,
A0A139342A13C49A00B69FBC /* View+Secure.swift */,
Expand Down Expand Up @@ -434,6 +449,10 @@
A0C5C2E02A0FD05A0038C889 /* PlantUMLAppUITests.swift in Sources */,
A0C0C34C2B5DA7A200CE66A2 /* ActivityView.swift in Sources */,
A0C5C2E12A0FD05A0038C889 /* PlantUMLAppUITestsLaunchTests.swift in Sources */,
A0EA85652BADDC5B00800522 /* EditorElement.swift in Sources */,
A0EA855F2BADDB3800800522 /* XCUIElement+Gesture.swift in Sources */,
A0EA85612BADDB9500800522 /* XCUIApplication+Tap.swift in Sources */,
A0EA85632BADDBFA00800522 /* XCTestCase+Wait.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -452,6 +471,7 @@
A0943A6F2944A44900342426 /* ScaleToFit+ToggleStyle.swift in Sources */,
A0A80A762B3ED90A00CB08CA /* SwiftUI+PencilKit.swift in Sources */,
A0D3C64C28984A0E000838D7 /* PlantUMLDocument.swift in Sources */,
A0EA85672BADF6F200800522 /* Constants.swift in Sources */,
A0D3C64E28984A0E000838D7 /* PlantUMLDocumentView.swift in Sources */,
A047206F29549ACC007E061F /* SwiftUI+Share.swift in Sources */,
A0C0C34A2B5DA7A200CE66A2 /* ActivityView.swift in Sources */,
Expand Down
48 changes: 48 additions & 0 deletions PlantUMLAppUITests/EditorElement.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//
// EditorElement.swift
// PlantUMLAppUITests
//
// Created by bsorrentino on 22/03/24.
//

import XCTest


struct EditorElement {

var element:XCUIElement

init( app: XCUIApplication ) {

if( app.webViews.textViews.element.waitForExistence(timeout: 5.0) ) {

XCTAssertEqual( app.webViews.textViews.count, 1 )
element = app.webViews.textViews.element(boundBy: 0)

return
}

XCTAssertTrue(app.webViews.textFields.element.waitForExistence(timeout: 5.0))
XCTAssertEqual( app.webViews.textFields.count, 1 )

element = app.webViews.textFields.element(boundBy: 0)
}

func typeText(_ str:String) {
str.forEach { char in
element.typeText( "\(char)" )
}
}

func typeText( andDismissIntellisense str: String ) {
typeText( str )
let coordinate = element.coordinate(withNormalizedOffset: CGVector( dx: 300, dy: 0))
coordinate.tap()
}

func typeText( andSelectIntellisense str:String, then: (() -> Void)? = nil ) {
typeText( str )
typeText("\t")
then?()
}
}
109 changes: 0 additions & 109 deletions PlantUMLAppUITests/PlantUMLAppUITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,115 +8,6 @@
import XCTest


// table extension
extension XCUIElement {


/// Performs a swipe left gesture on the UI element.
///
/// This simulates a long swipe left gesture by calculating start and end points
/// with normalized offsets, pressing on the start point, and dragging to the end point.
///
/// Useful for navigating back or dismissing views in UI Tests.
/// [Perform a full swipe left action in UI Tests?](https://stackoverflow.com/a/51639973)
func longSwipeLeft() {
let startOffset: CGVector
let endOffset: CGVector

startOffset = CGVector(dx: 0.6, dy: 0.0)
endOffset = CGVector.zero

let startPoint = self.coordinate(withNormalizedOffset: startOffset)
let endPoint = self.coordinate(withNormalizedOffset: endOffset)
startPoint.press(forDuration: 0, thenDragTo: endPoint)
}



}

extension XCUIApplication {
/// Taps on the screen coordinate specified by point.
///
/// - Parameter point: The point on the screen to tap.
///
/// This converts the point to a normalized coordinate using the receiver's frame.
/// It then applies the offset and performs the tap on the resulting coordinate.
func tapCoordinate(dx: CGFloat, dy: CGFloat) {
let normalized = self.coordinate(withNormalizedOffset: .zero)
let offset = CGVector(dx: dx, dy: dy)
let coordinate = normalized.withOffset(offset)
coordinate.tap()
}
}

extension XCUIElementQuery {

}


extension XCTestCase {

func waitForNotExistence( element: XCUIElement, timeout: TimeInterval ) {
let predicate = NSPredicate(format: "exists == FALSE")

expectation(for: predicate, evaluatedWith: element, handler: nil)

waitForExpectations(timeout: timeout, handler: nil)
}

func waitUntilEnabled( element: XCUIElement, timeout: TimeInterval ) {
let predicate = NSPredicate(format: "enabled == TRUE")

let _ = XCTWaiter.wait( for: [ expectation(for: predicate, evaluatedWith: element, handler: nil) ], timeout: timeout )

}

func wait( reason description: String, timeout: TimeInterval ) {
let _ = XCTWaiter.wait( for: [ expectation(description: description) ], timeout: timeout )
}

}


struct EditorElement {

var element:XCUIElement

init( app: XCUIApplication ) {

if( app.webViews.textViews.element.waitForExistence(timeout: 5.0) ) {

XCTAssertEqual( app.webViews.textViews.count, 1 )
element = app.webViews.textViews.element(boundBy: 0)

return
}

XCTAssertTrue(app.webViews.textFields.element.waitForExistence(timeout: 5.0))
XCTAssertEqual( app.webViews.textFields.count, 1 )

element = app.webViews.textFields.element(boundBy: 0)
}

func typeText(_ str:String) {
str.forEach { char in
element.typeText( "\(char)" )
}
}

func typeText( andDismissIntellisense str: String ) {
typeText( str )
let coordinate = element.coordinate(withNormalizedOffset: CGVector( dx: 300, dy: 0))
coordinate.tap()
}

func typeText( andSelectIntellisense str:String, then: (() -> Void)? = nil ) {
typeText( str )
typeText("\t")
then?()
}
}

final class PlantUMLAppUITests: XCTestCase {

Expand Down
33 changes: 33 additions & 0 deletions PlantUMLAppUITests/XCTestCase+Wait.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// XCTestCase+Wait.swift
// PlantUMLAppUITests
//
// Created by bsorrentino on 22/03/24.
//

import XCTest

extension XCTestCase {

func waitForNotExistence( element: XCUIElement, timeout: TimeInterval ) {
let predicate = NSPredicate(format: "exists == FALSE")

expectation(for: predicate, evaluatedWith: element, handler: nil)

waitForExpectations(timeout: timeout, handler: nil)
}

func waitUntilEnabled( element: XCUIElement, timeout: TimeInterval ) {
let predicate = NSPredicate(format: "enabled == TRUE")

let _ = XCTWaiter.wait( for: [ expectation(for: predicate, evaluatedWith: element, handler: nil) ], timeout: timeout )

}

func wait( reason description: String, timeout: TimeInterval ) {
let _ = XCTWaiter.wait( for: [ expectation(description: description) ], timeout: timeout )
}

}


24 changes: 24 additions & 0 deletions PlantUMLAppUITests/XCUIApplication+Tap.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// XCUIApplication+Coordinate.swift
// PlantUMLAppUITests
//
// Created by bsorrentino on 22/03/24.
//

import XCTest

extension XCUIApplication {
/// Taps on the screen coordinate specified by point.
///
/// - Parameter point: The point on the screen to tap.
///
/// This converts the point to a normalized coordinate using the receiver's frame.
/// It then applies the offset and performs the tap on the resulting coordinate.
func tapCoordinate(dx: CGFloat, dy: CGFloat) {
let normalized = self.coordinate(withNormalizedOffset: .zero)
let offset = CGVector(dx: dx, dy: dy)
let coordinate = normalized.withOffset(offset)
coordinate.tap()
}
}

35 changes: 35 additions & 0 deletions PlantUMLAppUITests/XCUIElement+Gesture.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// XCUIElement+Gesture.swift
// PlantUMLAppUITests
//
// Created by bsorrentino on 22/03/24.
//

import XCTest

// table extension
extension XCUIElement {


/// Performs a swipe left gesture on the UI element.
///
/// This simulates a long swipe left gesture by calculating start and end points
/// with normalized offsets, pressing on the start point, and dragging to the end point.
///
/// Useful for navigating back or dismissing views in UI Tests.
/// [Perform a full swipe left action in UI Tests?](https://stackoverflow.com/a/51639973)
func longSwipeLeft() {
let startOffset: CGVector
let endOffset: CGVector

startOffset = CGVector(dx: 0.6, dy: 0.0)
endOffset = CGVector.zero

let startPoint = self.coordinate(withNormalizedOffset: startOffset)
let endPoint = self.coordinate(withNormalizedOffset: endOffset)
startPoint.press(forDuration: 0, thenDragTo: endPoint)
}



}

0 comments on commit e0d0a97

Please sign in to comment.