patrol icon indicating copy to clipboard operation
patrol copied to clipboard

Need to run two tests in a test file using patrol build android. Runs only one via the script and then fails. I get PatrolAppServiceClientException: Invalid response 500, Internal Server Error

Open stefanosn opened this issue 5 months ago โ€ข 13 comments

Steps to reproduce

I have one real device connected to my Mac. I have installed flutter and the script below that builds android using patrol build android. Then uninstalls myapp from android real device. Then install app-$FLAVOR-debug.apk to android real device. Then install app-$FLAVOR-debug-androidTest.apk to android real device. Then finds the instrument

INSTRUMENT_LINE=$(adb -s "$device" shell cmd package list instrumentation | grep "com.eight.app.uat.test") TEST_RUNNER=$(echo "$INSTRUMENT_LINE" | cut -d: -f2 | cut -d' ' -f1)

and then runs it using adb -s "$device" shell am instrument -w -r "$TEST_RUNNER"

The app opens and runs the file integration_test/$TEST_PATH/notifications_comment_post_test.dart which inside contains two tests. First test runs and I get success but then I the second one does not start it fails saying PatrolAppServiceClientException: Invalid response 500, Internal Server Error. Check below the output in console. Am I missing something? Please any help appreciated.

This is the script

# ๐Ÿ— Build Patrol Android (stream output)
 echo "๐Ÿ”จ Building Patrol Android..."
 patrol build android \
   --flavor="$FLAVOR" \
   --dart-define-from-file="$DART_DEFINE_FILE" \
   --target="integration_test/$TEST_PATH/notifications_comment_post_test.dart" \
   --package-name=myapp \
   --verbose \
   | tee "$LOG_DIR/android_build.log"

 ANDROID_BUILD_EXIT_CODE=${PIPESTATUS[0]}
 if [ $ANDROID_BUILD_EXIT_CODE -ne 0 ]; then
  echo "โŒ patrol build android failed"
   exit 1
 fi

echo "-STARTING ANDROID DEVICES TEST-"
# # ๐Ÿš€ Run Android tests per test file per device
for device in "${ANDROID_DEVICE_IDS[@]}"; do
  log_file="$LOG_DIR/android_all_${device}.log"

echo "๐Ÿงน Uninstalling app and test APK on device: $device"
adb -s "$device" uninstall myapp || true
adb -s "$device" uninstall myapp.test || true

echo "๐Ÿ“ฆ Installing app APK..."
adb -s "$device" install -r ../build/app/outputs/flutter-apk/app-$FLAVOR-debug.apk

echo "๐Ÿ“ฆ Installing test APK..."
adb -s "$device" install -r ../build/app/outputs/apk/androidTest/$FLAVOR/debug/app-$FLAVOR-debug-androidTest.apk

  echo "๐Ÿงช Running native Android test runner on device: $device"

# Find the actual test runner for the current app flavor
INSTRUMENT_LINE=$(adb -s "$device" shell cmd package list instrumentation | grep "my app")
TEST_RUNNER=$(echo "$INSTRUMENT_LINE" | cut -d: -f2 | cut -d' ' -f1)

if [ -z "$TEST_RUNNER" ]; then
  echo "โŒ Could not find instrumentation runner for my app on device $device"
  exit 1
fi

echo "๐Ÿš€ Running: adb -s $device shell am instrument -w $TEST_RUNNER"
adb -s "$device" shell am instrument -w -r "$TEST_RUNNER"

done

Specifically the error

