Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make more Selector properties work on iOS #2030

Merged
merged 26 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
75efe19
start
bartekpacia Dec 19, 2023
30b4ef4
small progress
bartekpacia Dec 20, 2023
909d7f6
add extension `toNSPredicate()` on `Selector`
bartekpacia Dec 20, 2023
35ba9fa
more progress
bartekpacia Dec 20, 2023
62cd0e0
implement toNSPredicate and test it
fylyppo Dec 21, 2023
d87314c
Merge branch 'master' of github.com:leancodepl/patrol into feature/io…
piotruela Dec 27, 2023
d891347
Format swift code
piotruela Dec 27, 2023
7ab42bb
Merge branch 'master' of github.com:leancodepl/patrol into feature/io…
piotruela Jan 9, 2024
4526fd0
Update patrol dependency
piotruela Jan 9, 2024
7f765ce
Update pods version
piotruela Jan 9, 2024
01999dc
Make textStartsWith and textContains work in more methods on iOS
piotruela Jan 9, 2024
88e1246
Format code
piotruela Jan 9, 2024
b805128
Update enterText to work with textStartsWith and textContains
piotruela Jan 10, 2024
ac5e907
Update macos protocol implementation
piotruela Jan 10, 2024
2c3f457
Add tests for native Selector methods on iOS
piotruela Jan 10, 2024
6ef3a0a
Remove incorrect TODO
piotruela Jan 10, 2024
fa164fa
Add comment explaining weird behavior of ios_selector_test.dart
piotruela Jan 10, 2024
9701ebb
Merge branch 'master' of github.com:leancodepl/patrol into feature/io…
piotruela Jan 11, 2024
1bb4985
Format swift code
piotruela Jan 11, 2024
cfdfe20
Remove flaky ios selector tests
Jan 19, 2024
3688294
Hide extension behind PATROL_ENABLED
zltnDC Feb 8, 2024
b0605d3
Make darwin contracts public
zltnDC Feb 9, 2024
f4314ab
Fix tests
zltnDC Feb 9, 2024
8aeb56c
Merge branch 'master' into feature/ios_text_startswith_endswith
zltnDC Feb 9, 2024
5d87802
Fix swift format
zltnDC Feb 9, 2024
8c93fd8
Unhide Selector extension
zltnDC Feb 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dev/e2e_app/integration_test/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ final _nativeAutomatorConfig = NativeAutomatorConfig(

Future<void> createApp(PatrolIntegrationTester $) async {
await app_main.main();
await $.pumpAndSettle();
}

void patrol(
Expand Down
105 changes: 105 additions & 0 deletions dev/e2e_app/ios/RunnerTests/RunnerTests.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,114 @@
import XCTest
import patrol

typealias Selector = patrol.Selector

final class RunnerTests: XCTestCase {
func testSample() {
// This test is here to serve as a sample for more tests in the future
XCTAssertEqual(2 + 2, 4)
}

func testSelectorToNSPredicate_text() {
var selector = createEmptySelector()
selector.text = "Log in"

let predicate = selector.toNSPredicate()

NSLog(predicate.predicateFormat)
XCTAssertEqual(
predicate.predicateFormat,
"""
label == "Log in" OR \
title == "Log in"
""")
}

func testSelectorToNSPredicate_textStartsWith() {
var selector = createEmptySelector()
selector.textStartsWith = "Log in"

let predicate = selector.toNSPredicate()

NSLog(predicate.predicateFormat)
XCTAssertEqual(
predicate.predicateFormat,
"""
label BEGINSWITH "Log in" OR \
title BEGINSWITH "Log in"
""")
}

func testSelectorToNSPredicate_textContains() {
var selector = createEmptySelector()
selector.textContains = "Log in"

let predicate = selector.toNSPredicate()

NSLog(predicate.predicateFormat)
XCTAssertEqual(
predicate.predicateFormat,
"""
label CONTAINS "Log in" OR \
title CONTAINS "Log in"
""")
}

func testSelectorToNSPredicate_resourceId() {
var selector = createEmptySelector()
selector.resourceId = "log_in"

let predicate = selector.toNSPredicate()

NSLog(predicate.predicateFormat)
XCTAssertEqual(
predicate.predicateFormat,
"""
identifier == "log_in"
""")
}

func testSelectorToNSPredicate_complex_1() {
var selector = createEmptySelector()
selector.textContains = "text_contains"
selector.resourceId = "resource_id"

let predicate = selector.toNSPredicate()

NSLog(predicate.predicateFormat)
XCTAssertEqual(
predicate.predicateFormat,
"""
(label CONTAINS "text_contains" OR \
title CONTAINS "text_contains") AND \
identifier == "resource_id"
""")
}

func testSelectorToNSPredicate_complex_2() {
var selector = createEmptySelector()
selector.textContains = "text_contains"
selector.resourceId = "resource_id"

let predicate = selector.toNSPredicate()

NSLog(predicate.predicateFormat)
XCTAssertEqual(
predicate.predicateFormat,
"""
(label CONTAINS "text_contains" OR \
title CONTAINS "text_contains") AND \
identifier == "resource_id"
""")
}
}

private func createEmptySelector(text: String? = nil) -> patrol.Selector {
// Temporary fix. We will remove the Selector class later
let jsonString = "{}"

let jsonData = jsonString.data(using: .utf8)!
let decoder = JSONDecoder()

return try! decoder.decode(patrol.Selector.self, from: jsonData)
}
7 changes: 6 additions & 1 deletion dev/e2e_app/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class _ExampleHomePageState extends State<ExampleHomePage> {
),
Text(
'$_counter',
semanticsLabel: 'Counter: $_counter',
key: const Key('counterText'),
style: Theme.of(context).textTheme.headlineMedium,
),
Expand All @@ -110,7 +111,11 @@ class _ExampleHomePageState extends State<ExampleHomePage> {
key: const Key('tile1'),
title: const Text('Add'),
trailing: IconButton(
icon: const Icon(Icons.add, key: Key('icon1')),
icon: const Icon(
Icons.add,
key: Key('icon1'),
semanticLabel: 'Increment counter',
),
onPressed: _incrementCounter,
),
),
Expand Down
4 changes: 2 additions & 2 deletions dev/e2e_app/macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

import FlutterMacOS
import Foundation

import flutter_local_notifications
import flutter_timezone
import geolocator_apple
import patrol

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
FlutterLocalNotificationsPlugin.register(
with: registry.registrar(forPlugin: "FlutterLocalNotificationsPlugin"))
FlutterLocalNotificationsPlugin.register(with: registry.registrar(forPlugin: "FlutterLocalNotificationsPlugin"))
FlutterTimezonePlugin.register(with: registry.registrar(forPlugin: "FlutterTimezonePlugin"))
GeolocatorPlugin.register(with: registry.registrar(forPlugin: "GeolocatorPlugin"))
PatrolPlugin.register(with: registry.registrar(forPlugin: "PatrolPlugin"))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,93 @@
extension Selector {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This extension should be rather below #if PATROL_ENABLED.

public func toTextFieldNSPredicate() -> NSPredicate {
var format = ""
var begun = false
var values = [String]()

if text != nil {
begun = true
format += "(label == %@ OR title == %@ OR value == %@ OR placeholderValue == %@)"
values.append(text!)
values.append(text!)
values.append(text!)
values.append(text!)
}

if textStartsWith != nil {
if begun { format += " AND " }
begun = true
format +=
"(label BEGINSWITH %@ OR title BEGINSWITH %@ OR value BEGINSWITH %@ OR placeholderValue BEGINSWITH %@)"
values.append(textStartsWith!)
values.append(textStartsWith!)
values.append(textStartsWith!)
values.append(textStartsWith!)
}

if textContains != nil {
if begun { format += " AND " }
begun = true
format +=
"(label CONTAINS %@ OR title CONTAINS %@ OR value CONTAINS %@ OR placeholderValue CONTAINS %@)"
values.append(textContains!)
values.append(textContains!)
values.append(textContains!)
values.append(textContains!)
}

if resourceId != nil {
if begun { format += " AND " }
begun = true
format += "(identifier == %@)"
values.append(resourceId!)
}

let predicate = NSPredicate(format: format, argumentArray: values)

return predicate
}

public func toNSPredicate() -> NSPredicate {
var format = ""
var begun = false
var values = [String]()

if text != nil {
begun = true
format += "(label == %@ OR title == %@)"
values.append(text!)
values.append(text!)
}

if textStartsWith != nil {
if begun { format += " AND " }
begun = true
format += "(label BEGINSWITH %@ OR title BEGINSWITH %@)"
values.append(textStartsWith!)
values.append(textStartsWith!)
}

if textContains != nil {
if begun { format += " AND " }
begun = true
format += "(label CONTAINS %@ OR title CONTAINS %@)"
values.append(textContains!)
values.append(textContains!)
}

if resourceId != nil {
if begun { format += " AND " }
begun = true
format += "(identifier == %@)"
values.append(resourceId!)
}

let predicate = NSPredicate(format: format, argumentArray: values)

return predicate
}
}

#if PATROL_ENABLED
import XCTest
import os
Expand All @@ -13,21 +103,19 @@

// MARK: General UI interaction
func tap(
onText text: String,
on selector: Selector,
inApp bundleId: String,
atIndex index: Int,
withTimeout timeout: TimeInterval?
) throws
func doubleTap(
onText text: String,
on selector: Selector,
inApp bundleId: String,
withTimeout timeout: TimeInterval?
) throws
func tapAt(coordinate vector: CGVector, inApp bundleId: String) throws
func enterText(
_ data: String,
byText text: String,
atIndex index: Int,
on selector: Selector,
inApp bundleId: String,
dismissKeyboard: Bool,
withTimeout timeout: TimeInterval?
Expand All @@ -41,7 +129,7 @@
) throws
func swipe(from start: CGVector, to end: CGVector, inApp bundleId: String) throws
func waitUntilVisible(
onText text: String,
on selector: Selector,
inApp bundleId: String,
withTimeout timeout: TimeInterval?
) throws
Expand All @@ -58,7 +146,7 @@
func enableBluetooth() throws
func disableBluetooth() throws
func getNativeViews(
byText text: String,
on selector: Selector,
inApp bundleId: String
) throws -> [NativeView]
func getUITreeRoots(installedApps: [String]) throws -> [NativeView]
Expand Down
Loading
Loading