如何使用junit 5订购测试

迈克尔:

我使用appium和junit 5在java中创建了一些自动化测试。我试图@Order在每次测试之前对带有批注的测试进行排序在上课之前我正在使用@TestMethodOrder(MethodOrderer.OrderAnnotation.class)

但是它仍然没有命令。在代码下方,您可以看到测试顺序的附件。根据外观,它现在不下任何订单。

Maven依赖项:

<dependencies>
        <dependency>
            <groupId>io.appium</groupId>
            <artifactId>java-client</artifactId>
            <version>7.2.0</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api -->
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>5.6.0-M1</version>
            <scope>compile</scope>
        </dependency>

    </dependencies>

测试类:

package Tests;

import AppiumBase.BaseTestClass;
import Components.DrawerNavigation;
import Components.RenewPolicy;
import Utils.CustomAnotations.Attributes;
import Utils.CustomScreenAction;
import com.sun.org.glassfish.gmbal.Description;
import org.junit.jupiter.api.*;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.springframework.core.annotation.Order;

import static Utils.CustomAnotations.Attributes.TEXT_VIEW;

@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
@TestInstance(TestInstance.Lifecycle.PER_METHOD)
@DisplayName("Renew policy functionality")
@Attributes
public class RenewPolicyTest extends BaseTestClass {

    private WebDriverWait wait;
    private DrawerNavigation drawerNavigation;
    private RenewPolicy renewPolicy;
    private CustomScreenAction csa;

    @BeforeEach
    void executeBeforeEachTestInThisClass() {
        wait = new WebDriverWait(driver(), 10);
        drawerNavigation = new DrawerNavigation(driver());
        renewPolicy = new RenewPolicy(driver());
        csa = new CustomScreenAction();
    }

    @AfterEach
    void executeAfterEachTestInThisClass() {
        wait = null;
        drawerNavigation = null;
        renewPolicy = null;
    }

    @Test
    @Order(1)
    @DisplayName("Check renew policy button")
    @Description("Verify that the renew policy button appear on main screen")
    void isButtonAppear() {
        renewPolicy.isRenewPolicyButtonAppearOnMainScreen();
    }

    @Test
    @Order(2)
    @DisplayName("Check renew policy screen is opens")
    @Description("Verify that the renew policy button on MAIN SCREEN is clickable and right screen is opens")
    void isRenewPolicyScreenAppear() {
        renewPolicy.clickOnRenewPolicyButton();
    }

    @Test
    @Order(3)
    @DisplayName("Check renew policy screen opens from side menu")
    @Description("Verify that the renew policy button on DRAWER NAVIGATION is clickable and right screen is opens")
    void isRenewPolicyScreenOpenOnClickButtonFromDN() {
        drawerNavigation.openSideMenu();
        drawerNavigation.openRenewPolicyScreen();
    }

    @Test
    @Order(4)
    @DisplayName("Check checkbox")
    @Description("Check that the checkbox is checkable")
    void isCheckBoxCheckable() {
        renewPolicy.clickOnRenewPolicyButton();
        if (renewPolicy.isRenewPolicyScreenOpens()) {
            CustomScreenAction csa = new CustomScreenAction();
            csa.scrollToElement(TEXT_VIEW, "לשינויים אפשר לפנות למוקד");
        }
        renewPolicy.checkCheckBox();
    }

    @Test
    @Order(5)
    @DisplayName("Check confirm and pay button - disabled")
    @Description("Verify that the button is disabled while checkbox not checked")
    void isButtonDisabled() {
        renewPolicy.clickOnRenewPolicyButton();
        if (renewPolicy.isRenewPolicyScreenOpens()) {
            csa.scrollToElement(TEXT_VIEW, "מאשר תשלום וחידוש פוליסה");
        }
        if (renewPolicy.isConfirmAndRenewPolicyButtonDisplay()) {
            csa.isElementDisabled(renewPolicy.getConfirmAndRenewPolicyButton());
        }
    }

    @Test
    @Order(6)
    @DisplayName("Check confirm and pay button - enabled")
    @Description("Verify that the button is enabled while checkbox checked")
    void isButtonEnabled() {
        renewPolicy.clickOnRenewPolicyButton();
        if (renewPolicy.isRenewPolicyScreenOpens()) {
            csa.scrollToElement(TEXT_VIEW, "מאשר תשלום וחידוש פוליסה");
        }
        renewPolicy.checkCheckBox();
        if (renewPolicy.isConfirmAndRenewPolicyButtonDisplay()) {
            csa.isElementEnabled(renewPolicy.getConfirmAndRenewPolicyButton());
        }
    }
}

输出: 在此处输入图片说明

等候Kumar:

您的导入错误,请替换import org.springframework.core.annotation.Order;import org.junit.jupiter.api.Order;

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章