๐Ÿงช Running native Android test runner on device: deviceid
๐Ÿš€ Running: adb -s device shell am instrument -w myapp.uat.test/pl.leancode.patrol.PatrolJUnitRunner
INSTRUMENTATION_STATUS: class=myapp.MainActivityTest
INSTRUMENTATION_STATUS: current=1
INSTRUMENTATION_STATUS: id=AndroidJUnitRunner
INSTRUMENTATION_STATUS: numtests=2
INSTRUMENTATION_STATUS: stream=
com.eight.app.MainActivityTest:
INSTRUMENTATION_STATUS: test=runDartTest[features.notifications.notifications_comment_post_test Notifications social comment post - Happy path Should make a comment from account A and see the notification for comment in account B]
INSTRUMENTATION_STATUS_CODE: 1
INSTRUMENTATION_STATUS: class=myapp.MainActivityTest
INSTRUMENTATION_STATUS: current=1
INSTRUMENTATION_STATUS: id=AndroidJUnitRunner
INSTRUMENTATION_STATUS: numtests=2
INSTRUMENTATION_STATUS: stream=.
INSTRUMENTATION_STATUS: test=runDartTest[features.notifications.notifications_comment_post_test Notifications social comment post - Happy path Should make a comment from account A and see the notification for comment in account B]
INSTRUMENTATION_STATUS_CODE: 0
INSTRUMENTATION_STATUS: class=myapp.MainActivityTest
INSTRUMENTATION_STATUS: current=2
INSTRUMENTATION_STATUS: id=AndroidJUnitRunner
INSTRUMENTATION_STATUS: numtests=2
INSTRUMENTATION_STATUS: stream=
INSTRUMENTATION_STATUS: test=runDartTest[features.notifications.notifications_comment_post_test Notifications social comment post - Happy path Should see the notification when someone adds you as a friend]
INSTRUMENTATION_STATUS_CODE: 1
INSTRUMENTATION_STATUS: class=myapp.MainActivityTest
INSTRUMENTATION_STATUS: current=2
INSTRUMENTATION_STATUS: id=AndroidJUnitRunner
INSTRUMENTATION_STATUS: numtests=2
INSTRUMENTATION_STATUS: stack=java.lang.RuntimeException: pl.leancode.patrol.contracts.PatrolAppServiceClientException: Invalid response 500, Internal Server Error
        at pl.leancode.patrol.PatrolJUnitRunner.runDartTest(PatrolJUnitRunner.java:164)
        at com.eight.app.MainActivityTest.runDartTest(MainActivityTest.java:29)
        ... 39 trimmed
Caused by: pl.leancode.patrol.contracts.PatrolAppServiceClientException: Invalid response 500, Internal Server Error
        at pl.leancode.patrol.contracts.PatrolAppServiceClient.performRequest(PatrolAppServiceClient.kt:47)
        at pl.leancode.patrol.contracts.PatrolAppServiceClient.runDartTest(PatrolAppServiceClient.kt:23)
        at pl.leancode.patrol.PatrolAppServiceClient.runDartTest(PatrolAppServiceClient.kt:53)
        at pl.leancode.patrol.PatrolJUnitRunner.runDartTest(PatrolJUnitRunner.java:156)
        ... 41 more

INSTRUMENTATION_STATUS: stream=
Error in runDartTest[features.notifications.notifications_comment_post_test Notifications social comment post - Happy path Should see the notification when someone adds you as a friend](myapp.MainActivityTest):
java.lang.RuntimeException: pl.leancode.patrol.contracts.PatrolAppServiceClientException: Invalid response 500, Internal Server Error
        at pl.leancode.patrol.PatrolJUnitRunner.runDartTest(PatrolJUnitRunner.java:164)
        at com.eight.app.MainActivityTest.runDartTest(MainActivityTest.java:29)
        ... 39 trimmed
Caused by: pl.leancode.patrol.contracts.PatrolAppServiceClientException: Invalid response 500, Internal Server Error
        at pl.leancode.patrol.contracts.PatrolAppServiceClient.performRequest(PatrolAppServiceClient.kt:47)
        at pl.leancode.patrol.contracts.PatrolAppServiceClient.runDartTest(PatrolAppServiceClient.kt:23)
        at pl.leancode.patrol.PatrolAppServiceClient.runDartTest(PatrolAppServiceClient.kt:53)
        at pl.leancode.patrol.PatrolJUnitRunner.runDartTest(PatrolJUnitRunner.java:156)
        ... 41 more

INSTRUMENTATION_STATUS: test=runDartTest[features.notifications.notifications_comment_post_test Notifications social comment post - Happy path Should see the notification when someone adds you as a friend]
INSTRUMENTATION_STATUS_CODE: -2
INSTRUMENTATION_RESULT: stream=

