AWS Device Farm忽略TestNG Priority注释

时间:2019-02-20 10:38:12

标签: testng appium-android aws-device-farm

我用setUp()tearDown()注释下的@BeforeClass@AfterClass方法创建了一个测试套件类。

我在此类中包括了6个测试用例,每个测试用例都包含@Test(priority = #)。我在本地计算机上执行了该类,并且工作正常,但是当我将其上载到AWS Device Farm时,它仅在初始化appium服务器时使用(priority = 1)执行一个测试用例,并针对所有其他测试用例设备场执行

。 >

如何克服这种障碍?

1 个答案:

答案 0 :(得分:1)

您是否正在使用自定义环境?在标准环境中可能会遇到此限制。

https://aws.amazon.com/premiumsupport/knowledge-center/xml-file-tests-jar-file-device-farm/

  

注意:在Device Farm的标准环境中,testng.xml文件仅支持部分功能。如果需要优先级,则该项目需要include标签,exclude标签,复杂分组或使用testng.xml文件中的参数,然后使用自定义环境。

[编辑]

我使用示例应用程序和测试测试了优先级

git clone https://github.com/aws-samples/aws-device-farm-appium-tests-for-sample-app.git
cd aws-device-farm-appium-tests-for-sample-app/
mkdir ./src/test/resources
// I used VS code here but any text editor will work
code ./src/test/resources/testng.xml

然后,我在上面的支持链接中添加了一些代码,以免影响所有测试:

testng.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="Tests.LoginTest"/> <!--Package.ClassName-->
        </classes>
    </test>
</suite>

然后,我修改了LoginTest以使用TestNG的priority feature

LoginTest.java

/*
 * Copyright 2014-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License").
 * You may not use this file except in compliance with the License.
 * A copy of the License is located at
 *
 * http://aws.amazon.com/apache2.0
 *
 * or in the "license" file accompanying this file. This file is distributed
 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
 * express or implied. See the License for the specific language governing
 * permissions and limitations under the License.
 */

package Tests;

import Pages.LoginPage;
import Tests.AbstractBaseTests.TestBase;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

/**
 * Tests for a login page
 */
public class LoginTest extends TestBase {
    private static final String LOGIN_SUCCESS_MESSAGE = "You are logged on as admin";
    private static final String LOGIN_FAIL_MESSAGE = "You gave me the wrong username and password";
    private static final String CORRECT_USER_NAME = "admin";
    private static final String CORRECT_PASSWORD = "password";
    private static final String FAIL_USER_NAME = "Wrong User";
    private static final String FAIL_PASSWORD = "12345";
    private static final String BAD_TEXT_ENTRY_MSG = "Username sent to text field incorrectly";

    private LoginPage loginPage;

    @Override
    public String getName() {
        return "Login Page";
    }

    /**
     * Creates a login
     */
    @BeforeTest
    @Override
    public void setUpPage() {
        loginPage = new LoginPage(driver);
    }

    /**
     * Tests logging in with valid credentials by verifying if the login message is correct
     */
    @Test(priority = 1)
    public void loginSuccess() throws InterruptedException {
        Assert.assertTrue(loginPage.login(CORRECT_USER_NAME, CORRECT_PASSWORD), BAD_TEXT_ENTRY_MSG);
        Assert.assertEquals(loginPage.getMessage(), LOGIN_SUCCESS_MESSAGE);
    }

    /**
     * Tests logging in with invalid credentials by verifying if the error message is correct
     */
    @Test(priority = 2)
    public void loginFail() throws InterruptedException {
        Assert.assertTrue(loginPage.login(FAIL_USER_NAME, FAIL_PASSWORD), BAD_TEXT_ENTRY_MSG);
        Assert.assertEquals(loginPage.getMessage(), LOGIN_FAIL_MESSAGE);
    }

    /**
     * After each test method, logout or try again
     */
    @AfterMethod
    public void logOut() {
        loginPage.pressAltButton();
        Assert.assertTrue(loginPage.checkIfBackAtLogin());
    }
}

我使用命令mvn clean package -DskipTests=true

打包了测试

在设备场中运行此命令可获得以下结果:

scheduling run

视频:https://imgur.com/YHnq08X

customer artifacts

results

所以我无法重现该问题。您能否提供证据来证明Device Farm的自定义环境无法优先执行?