AWS Device Farm不接受Testng XML [英] Testng XML not accepted by AWS Device Farm

查看:77
本文介绍了AWS Device Farm不接受Testng XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用testng.xml ...,似乎Device Farm正在忽略整个文件。

I'm trying to use the testng.xml... and looks like Device Farm is ignoring the whole file.

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

My example is simple. I have a factory class that instantiate test classes, and this is how my xml file looks like

<?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>

我什至尝试手动排除方法

I even tried to exclude methods manually

<?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>

但是我得到了无法调用方法:将其设为静态或创建非-args构造函数。这意味着设备场正在尝试运行TestSingleUrl类中的方法。但是调用这些测试的人应该是工厂

But I'm getting a "Can't invoke method: either make it static or create a non-args constructor" . Which means that the Device Farm is trying to run the methods from TestSingleUrl Class..But the one who call these test should be the factory

有人知道我们怎么做吗?设备场接受我们的xml文件?

Does anyone know how can we make the Device Farm to accept our xml file?

这是我的工厂类:

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)};
        }
    }
}

这是我的TestSingleUrl类别:

And this is my TestSingleUrl Class:

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"));
    }
}

我认为我收到的错误消息是因为设备场正在尝试使用找到的@Test注释运行每个方法。如果它正在读取我的xml文件,则不会发生。

I think that the error messages I'm getting is because the device farm is trying to run every method with a @Test annotation that it finds. If it was reading my xml file it wouldn't happen.

RocketRaccoon

推荐答案

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

I'm not sure exactly but I believe you should be able to place the testng.xml in a resources directory and reference it from the pom.xml .

看起来像这篇文章,显示了如何从pom.xml中引用testng.xml:
如何从Maven中的pom.xml调用testng.xml文件

Looks like this post shows how to reference the testng.xml from the pom.xml: How to call testng.xml file from pom.xml in Maven

构建项目时,它将包含在jar中。

When you build the project then it will be included in the jar.

awslabs项目通过使用此mvn命令来构建它

The awslabs project builds it by using this mvn command

mvn clean package -DskipTests = true

mvn clean package -DskipTests=true

https://github.com/awslabs/aws-device-farm-appium-tests-for-sample-app

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

[Update] I downloaded the sample project from awslabs and imported it into eclipse. I then added this plugin to the pom.xml file:

  <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>     

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

我复制并粘贴了此处提供的xml:

I copied and pasted the xml provided here:

<?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

这产生了一个zip-目标目录中的with-dependencies.zip文件。

This produced a zip-with-dependencies.zip file in the target directory.

我通过创建一个新项目并选择Appium Java Testng作为我要运行的测试类型,将该测试包上传到设备场。

I uploaded this test package to device farm by creating a new project and selecting Appium Java Testng as the type of tests that I want to run.

我遇到了此解析错误:

Failed to generate the test suites[TestNG] [ERROR] Cannot find class in classpath: Factory

由于我没有该类,这是可以预期的但是,classpath证明了设备场确实读取了testng.xml。

Which is expected since I don't have that class in my classpath, however, this proves that Device Farm did read the testng.xml.

[更新]

I当我在testng.xml中使用exclude标记时,能够重现该问题。即当我使用此xml时:

I am able to reproduce the problem when I use the exclude tag in the testng.xml. I.E when I use this 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>

打算进一步研究方法标签。

Going to investigate further on the method tags.

[更新]

看起来这是Device Farm中的一个已知问题:
AWS设备场似乎正在忽略TestNG注释

Looks like this is a known issue in Device Farm: AWS Device farm seems to be ignoring TestNG annotations

猜想我们只需要等待它们更新其环境和解析器即可。

Guess we will just need to wait for them to update their environment and the parser.

您也许可以在专用设备上运行测试。您需要联系aws才能通过此电子邮件获得帮助:

You might be able to run your tests on a private device. You'll need to contact aws to get one at this email:

aws-devicefarm-support@amazon.com

aws-devicefarm-support@amazon.com

[更新]

看起来他们已经更新了webDriverAgent。看看现在是否有效。

Looks like they've updated the webDriverAgent. See if it works now.

希望有帮助。

最好的问候

詹姆斯

这篇关于AWS Device Farm不接受Testng XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