Time: 6.229
There was 1 failure:
1) runDartTest[features.notifications.notifications_comment_post_test Notifications social comment post - Happy path Should see the notification when someone adds you as a friend](com.eight.app.MainActivityTest)
java.lang.RuntimeException: pl.leancode.patrol.contracts.PatrolAppServiceClientException: Invalid response 500, Internal Server Error
        at pl.leancode.patrol.PatrolJUnitRunner.runDartTest(PatrolJUnitRunner.java:164)
        at com.eight.app.MainActivityTest.runDartTest(MainActivityTest.java:29)
        ... 39 trimmed
Caused by: pl.leancode.patrol.contracts.PatrolAppServiceClientException: Invalid response 500, Internal Server Error
        at pl.leancode.patrol.contracts.PatrolAppServiceClient.performRequest(PatrolAppServiceClient.kt:47)
        at pl.leancode.patrol.contracts.PatrolAppServiceClient.runDartTest(PatrolAppServiceClient.kt:23)
        at pl.leancode.patrol.PatrolAppServiceClient.runDartTest(PatrolAppServiceClient.kt:53)
        at pl.leancode.patrol.PatrolJUnitRunner.runDartTest(PatrolJUnitRunner.java:156)
        ... 41 more

FAILURES!!!
Tests run: 2,  Failures: 1


INSTRUMENTATION_CODE: -1

Also this can help

if I run

adb shell cmd package list instrumentation

I see in console

instrumentation:androidx.test.orchestrator/.AndroidTestOrchestrator (target=androidx.test.orchestrator)
instrumentation:myapp.test/pl.leancode.patrol.PatrolJUnitRunner (target=myapp)
instrumentation:myapp.uat.test/pl.leancode.patrol.PatrolJUnitRunner (target=myapp.uat)
instrumentation:com.microsoft.office.officehubrow/android.test.InstrumentationTestRunner (target=com.microsoft.office.msohttp.tests)
instrumentation:com.samsung.android.app.dressroom/androidx.test.runner.AndroidJUnitRunner (target=com.samsung.android.app.dressroom)

Actual results

๐Ÿงช Running native Android test runner on device: deviceid
๐Ÿš€ Running: adb -s device shell am instrument -w myapp.uat.test/pl.leancode.patrol.PatrolJUnitRunner
INSTRUMENTATION_STATUS: class=myapp.MainActivityTest
INSTRUMENTATION_STATUS: current=1
INSTRUMENTATION_STATUS: id=AndroidJUnitRunner
INSTRUMENTATION_STATUS: numtests=2
INSTRUMENTATION_STATUS: stream=
com.eight.app.MainActivityTest:
INSTRUMENTATION_STATUS: test=runDartTest[features.notifications.notifications_comment_post_test Notifications social comment post - Happy path Should make a comment from account A and see the notification for comment in account B]
INSTRUMENTATION_STATUS_CODE: 1
INSTRUMENTATION_STATUS: class=myapp.MainActivityTest
INSTRUMENTATION_STATUS: current=1
INSTRUMENTATION_STATUS: id=AndroidJUnitRunner
INSTRUMENTATION_STATUS: numtests=2
INSTRUMENTATION_STATUS: stream=.
INSTRUMENTATION_STATUS: test=runDartTest[features.notifications.notifications_comment_post_test Notifications social comment post - Happy path Should make a comment from account A and see the notification for comment in account B]
INSTRUMENTATION_STATUS_CODE: 0
INSTRUMENTATION_STATUS: class=myapp.MainActivityTest
INSTRUMENTATION_STATUS: current=2
INSTRUMENTATION_STATUS: id=AndroidJUnitRunner
INSTRUMENTATION_STATUS: numtests=2
INSTRUMENTATION_STATUS: stream=
INSTRUMENTATION_STATUS: test=runDartTest[features.notifications.notifications_comment_post_test Notifications social comment post - Happy path Should see the notification when someone adds you as a friend]
INSTRUMENTATION_STATUS_CODE: 1
INSTRUMENTATION_STATUS: class=myapp.MainActivityTest
INSTRUMENTATION_STATUS: current=2
INSTRUMENTATION_STATUS: id=AndroidJUnitRunner
INSTRUMENTATION_STATUS: numtests=2
INSTRUMENTATION_STATUS: stack=java.lang.RuntimeException: pl.leancode.patrol.contracts.PatrolAppServiceClientException: Invalid response 500, Internal Server Error
        at pl.leancode.patrol.PatrolJUnitRunner.runDartTest(PatrolJUnitRunner.java:164)
        at com.eight.app.MainActivityTest.runDartTest(MainActivityTest.java:29)
        ... 39 trimmed
