-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0d4307e
commit e0d0a97
Showing
6 changed files
with
161 additions
and
110 deletions.
There are no files selected for viewing
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
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
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?() | ||
} | ||
} |
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
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
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 ) | ||
} | ||
|
||
} | ||
|
||
|
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
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() | ||
} | ||
} | ||
|
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
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) | ||
} | ||
|
||
|
||
|
||
} |