Fail to start uiautomator2 by Appium on Android 3rd emulator
2024-01-13 12:21

In my pipeline script, I use this command to start my Android UI automation on a 3rd party emulator.

".\\gradlew cucumber -Pargs=\"-rerun ${rerun_times} -enable-report ${enable_report} -timezone GMT+08:00 -suite ${running_scope}\" -b android\\build.gradle && exit %%ERRORLEVEL%%"

this command would invoke couple Gradle tasks: enter image description here

and my full pipeline has several stages, looks like: enter image description here

I put the above command in the last stage - Initiate AT, I don't see anything in the 4 stages before would affect AT running enter image description here

My issue is: When I run the full script on pipeline project 1, I can see Appium Settings apk flashing on the screen (that often means Appium server started), then nothing happened, here's the log enter image description here

I tried to separate the command and run it alone in pipeline project 2 enter image description here

I can see my debug app running successfully after Appium Settings apk flashing, here's the log I expected enter image description here

Can somebody help, I only start to use Jenkins pipeline this month, and I'm really confused.



Answer 1 :

I broke up each stage in the script and reassembled them with the Gradle command, finally I proved my point of 5 stages having nothing to do with each other, And I found the origin of the issue. What caused my problem was an environment variable I set up in environment block, HTTP_PROXY, I didn't know it also is what Appium will be using when it invokes uiautomator2, I still don't know, it's just my guess.


other answer :

It seems like you are facing an issue with starting Appium on a 3rd party emulator when running a Jenkins pipeline for Android UI automation. Here are some steps you can take to troubleshoot and resolve the issue:

Check Emulator Status: Ensure that the 3rd party emulator is properly configured and running before starting the Jenkins pipeline. You can manually start the emulator and confirm its status.

Appium Settings APK Flashing: If the Appium Settings APK is flashing on the screen, it indicates that the Appium server might be starting. However, the subsequent steps are not proceeding as expected. Check the Appium server logs for any errors or warnings that might provide insights into the issue.

Pipeline Stage Isolation: Since youve mentioned that the issue occurs in the last stage, "Initiate AT," try isolating this stage. You can create a simplified pipeline with only the "Initiate AT" stage and its associated commands. This can help you identify if there are any specific issues within this stage.

Logging and Debugging: Enhance the logging in your Jenkins pipeline. Add more detailed logs at different stages to identify where the pipeline might be failing. This can be done by printing additional information or using Jenkins logging features.

Gradle Tasks: The Gradle tasks you are invoking in your pipeline seem to include Cucumber tests. Ensure that these tasks are configured correctly and are not encountering any errors. Check the Gradle build logs for any issues related to running the Cucumber tests.

Environment Variables: Verify that the environment variables used in your pipeline script are correctly set. Pay special attention to variables related to Android settings, timezone, and suite configuration.

Permissions and Dependencies: Ensure that the Jenkins environment has the necessary permissions to interact with the emulator and execute the required commands. Additionally, check for any dependencies that might be missing or causing conflicts.

Parallel Execution: If your pipeline involves parallel execution of stages, consider running the "Initiate AT" stage sequentially to rule out any concurrency-related issues.

Update Jenkins Plugins: Make sure that your Jenkins plugins (especially those related to Android and UI automation) are up to date. Outdated plugins might have compatibility issues.

Community Support: Seek help from the Jenkins community or relevant forums where others may have encountered similar issues. Provide detailed information, including logs and configurations, to get more targeted assistance.

By systematically addressing these points, you should be able to identify and resolve the issues with starting Appium on the 3rd party emulator in your Jenkins pipeline.