### Install iOS Pods Source: https://patrol.leancode.co/llms-full.txt Navigate to the ios directory and run this command to install the necessary CocoaPods dependencies. ```bash pod install --repo-update ``` -------------------------------- ### Show Installed Tooling Information Source: https://patrol.leancode.co/llms-full.txt Displays information about the installed tooling. Use `--help` for all options. ```bash patrol doctor ``` -------------------------------- ### Install mobile-tools via Homebrew Source: https://patrol.leancode.co/llms-full.txt Install the mobile-tools package, which includes scripts for scheduling test runs on BrowserStack, using Homebrew. ```bash brew tap leancodepl/tools brew install mobile-tools ``` -------------------------------- ### PlatformAutomator Setup and Network Enablement Source: https://patrol.leancode.co/native-to-platform-migration This snippet shows the equivalent setup using PlatformAutomator after migration. It highlights the instantiation of PlatformAutomator and the subsequent enabling of network functionalities. ```typescript // After: patrolTearDown(() async { final automator = PlatformAutomator(config: nativeConfig); }); ``` -------------------------------- ### Example Patrol VS Code Settings Source: https://leancode.co/blog/patrol-vs-code-extension An example of how to configure additional arguments for Patrol commands within VS Code's `settings.json` file. This allows for persistent configuration of command-line options. ```json "patrol.additionalArgs": ["--verbose"] "patrol.develop.additionalArgs": ["--no-uninstall"] Β "patrol.test.additionalArgs": ["--clear-permissions"] ``` -------------------------------- ### Example BrowserStack Test Scheduling Output Source: https://patrol.leancode.co/llms-full.txt Example output demonstrating the successful scheduling of a test execution on BrowserStack after building and uploading the app and test artifacts. ```bash $ export BS_PROJECT=AwesomeApp # optional $ export BS_ANDROID_DEVICES="[\"Google Pixel 4-10.0\"]" # optional $ bs_android β€’ Building apk with entrypoint test_bundle.dart... βœ“ Completed building apk with entrypoint test_bundle.dart (11.0s) % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 87.4M 100 235 100 87.4M 7 2857k 0:00:33 0:00:31 0:00:02 2052k Uploaded app, url: bs://fb61a714e1a0c60e2578d940dad52b74da244d54 Uploaded test, url: bs://a715b1231d41ac627bd683f1b16c28476babd72e {"message":"Success","build_id":"a30440db559fcab65554ab0273437f3bd45d761b"} Scheduled test execution ``` -------------------------------- ### Patrol Test Summary Example Source: https://patrol.leancode.co/llms-full.txt Example output indicating a successful test run. ```text Test summary: πŸ“ Total: 1 βœ… Successful: 1 ❌ Failed: 0 ⏩ Skipped: 0 πŸ“Š Report: ⏱️ Duration: 4s ``` -------------------------------- ### Install Patrol CLI Source: https://patrol.leancode.co/llms-full.txt Installs the Patrol command-line interface globally. Ensure the patrol executable is added to your system's PATH. ```bash flutter pub global activate patrol_cli ``` -------------------------------- ### Android Native Test Setup Source: https://patrol.leancode.co/llms-full.txt Sets up the Android native test environment by creating the necessary directory structure and MainActivityTest.java file. ```java package com.example.myapp; // replace "com.example.myapp" with your app's package import androidx.test.platform.app.InstrumentationRegistry; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; import pl.leancode.patrol.PatrolJUnitRunner; ``` -------------------------------- ### Cross-Platform Selector Example Source: https://patrol.leancode.co/documentation/other/patrol-devtools-extension This example demonstrates how to create cross-platform selectors that work on both Android and iOS by using unique identifiers found in the inspector. ```dart // Cross-platform button using unique identifiers await patrol.nativeMatcher("**/android.widget.Button id=com.example.app:id/save_button").tap(); await patrol.nativeMatcher("**/ios.widget.Button id=SaveButton").tap(); ``` -------------------------------- ### Unified Native Interaction Example Source: https://leancode.co/blog/patrol-web-support Demonstrates the initial 'one API, two platforms' approach for native interactions. This example shows how to tap text using a unified API call that works on both iOS and Android. ```dart $$.native.tap(Selector(text: \ ``` -------------------------------- ### Web Automation Example Source: https://patrol.leancode.co/documentation/native/overview Demonstrates basic web automation capabilities in Patrol, such as running a main function for web tests. ```dart void main() { // Patrol web automation code here } ``` -------------------------------- ### Initialize App and Settle Widgets Source: https://leancode.co/blog/try-patrol-quick-hands-on-tutorial Initializes the application and waits for all widgets to settle. This is a common setup step for Patrol tests. ```dart await initApp(); await $.pumpWidgetAndSettle(const MyApp()); ``` -------------------------------- ### Platform Mobile Tap Example Source: https://patrol.leancode.co/native-to-platform-migration Demonstrates how to use the `$.platform.mobile.tap()` function with different selector types. This is commonly used during migration to abstract native tap actions. ```javascript $.platform.mobile.tap(MobileSelector.fromName("some name")) $.platform.mobile.tap(Selector.fromName("some name")) $.platform.mobile.tap(PlatformSelector.fromName("some name")) ``` -------------------------------- ### Flutter Default Finder Example Source: https://patrol.leancode.co/llms-full.txt Demonstrates the traditional Flutter way of interacting with widgets during testing, involving multiple steps for form input and interaction. ```dart testWidgets('signs up', (WidgetTester tester) async { await tester.pumpWidget(AwesomeApp()); await tester.pumpAndSettle(); await tester.enterText( find.byKey(Key('emailTextField')), 'charlie@root.me', ); await tester.pumpAndSettle(); await tester.enterText( find.byKey(Key('nameTextField')), 'Charlie', ); await tester.pumpAndSettle(); await tester.enterText( find.byKey(Key('passwordTextField')), 'ny4ncat', ); await tester.pumpAndSettle(); await tester.tap(find.byKey(Key('termsCheckbox'))); await tester.pumpAndSettle(); await tester.tap(find.byKey(Key('signUpButton'))); await tester.pumpAndSettle(); expect(find.text('Welcome, Charlie!'), findsOneWidget); }); ``` -------------------------------- ### Browser-Native Interaction Examples Source: https://leancode.co/blog/patrol-web-support Examples of browser-native interactions available through $.platform.web, including toggling dark mode, resizing the window, and managing browser history. These actions are specific to the web environment. ```dart switching between light and dark mode, ``` ```dart resizing the browser window, ``` ```dart navigating browser history, ``` ```dart Ctrl+A ``` ```dart Cmd+C ``` -------------------------------- ### Example Patrol Test Console Output Source: https://patrol.leancode.co/llms-full.txt This snippet shows an example of the console output generated during Patrol test execution. It includes logs for individual test steps, their status (e.g., βœ… for success, ❌ for failure, ⏳ for pending), test names, file paths, and execution times. It also demonstrates how a PlatformException might be reported within the logs. ```text ... 1.scrollTo widgets with text "Open permissions screen". βœ… 2. scrollTo widgets with text "Open permissions screen". βœ… 3. tap widgets with text "Open permissions screen". βœ… 4. tap widgets with text "Request camera permission". βœ… 5. isPermissionDialogVisible (native) βœ… 6. tap widgets with text "Request camera permission". βœ… 7. isPermissionDialogVisible (native) ⏳ 8. denyPermission (native) ❌ denies various permissions (patrol_test/permissions/deny_many_permissions_twice_test.dart) (9s) ══║ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK β•žβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β• The following PlatformException was thrown running a test: PlatformException(PermissionHandler.PermissionManager, A request for permissions is already running, please wait for it to finish before doing another request (note that you can request multiple permissions at the same time)., null, null) When the exception was thrown, this was the stack: #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:648:7) #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:334:18) #2 MethodChannelPermissionHandler.requestPermissions (package:permission_handler_platform_interface/src/method_channel/method_channel_permission_handler.dart:79:9) #3 PermissionActions.request (package:permission_handler/permission_handler.dart:52:31) #4 _PermissionsScreenState._requestCameraPermission (package:e2e_app/permissions_screen.dart:21:20) The test description was: denies various permissions ═════════════════════════════════════════════════════════════════ βœ… taps on notification (patrol_test/permissions/notifications_test.dart) (16s) βœ… taps on notification native2 (patrol_test/permissions/notifications_test.dart) (14s) βœ… grants various permissions (patrol_test/permissions/permissions_many_test.dart) (15s) ... ``` -------------------------------- ### Tap login button using key Source: https://patrol.leancode.co/llms-full.txt This example shows how to tap a button using its assigned key, making the code more self-explanatory and easier to understand at a glance. ```dart await $(#loginButton).tap(); ``` -------------------------------- ### Example Flutter App Structure Source: https://patrol.leancode.co/llms-full.txt A basic Flutter application structure with two Expanded ListViews, demonstrating a scenario with multiple Scrollable widgets. ```dart class App extends StatelessWidget { App({super.key}); @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( body: Column( children: [ Expanded(child: ListView(key: Key('listView1'))), Expanded( child: ListView.builder( key: Key('listView2'), itemCount: 101, itemBuilder: (context, index) => Text('index: $index'), ), ), ], ), ), ); } } ``` -------------------------------- ### Android Native Test Report Path (With Flavor) Source: https://patrol.leancode.co/llms-full.txt Example of a native test report file path for Android builds with a specific flavor. ```text πŸ“Š Report: file:///Users/user/patrol/dev/e2e_app/build/app/reports/androidTests/connected/debug/flavors/dev/index.html ``` -------------------------------- ### Android Native Test Report Path (No Flavor) Source: https://patrol.leancode.co/llms-full.txt Example of a native test report file path for Android builds without specific flavors. ```text πŸ“Š Report: file:///Users/user/patrol/dev/e2e_app/build/app/reports/androidTests/connected/debug/index.html ``` -------------------------------- ### Before: Native Android Selector Source: https://patrol.leancode.co/native-to-platform-migration Example of a native Android selector before migration. This code snippet demonstrates the original implementation that needs to be adapted for cross-platform compatibility. ```typescript // Before: await $.platform.mobile.tap(MobileSelector( android )); ``` -------------------------------- ### Basic App Creation and Interaction Source: https://patrol.leancode.co/documentation/patrol-tags Demonstrates creating an app instance and interacting with a component. Use this for setting up basic tests. ```typescript async { await createApp(); await $("#counterText").tap(); expect($("#counterText").text, '1'); } ``` -------------------------------- ### Upload App and Run Tests on LambdaTest Source: https://patrol.leancode.co/llms-full.txt This command-line output shows the process of uploading an app and its test suite to LambdaTest, followed by the JSON response indicating the status of the upload and build ID. Environment variables can be set to specify the project and target devices. ```bash $ export LAMBDATEST_PROJECT=AwesomeApp # optional $ export LAMBDATEST_DEVICES="[\"Pixel 7 Pro-13\"]" # optional β€’ Building apk with entrypoint test_bundle.dart... βœ“ Completed building apk with entrypoint test_bundle.dart (11.0s) % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 82.4M 100 255 100 82.4M 7 2897k 0:00:31 0:00:36 0:00:02 2051k Uploaded app, "app_id": "lt://APP1016047291733313441063634", Uploaded testsuite, "app_id": "lt://APP1016047291733312896265135", { "status": [ "Success" ], "buildId": [ "5875687" ], "message": [ "" ] } ``` -------------------------------- ### Sign in and handle permissions Source: https://patrol.leancode.co/llms-full.txt This snippet demonstrates signing into an app and handling permission dialogs. It's useful for setting up the initial state of the app before further testing. ```dart patrolTest( 'signs in, triggers a notification, and taps on it', ($) async { initApp(); await $.pumpWidgetAndSettle(const MainApp()); await $(keys.signInPage.emailTextField).enterText('test@email.com'); await $(keys.signInPage.passwordTextField).enterText('password'); await $(keys.signInPage.signInButton).tap(); if (await $.platform.mobile.isPermissionDialogVisible()) { await $.platform.mobile.grantPermissionWhenInUse(); } }, ); ``` -------------------------------- ### Top-Level Actions in Patrol Source: https://leancode.co/blog/patrol-web-support Examples of actions that are conceptually available across all platforms, even if their implementation varies. The 'tap' action is an example of such a top-level interaction. ```javascript $$.platform.tap(); ``` -------------------------------- ### Enable Video Recording Source: https://leancode.co/blog/patrol-web-support Configure video recording mode for test execution. ```bash --web-video - Video recording mode. ``` -------------------------------- ### iOS Selector Example Source: https://patrol.leancode.co/documentation/patrol-devtools-extension Example of how to define an iOS selector for UI elements. This is useful for targeting specific XCUI elements in your iOS application during automated tests. ```dart IOSSelector(elementType: 'XCUIElementTypeButton') ``` -------------------------------- ### Native Interaction Example (iOS/Android) Source: https://leancode.co/blog/patrol-web-support This is an example of the original `$.native` API used for interacting with native elements on iOS and Android. It aimed to provide a unified API for common actions. ```dart $.native.tap(Selector(text: "Press me")); ``` -------------------------------- ### Retrieve Test Reports using ADB Source: https://patrol.leancode.co/llms-full.txt These bash commands show how to create a directory for test reports, retrieve them from the device using ADB, and then serve them with Allure. ```bash mkdir -p ./build/reports ``` ```bash adb exec-out sh -c 'cd /sdcard/googletest/test_outputfiles && tar cf - allure-results' | tar xvf - -C build/reports ``` ```bash allure serve ./build/reports/allure-results ``` -------------------------------- ### Example Test Summary Output Source: https://patrol.leancode.co/llms-full.txt This is an example of the test summary printed after running Patrol tests, showing total tests, successes, failures, skipped tests, report location, and duration. ```text Test summary: πŸ“ Total: 8 βœ… Successful: 3 ❌ Failed: 5 - taps on notification (patrol_test/permissions/notifications_test.dart) - taps on notification native2 (patrol_test/permissions/notifications_test.dart) - accepts location permission (patrol_test/permissions/permissions_location_test.dart) - accepts location permission native2 (patrol_test/permissions/permissions_location_test.dart) - grants various permissions (patrol_test/permissions/permissions_many_test.dart) ⏩ Skipped: 0 πŸ“Š Report: file:///Users/user/patrol/dev/e2e_app/build/app/reports/androidTests/connected/index.html ⏱️ Duration: 227s ``` -------------------------------- ### List Attached Devices Source: https://patrol.leancode.co/llms-full.txt Lists attached devices, simulators, and emulators. Use `--help` for all options. ```bash patrol devices ``` -------------------------------- ### Build Android App Binaries Source: https://patrol.leancode.co/llms-full.txt Builds app binaries for Android integration testing. Use --help for all available options. ```bash patrol build android ``` -------------------------------- ### NativeAutomator2 - Introduction Source: https://leancode.co/blog/patrol-web-support Introduces the NativeAutomator2 framework, which handles platform-specific selectors for UI elements. ```text NativeAutomator2 ``` -------------------------------- ### Web Get Clipboard Source: https://patrol.leancode.co/llms-full.txt Retrieve the content from the browser's clipboard. ```dart final clipboardContent = await $.platform.web.getClipboard(); ``` -------------------------------- ### Build iOS App Binaries Source: https://patrol.leancode.co/llms-full.txt Builds app binaries for iOS integration testing. Use --help for all available options. ```bash patrol build ios ``` -------------------------------- ### Clipboard Source: https://patrol.leancode.co/documentation/web Interact with the browser's clipboard to set and get text. ```APIDOC ## Clipboard ### Description Allows setting text to the clipboard and retrieving text from it. ### Methods - `setClipboard(text: String)`: Sets the specified text to the clipboard. - `getClipboard()`: Retrieves the current text from the clipboard. ### Example ```dart await $.platform.web.setClipboard(text: 'test'); final clipboard = await $.platform.web.getClipboard(); ``` ``` -------------------------------- ### Define keys in a dedicated file Source: https://patrol.leancode.co/llms-full.txt This example shows how to define all widget keys in a central `lib/keys.dart` file for better organization and to prevent typos. It includes a `Keys` class and a `K` typedef for easy access. ```dart import 'package:flutter/foundation.dart'; typedef K = Keys; class Keys { const Keys(); static const usernameTextField = Key('usernameTextField'); static const passwordTextField = Key('passwordTextField'); static const loginButton = Key('loginButton'); static const forgotPasswordButton = Key('forgotPasswordButton'); static const privacyPolicyLink = Key('privacyPolicyLink'); } ``` -------------------------------- ### Get device information Source: https://patrol.leancode.co/documentation/native/usage Retrieve information about the device where the tests are running. This is useful for debugging and conditional logic. ```dart // Check if running on an ``` -------------------------------- ### Build iOS with Patrol Configuration Source: https://patrol.leancode.co/llms-full.txt Run this command to build the iOS project with Patrol configuration, specifying the test file. ```bash flutter build ios --config-only patrol_test/example_test.dart ``` -------------------------------- ### Access Dart-Code Extension API Source: https://leancode.co/blog/patrol-vs-code-extension Retrieve the PublicDartExtensionApi from the Dart-Code extension to interact with its functionalities. Ensure the Dart extension is installed. ```typescript Β const dartExtension = vs.extensions.getExtension("dart-code.dart-code") Β if (!dartExtension) { Β Β Β throw new Error("Dart extension not found") Β } Β const dartExtensionApi = dartExtension.exports Β const testModel = new TestModel({ showSkippedTests: true }, isPathInsideFlutterProject) Β const testDiscoverer = new TestDiscoverer(logger, dartExtensionApi.workspace, testModel) Β context.subscriptions.push(testDiscoverer) Β constvsTestController = newVsCodeTestController(logger, testModel, testDiscoverer, dartExtensionApi.sdks) ``` -------------------------------- ### Get Operating System Version Source: https://patrol.leancode.co/llms-full.txt Retrieves the operating system version of the device. The format may vary between Android and iOS. ```dart // Get OS version (e.g., 30 for Android 11) final osVersion = await $.platform.mobile.getOsVersion(); if (osVersion >= 30) { // Android 11+ specific behavior } ``` -------------------------------- ### Getting Device Information Source: https://patrol.leancode.co/documentation/native/usage Retrieve information about the device running the tests, such as OS version and whether it's a virtual device. ```dart // Check if running on an emulator/simulator final isVirtual = await $.platform.mobile.isVirtualDevice(); // Get OS version (e.g., 30 for Android 11) final osVersion = await $.platform.mobile.getOsVersion(); if (osVersion >= 30) { // Android 11+ specific behavior } ``` -------------------------------- ### Run Multiple Specific Integration Tests (Comma Separated) Source: https://patrol.leancode.co/llms-full.txt Alternatively, provide multiple test files as a comma-separated list to the --targets flag. ```bash patrol test --targets patrol_test/login_test.dart,patrol_test/app_test.dart ``` -------------------------------- ### Platform-Specific Actions in Patrol Source: https://leancode.co/blog/patrol-web-support Examples of accessing platform-specific actions directly through their respective namespaces. Use these when an action is unique to a particular platform. ```javascript $$.platform.android.pressBack(); ``` ```javascript $$.platform.ios.closeHeadsUpNotification(); ``` ```javascript $$.platform.web.copyToClipboard(); ``` -------------------------------- ### Web Test Environment Configuration Options Source: https://leancode.co/blog/patrol-web-support Configure various aspects of the web test environment, such as locale, timezone, color scheme, geolocation, permissions, user agent, and viewport. ```bash --web-locale ``` ```bash --web-timezone ``` ```bash --web-color-scheme ``` ```bash --web-geolocation ``` ```bash --web-permissions ``` ```bash --web-user-agent ``` ```bash --web-viewport ``` -------------------------------- ### Clipboard Operations in Patrol Source: https://patrol.leancode.co/documentation/native/usage Perform clipboard operations using Patrol's platform-specific methods. Example shows copying text. ```dart await $.platform.native.copy(text: 'Hello Patrol'οΌ‰; ``` -------------------------------- ### Run All Integration Tests Source: https://patrol.leancode.co/llms-full.txt Execute all integration tests. Use 'patrol test --help' for a full list of options. ```bash patrol test ``` -------------------------------- ### Handling iOS Permissions Manually Source: https://patrol.leancode.co/documentation/native/usage For non-English locales on iOS, manual tapping is required. This example shows how to tap the 'Allow' button. ```dart await $.platform.ios.tap( IOSSelector(text: 'Allow'), appId: 'com.apple.springboard', ); ``` -------------------------------- ### Open Specific iOS App Source: https://patrol.leancode.co/documentation/native/usage Open a specific iOS application using its bundle identifier. For example, opening the Settings app. ```dart await $.platform.ios.openPlatformApp(iosAppId: 'com.apple.Preferences'); ``` -------------------------------- ### Create Patrol MCP Server Launcher Script Source: https://leancode.co/blog/patrol-mcp-release Create an executable script named 'run-patrol' to serve as the entry point for the MCP server. This script will be registered with your AI assistant. ```bash run-patrol ``` -------------------------------- ### iOS Selector Example Source: https://patrol.leancode.co/documentation/other/patrol-devtools-extension This snippet shows how to define an iOS selector for a button element. It specifies the element type and its class name. ```dart patrol( ..., ).ios.tap(find.byValueKey('some_key')); // Example of how to define a selector for an iOS button: patrol( ..., ).ios.tap(find.byElement(IOSSelector(id: 'some_id'))) ``` -------------------------------- ### Run Patrol Web Tests in Headless Mode for CI Source: https://patrol.leancode.co/documentation/web For CI environments, it's recommended to run web tests in headless mode to avoid issues with graphical displays. Use the `--web-headless true` flag. ```bash patrol test \ --device chrome \ --target patrol_test/login_test.dart \ --web-headless true ``` -------------------------------- ### Android Selector Example Source: https://patrol.leancode.co/documentation/other/patrol-devtools-extension This snippet demonstrates how to define an Android selector for a button element. It specifies the element type and its class name. ```dart patrol( ..., ).ios.tap(find.byValueKey('some_key')); // Example of how to define a selector for an Android button: patrol( ..., ).android.tap(find.byElement(AndroidSelector(clickable: true, text: 'Login'))) ```