Issue
I'm Created some automation test in java , using appium and junit 5.
I'm trying to Order my test with @Order
annotation before each test.
And before test class I'm using @TestMethodOrder(MethodOrderer.OrderAnnotation.class)
.
But it still not ordered. Below the code you can see attachment with tests order. Based on what it looks like, it doesn't make any order right now.
Maven dependencies:
<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>
Class with tests:
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());
}
}
}
Solution
Your import is wrong, replace import org.springframework.core.annotation.Order;
with import org.junit.jupiter.api.Order;
Answered By - Adwait Kumar