Caused by: pl.leancode.patrol.contracts.PatrolAppServiceClientException: Invalid response 500, Internal Server Error
        at pl.leancode.patrol.contracts.PatrolAppServiceClient.performRequest(PatrolAppServiceClient.kt:47)
        at pl.leancode.patrol.contracts.PatrolAppServiceClient.runDartTest(PatrolAppServiceClient.kt:23)
        at pl.leancode.patrol.PatrolAppServiceClient.runDartTest(PatrolAppServiceClient.kt:53)
        at pl.leancode.patrol.PatrolJUnitRunner.runDartTest(PatrolJUnitRunner.java:156)
        ... 41 more

INSTRUMENTATION_STATUS: stream=
Error in runDartTest[features.notifications.notifications_comment_post_test Notifications social comment post - Happy path Should see the notification when someone adds you as a friend](myapp.MainActivityTest):
java.lang.RuntimeException: pl.leancode.patrol.contracts.PatrolAppServiceClientException: Invalid response 500, Internal Server Error
        at pl.leancode.patrol.PatrolJUnitRunner.runDartTest(PatrolJUnitRunner.java:164)
        at com.eight.app.MainActivityTest.runDartTest(MainActivityTest.java:29)
        ... 39 trimmed
Caused by: pl.leancode.patrol.contracts.PatrolAppServiceClientException: Invalid response 500, Internal Server Error
        at pl.leancode.patrol.contracts.PatrolAppServiceClient.performRequest(PatrolAppServiceClient.kt:47)
        at pl.leancode.patrol.contracts.PatrolAppServiceClient.runDartTest(PatrolAppServiceClient.kt:23)
        at pl.leancode.patrol.PatrolAppServiceClient.runDartTest(PatrolAppServiceClient.kt:53)
        at pl.leancode.patrol.PatrolJUnitRunner.runDartTest(PatrolJUnitRunner.java:156)
        ... 41 more

INSTRUMENTATION_STATUS: test=runDartTest[features.notifications.notifications_comment_post_test Notifications social comment post - Happy path Should see the notification when someone adds you as a friend]
INSTRUMENTATION_STATUS_CODE: -2
INSTRUMENTATION_RESULT: stream=

Time: 6.229
There was 1 failure:
1) runDartTest[features.notifications.notifications_comment_post_test Notifications social comment post - Happy path Should see the notification when someone adds you as a friend](com.eight.app.MainActivityTest)
java.lang.RuntimeException: pl.leancode.patrol.contracts.PatrolAppServiceClientException: Invalid response 500, Internal Server Error
        at pl.leancode.patrol.PatrolJUnitRunner.runDartTest(PatrolJUnitRunner.java:164)
        at com.eight.app.MainActivityTest.runDartTest(MainActivityTest.java:29)
        ... 39 trimmed
Caused by: pl.leancode.patrol.contracts.PatrolAppServiceClientException: Invalid response 500, Internal Server Error
        at pl.leancode.patrol.contracts.PatrolAppServiceClient.performRequest(PatrolAppServiceClient.kt:47)
        at pl.leancode.patrol.contracts.PatrolAppServiceClient.runDartTest(PatrolAppServiceClient.kt:23)
        at pl.leancode.patrol.PatrolAppServiceClient.runDartTest(PatrolAppServiceClient.kt:53)
        at pl.leancode.patrol.PatrolJUnitRunner.runDartTest(PatrolJUnitRunner.java:156)
        ... 41 more

FAILURES!!!
Tests run: 2,  Failures: 1


INSTRUMENTATION_CODE: -1

### Logs

<details>
<summary>Logs</summary>


</details>


### Patrol version

patrol: 3.16.0

### Patrol Doctor output

<details>
<summary>Patrol Doctor output</summary>


</details>


### Flutter Doctor output

<details>
<summary>Flutter Doctor output</summary>


</details>

