当前位置: 首页 > 知识库问答 >
问题:

AWS设备场不接受Testng XML

景阳平
2023-03-14

我正在尝试使用testng.xml...并且看起来设备场忽略了整个文件。

我的例子很简单。我有一个实例化测试类的工厂类,这就是我的xml文件的样子

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Default Suite">
    <test name="test">
        <classes>
            <class name="Factory"/>
        </classes>
    </test>
</suite>

我甚至尝试手动排除方法

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Default Suite">
    <test name="test">
        <classes>
            <class name="Factory"/>
            <class name="TestSingleUrl">
                    <methods>
                        <exclude name="testCorrectSiteKey"/>
                        <exclude name="testIsTagImplemented"/>
                        <exclude name="testHttpsScheme"/>
                        <exclude name="testCorrectTagName"/>
                        <exclude name="testCorrectBootstrapPath"/>
                    </methods>
            </class>
        </classes>
    </test>
</suite>
public class Factory{

    private String targetSiteKey;

    //Data Provider that consumes the first line, which contains the target sitekey of the tag
    @DataProvider(name = "urlProvider")
    public Iterator<Object[]> createData() throws IOException {
        List<String> lines = IOUtils.readLines(new InputStreamReader(this.getClass().getResourceAsStream("Urls.csv")));
        List<Object[]> objectArrays = lines.stream().map(x -> new Object[]{x}).collect(Collectors.toList());

        Iterator<Object[]> itr = objectArrays.iterator();
        targetSiteKey = itr.next()[0].toString();

        return itr;
    }

    @Factory(dataProvider="urlProvider")
    public Object[] creatingTests(String url){
        System.out.println(System.currentTimeMillis());
        String siteKey=null;
        String path = null;
        String tagName = null;
        WebElement browsi;
        try{
            RemoteWebDriver driver = DriverWrapper.getDriver();
            driver.get(url);
            browsi = driver.findElement(By.id("browsi-tag"));

            tagName = browsi.getTagName();
            siteKey = browsi.getAttribute("data-sitekey");
            path = browsi.getAttribute("src");

        }catch(Exception ignored){}
        finally{
            return new Object[] {new TestSingleUrl(targetSiteKey,siteKey,path,tagName,url)};
        }
    }
}
public class TestSingleUrl {
    private String targetSiteKey,siteKey,path,tagName,url;

    public TestSingleUrl(String targetSiteKey,String siteKey, String path, String tagName,String url){
        this.targetSiteKey = targetSiteKey;
        this.siteKey=siteKey;
        this.path=path;
        this.tagName=tagName;
        this.url=url;
    }

    @Test
    public void testCorrectSiteKey(){
        System.out.println(url);
        Assert.assertEquals(siteKey, targetSiteKey);
    }

    @Test
    public void testIsTagImplemented(){
        System.out.println(url);
        Assert.assertFalse(siteKey.isEmpty());
        Assert.assertFalse(tagName.isEmpty());
        Assert.assertFalse(path.isEmpty());
    }

    @Test
    public void testHttpsScheme(){
        System.out.println(url);
        Assert.assertTrue(path.contains("https"));
    }

    @Test
    public void testCorrectTagName(){
        System.out.println(url);
        Assert.assertEquals(tagName,"script");
    }

    @Test
    public void testCorrectBootstrapPath(){
        System.out.println(url);
        Assert.assertTrue(path.contains("middycdn-a.akamaihd.net/bootstrap/bootstrap.js"));
    }
}

共有1个答案

孙阳旭
2023-03-14

我不太确定,但我相信您应该能够将testng.xml放在资源目录中,并从pom.xml引用它。

这篇文章展示了如何从pom.xml中引用testng.xml:如何在Maven中从pom.xml调用testng.xml文件

当您构建项目时,它将包含在JAR中。

[Update]我从awslabs下载了示例项目,并将其导入到Eclipse中。然后我将这个插件添加到pom.xml文件中:

  <plugin>
           <groupId>org.apache.maven.plugins</groupId>
           <artifactId>maven-surefire-plugin</artifactId>
           <version>2.12.4</version>
           <configuration>
              <suiteXmlFiles>
                 <suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
              </suiteXmlFiles>
           </configuration>
        </plugin>     

然后,我在./src/test/resources/中创建了testng.xml

我复制并粘贴了这里提供的xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Default Suite">
    <test name="test">
        <classes>
            <class name="Factory"/>
        </classes>
    </test>
</suite>
mvn clean package -DskipTests=true
Failed to generate the test suites[TestNG] [ERROR] Cannot find class in classpath: Factory

这是意料之中的,因为我的类路径中没有该类,但是,这证明设备场确实读取了testng.xml。

[更新]

当我在testng.xml中使用exclude标记时,我可以重现这个问题。即当我使用这个XML时:

 <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Default Suite">
    <test name="test">
        <classes>
            <class name="factory.TestSingleUrl">
                <methods>
                    <exclude name="testCorrectSiteKey" />
                    <exclude name="testIsTagImplemented" />
                    <exclude name="testHttpsScheme" />
                    <exclude name="testCorrectTagName" />
                    <exclude name="testCorrectBootstrapPath" />
                </methods>
            </class>
        </classes>
    </test>
</suite>

我想我们只需要等待他们更新他们的环境和解析器。

您可以在专用设备上运行测试。您需要联系aws才能在这封电子邮件中获得一个:

aws-devicefarm-support@amazon.com

 类似资料:
  • 我已将AWS设备场配置为对我的应用程序运行自动测试。 在这篇文章之后,我成功地运行了使用和测试类型的测试。 现在我想使用Appium测试NG类型。我已经安装了appium模块并使其运行: 但是现在呢?如何编写和使用离子2测试? 这里说: 您的Android Appium Java TestNG测试必须包含在。他们指向Appium的官方网站,进一步解释如何在android或ios设备上使用Appiu

  • 我使用Appium和WebdriverIO为React本机应用程序创建了测试,它在android模拟器和真实设备上本地运行良好,但在AWS设备场上不起作用。本教程https://medium.com/jetclosing-engineering/react-native-device-testing-w-appium-node-and-aws-device-farm-295081129790我随后

  • 我试图将iOS XCTest设置为在AWS设备场上运行,但似乎无论我如何构建和上传它们,每次测试都会出错并失败。当我运行XCode时,它们会成功执行,但不会在AWS设备场上运行。 我甚至尝试了从非常简单的应用程序,没有任何api调用,但也失败了。 以下是AWS设备场界面中出现的错误。 你可以从这里看到日志

  • 我是Flutter的初学者,我使用的是android平板电脑,它是运行在android 4.3版本上的华硕Fonepad7。我没有对项目目录中的文件进行任何更改。当我运行“flutter run”时,它返回: 我已经打开了USB调试,我正在使用Arch Linux进行编程。 有没有办法解决这个问题,还是因为我使用的是一个老版本的Android。我查过这里,上面说支持Android4.3版本。那么我

  • 我正在为UITesting做准备,我试过Jenkins。我计划尝试AWS设备场。 http://docs.aws.amazon.com/devicefarm/latest/developerguide/test-types-ios-xctest-ui.html#test-types-ios-xctest-ui-prepare 它是这样说的。 在将iOS XCTest UI测试上载到设备场进行测试之

  • 我有一个linux box,其中有一个用户“user1”,使用C shell。用户有。cshrc在其主目录中提供了一些有用的环境设置。 然而,当我使用这种可解析逻辑时,环境并没有为用户正确设置。 在输出中,我可以看到变量设置为。cshrc不在环境中。如何强制ansible处理用户的登录脚本? 非常感谢。