You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在AWS Device Farm中运行Maven命令及TestNG问题排查

Let's break down your two issues one by one and fix them step by step:

1. Maven Command Fails with "No POM in this directory" Error

Why this happens

AWS Device Farm extracts your uploaded test package into a temporary directory (like /tmp/scratchncneoU.scratch/test-packageO6o8s7 as shown in your error). When you run mvn test directly, Maven looks for the pom.xml in the current working directory—which isn’t the root of your extracted test package by default. Additionally, your original command has incorrect nested quoting around the cucumber.options parameter, which causes parsing issues for Maven.

Fix Steps

  • Navigate to the correct directory first: Use the $DEVICEFARM_TEST_PACKAGE_PATH environment variable (Device Farm automatically sets this to the root of your extracted test package where pom.xml resides).
  • Fix the quoting for cucumber.options: Avoid nested double quotes; use single quotes or format the system property without unnecessary outer quotes.

Your corrected YAML command should look like this:

- echo "Start Appium TestNG test"
- cd $DEVICEFARM_TEST_PACKAGE_PATH
- mvn test -Dcucumber.options='src/test/java/cucumber/features --glue cucumber.steps --tags @InstallApp'

Where is the POM file in Device Farm?

It lives at the root of your extracted test package, which is exactly what $DEVICEFARM_TEST_PACKAGE_PATH points to. Running cd $DEVICEFARM_TEST_PACKAGE_PATH ensures Maven can locate it immediately.


2. "Couldn't find the testng.xml in the jar file" Error

Why this happens

Even with your POM’s testResource configuration, two common issues are at play:

  1. Your testng.xml isn’t in a directory that Maven automatically packages into the test jar. By default, Maven only copies files from src/test/resources to the classpath; if your testng.xml is in src/test/java/cucumber, it might not be included in the jar unless you explicitly configure this.
  2. When using TestNG’s -testjar flag, it expects testng.xml to be at the jar’s root—or you need to specify its exact path inside the jar.

Fix Steps

Option 1: Ensure testng.xml is packaged in the jar

Either move your testng.xml to src/test/resources, or update your POM to explicitly include the file from its current location:

<build>
  <testResources>
    <testResource>
      <directory>${project.basedir}/src/test/java/cucumber</directory>
      <includes>
        <include>testng.xml</include>
      </includes>
    </testResource>
    <!-- Keep any other existing test resource configurations here -->
  </testResources>
</build>

Repackage your test jar after making this change.

Option 2: Specify the testng.xml path directly in your command

Instead of relying on the jar to contain testng.xml, point directly to the file in the extracted test package using the $DEVICEFARM_TEST_PACKAGE_PATH variable:

- java -Dappium.screenshots.dir=$DEVICEFARM_SCREENSHOT_PATH -Dcucumber.options='classpath:features --glue cucumber.steps --tags @InstallApp' org.testng.TestNG -testngxml $DEVICEFARM_TEST_PACKAGE_PATH/src/test/java/cucumber/testng.xml -d $DEVICEFARM_LOG_DIR/test-output -verbose 10

If you do keep testng.xml inside the jar, add -xmlpathinjar cucumber/testng.xml to the command to tell TestNG exactly where to find it.

内容的提问来源于stack exchange,提问作者kidulf

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.13 07:34:46