stefanosn avatar Jul 23 '25 06:07 stefanosn

Hi @stefanosn Since your script seems to be working fine let's focus on your test. Can you share logs from patrol test with --verbose flag? Also, code of your test would be very helpful

zoskar avatar Jul 23 '25 11:07 zoskar

Also, is there any specific reason why you don't use patrol test in this case?

And as a side note, if you have any other questions we also have a dedicated Discord channel: https://discord.gg/ukBK5t4EZg

zoskar avatar Jul 23 '25 11:07 zoskar

Hello thanks for answering. I did not explain the whole idea sorry.

The goal is to run in multiple devices in parallel using the script, not just one device the test that is why I use patrol build. Also I need to run multiple _test.dart in multiple devices in parallel.

Is there a way to do it with patrol test and run in multiple devices in parallel using a .sh? I would be glad to join your discord. I have posted another question there. I just thought that here it can help more people if answered because in discord not everyone has access but we can chat there for sure.

I would be grateful if you can help me.

This is a simple test I just did now and the output again occurs with the script i mentioned.

import 'package:flutter_test/flutter_test.dart';
import 'package:patrol/patrol.dart';

import '../../common/pump_app.dart';

void main() {
  group('Just pump app and wait', () {
    patrolTest(
      'Just pump app and wait 2 seconds',
      framePolicy: LiveTestWidgetsFlutterBindingFramePolicy.fullyLive,
      tags: ['notifications', 'happyPath', 'notificationsComment'],
      ($) async {
        await $.pumpApp();
        await Future.delayed(const Duration(seconds: 2));
      },
    );

    patrolTest(
      'Just pump app and wait 5 seconds',
      framePolicy: LiveTestWidgetsFlutterBindingFramePolicy.fullyLive,
      ($) async {
        await $.pumpApp();
        await Future.delayed(const Duration(seconds: 5));
      },
    );
  });
}

This is the log of the patrol build, I removed some defines and Task so it is smaller.

Verbose mode enabled. More logs will be printed.

Update available! 3.7.0 โ†’ 3.7.0. (Newest patrol_cli 3.9.0 is not compatible with project patrol version.)

To update to the latest compatible version, run:
dart pub global activate patrol_cli 3.7.0

โš ๏ธ  Before updating, please ensure your patrol package version is compatible with patrol_cli 3.9.0
Check the compatibility table at: https://patrol.leancode.co/documentation/compatibility-table


Received 1 test target(s)
Received test target: integration_test/features/pump_test.dart

Generated entrypoint integration_test/test_bundle.dart with 1 bundled test(s)
Received Android flavor: UAT
Received 5 --dart-define(s) (0 custom, 5 internal)
Received internal --dart-define: PATROL_WAIT=0
Received internal --dart-define: PATROL_APP_PACKAGE_NAME=myapp.uat
Received internal --dart-define: PATROL_ANDROID_APP_NAME=Myapp
Received internal --dart-define: PATROL_TEST_LABEL_ENABLED=true
Received internal --dart-define: INTEGRATION_TEST_SHOULD_REPORT_RESULTS_TO_NATIVE=false
$ flutter build apk --config-only -t integration_test/test_bundle.dart
$ flutter doctor --verbose
$ ./gradlew :app:dependencies
โ€ข Building apk with entrypoint test_bundle.dart...
$ ./gradlew :app:assembleUATDebug -Ptarget=integration_test/test_bundle.dart -Pdart-defines=RU5WX05BTUU9VUFU,R0lEX0NMSUVOVF9JRF9JT1M9NTUyODc4ODMzNTIxLTUyY2w3ZDdmdWx1cWQ4Ymp1aDF0cm01dTVidjRiN3JkLmFwcHMuZ29vZ2xldXNlcmNvbnRlbnQuY29t -Papp-server-port=8082 -Ptest-server-port=8081
	: > Task :gradle:checkKotlinGradlePluginConfigurationErrors SKIPPED
	: > Task :gradle:compileKotlin UP-TO-DATE
	: > Task :gradle:compileJava NO-SOURCE
	: > Task :gradle:compileGroovy NO-SOURCE
	: > Task :gradle:pluginDescriptors UP-TO-DATE
	: > Task :gradle:processResources UP-TO-DATE
	: > Task :gradle:classes UP-TO-DATE
	: > Task :gradle:jar UP-TO-DATE
	: > Task :app:UatDebugMinSdkCheck
	: > Task :app:preBuild UP-TO-DATE
	: > Task :app:preUatDebugBuild UP-TO-DATE
	: > Task :app:mergeUatDebugNativeDebugMetadata NO-SOURCE
	: > Task :advertising_id:preBuild UP-TO-DATE
	: > Task :advertising_id:preDebugBuild UP-TO-DATE
	: > Task :advertising_id:generateDebugResValues UP-TO-DATE
	: > Task :advertising_id:generateDebugResources UP-TO-DATE
	: > Task :advertising_id:packageDebugResources UP-TO-DATE
	: > Task :advertising_id:parseDebugLocalResources UP-TO-DATE
	: > Task :advertising_id:generateDebugRFile UP-TO-DATE
	: > Task :advertising_id:compileDebugKotlin UP-TO-DATE
	: > Task :advertising_id:javaPreCompileDebug UP-TO-DATE
	: > Task :advertising_id:compileDebugJavaWithJavac NO-SOURCE
	: > Task :advertising_id:bundleLibCompileToJarDebug UP-TO-DATE
	: > Task :app:compileFlutterBuildUatDebug UP-TO-DATE
	: > Task :app:packJniLibsflutterBuildUatDebug UP-TO-DATE
	: > Task :advertising_id:compileDebugLibraryResources UP-TO-DATE
	: > Task :advertising_id:writeDebugAarMetadata UP-TO-DATE
	
	: 
	: [Incubating] Problems report is available at: file:///build/reports/problems/problems-report.html
	: 
	: Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.
	: 
	: You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
	: 
	: For more on this, please refer to https://docs.gradle.org/8.13/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.
	: 
	: BUILD SUCCESSFUL in 13s
	: 732 actionable tasks: 25 executed, 707 up-to-date

stefanosn avatar Jul 23 '25 13:07 stefanosn

Hi @stefanosn ! Thanks for explaining your case.

In general, patrol test by itself doesn't support running on multiple devices. It can run only on one device per command invocation. You can try running patrol test multiple times with different --device argument, so each invocation runs on different device. In a bash script, you can tell it to execute those commands in parallel (I had to google it: https://stackoverflow.com/questions/3004811/how-do-you-run-multiple-programs-in-parallel-from-a-bash-script). There are also device farms and test runners that support parallel execution, eg. Marathon, Firebase Test Lab has a sharding feature in beta, others probably support it as well. If you need it locally, not on a device farm, check out Marathon Runner.

The way that you tried to use here doesn't work AFAIK, and it wasn't supposed to work - we assume you either use device farm or patrol test command.

jBorkowska avatar Jul 23 '25 14:07 jBorkowska

Hello @jBorkowska I tried Marathon locally for iOS but they told me on their slack that they do not support local devices. If you know how to do it in Marathon let me know. This is the ticket i added on Marathon github for iOS https://github.com/MarathonLabs/marathon/issues/1004

I have some more questions. Will patrol build for each device separately for android if i use the script? If each build is 4GB in space for each device i will need another 4GB and another 4GB and so on?

So if i do something like below it should run all tests for each device one by one sort of in parallel.

#!/bin/bash
set -euo pipefail

TEST_PATH=${1:-integration_test/notifications_test.dart}
FLAVOR=${2:-UAT}
DART_DEFINE_FILE=${3:-.env.uat}

echo "๐Ÿ” Getting Android devices..."
ANDROID_DEVICES=$(adb devices | grep -v "List" | grep -v "emulator" | grep -w "device" | cut -f1)

if [ -z "$ANDROID_DEVICES" ]; then
  echo "โŒ No Android devices found."
  exit 1
fi

LOG_DIR="build/logs"
mkdir -p "$LOG_DIR"

for DEVICE in $ANDROID_DEVICES; do
  echo "๐Ÿ“ฑ Running on device $DEVICE..."
  (
    patrol test \
      --target="$TEST_PATH" \
      --flavor="$FLAVOR" \
      --dart-define-from-file="$DART_DEFINE_FILE" \
      --device="$DEVICE" | tee "$LOG_DIR/$DEVICE.log"
  ) &
done

wait
echo "โœ… All parallel tests finished."

stefanosn avatar Jul 23 '25 17:07 stefanosn

Hi again! I didn't know that Marathon runner doesn't support physical iOS, so I don't know if there is a workaround for it (I haven't used Marathon yet).

About running multiple patrol test in parallel - I'm not sure, never did that. I asked my colleague, he tried running the same test in parallel on 2 devices, and he used what you are using (am instrument), but he was running only one test per instrument command - maybe you can work with that

jBorkowska avatar Jul 24 '25 12:07 jBorkowska

@zoskar @jBorkowska @daohoangson @rhalff But I do not understand why patrol fails on that command can anyone answer me? Why I get this error that was the reason I opened this ticket. How to overcome it?

adb -s "$device" shell am instrument -w -r "$TEST_RUNNER"

Caused by: pl.leancode.patrol.contracts.PatrolAppServiceClientException: Invalid response 500, Internal Server Error at pl.leancode.patrol.contracts.PatrolAppServiceClient.performRequest(PatrolAppServiceClient.kt:47) at pl.leancode.patrol.contracts.PatrolAppServiceClient.runDartTest(PatrolAppServiceClient.kt:23) at pl.leancode.patrol.PatrolAppServiceClient.runDartTest(PatrolAppServiceClient.kt:53) at pl.leancode.patrol.PatrolJUnitRunner.runDartTest(PatrolJUnitRunner.java:156)

stefanosn avatar Jul 24 '25 17:07 stefanosn

This command will throw if there are multiple tests in the apk. You can run only one test using this command. If you want to build once (I know you do), try using class argument: --class <your_app_package_name>.MainActivityTest#runDartTest\\['$nativeTestName'\\]". It's useful to check the format of native test name, we were changing it between versions. You can check it in a xml report which is generated after running patrol test command. For example:

Image "Class" at the top of this screenshot is what goes before # (int his case `pl.leancode.patrol.e2e_app.MainActivityTest`). `runDartTest[example_test__counter__state__is__the__same__after__going__to__Home__and__switching__apps]` is a test name, which goes after #.

jBorkowska avatar Jul 25 '25 10:07 jBorkowska

@jBorkowska Thanks for the advice Julia. I appreciate your help.

I will try it, but I do not want to run patrol test to get the runDartTest[example_test__counter__state__is__the__same__after__going__to__Home__and__switching__apps]

So my question is if I run patrol build android command where can I find the runDartTest commands runDartTest[example_test__counter__state__is__the__same__after__going__to__Home__and__switching__apps]?

I am asking this because I need to parse them find them and then pass them into the adb shell am instrument command right?

stefanosn avatar Jul 28 '25 07:07 stefanosn

@stefanosn You can construct it by yourself, it's deterministic. I showed this so you can see the pattern. runDartTest[] is constant. example_test is test file name without extension. The rest is test decsription (the argument you pass to patrolTest()).

jBorkowska avatar Jul 28 '25 12:07 jBorkowska

@jBorkowska But I do not want to construct it. I want to find it in the apk after patrol build android command finishes and parse the name...in the apk should be somewhere

test=runDartTest[features.notifications.notifications_comment_post_test Notifications social comment post - Happy path Should make a comment from account A and see the notification for comment in account B]

Where is the line above because patrol finds this and runs it using patrol test command.

stefanosn avatar Jul 29 '25 05:07 stefanosn

Patrol doesn't find it, it gives this name to those tests, so there is no need to find it afterwards

jBorkowska avatar Jul 29 '25 08:07 jBorkowska

@jBorkowska Yes this is what i am saying

patrol build android

gives the names right?

After giving the names, where in the apk can i find one test name that patrol build android gave and run it using adb instrument with --class command?

Like this

adb shell am instrument -w \
  -e class 'myapp.MainActivityTest#runDartTest\[my_test_name\]' \
  myapp.uat.test/pl.leancode.patrol.PatrolJUnitRunner

I do not want to write the names one by one, i need to retrieve them from the apk because they exist somewhere after the patrol build android command gives the names.

stefanosn avatar Jul 29 '25 15:07 stefanosn