Issue
I am writing automation scripts to test a an iOS App on a real device. I'm using appium server. I having some issues related to Junit Test Case execution. I previously wrote 9 test methods with @order() annotation. Like 1->9 . and I put the server capabilties in the first test method. Till 9 methods the execution was going fine. But when I wrote the 10 11 and 12 method. The execution started from 10th method. As 10->11->12->1-> and so on till 9.
Here's the code
class TesClass {
String appiumPort ="4723";
String serverIp ="0.0.0.0";
static IOSDriver<IOSElement> driver;
LoginPage lPage=null;
DesiredCapabilities cap;
ProgrammesPage p_page=null;
MainPage mPage=null;
/*
* Order is the priority of the test case
* this is the first test case in this class
* This is responsible for creating connection with the appium server
* this sets basic capabilities and some advance capabilities
* to run the test cases on a real Ios device
*
*/
@Order(1)
@Test
void test() throws MalformedURLException {
cap= new DesiredCapabilities();
cap.setCapability("deviceName", "Muhammad’s iPhone");
cap.setCapability("platformName", "iOS");
cap.setCapability("platformVersion","12.1.2");
cap.setCapability("automationName", "XCUITest");
cap.setCapability("app", "/Users/ahmsam/Downloads/MainApp-2.ipa");
cap.setCapability("xcodeOrgId","BNL4VQ2576");
cap.setCapability("xcodeSigningId","iPhone Developer");
cap.setCapability("udid","240476512a6dd29a2f82fc8211ef4ea1bf6b5891");
// cap.setCapability("udid","3c7ad82d510561a572d459cab855154cd578e3da");
cap.setCapability("updateWDABundleId","5SN9XXLNWB.uk.org.humanfocus.WildCard.Dev");
String serverUrl = "http://" + serverIp + ":" + appiumPort + "/wd/hub";
driver = new IOSDriver<IOSElement>(new URL(serverUrl), cap);
driver.manage().timeouts().implicitlyWait(55,TimeUnit.SECONDS);
lPage=new LoginPage(driver);
lPage.firstThreePopoClick();
boolean check= lPage.validateLoginpage();
// = lPage.loginTestCase();
Assert.assertTrue(check);
//fail("Not yet implemented");
}
@Order(2)
@Test
void test1()
{
lPage=new LoginPage(driver);
boolean check1=lPage.TestdoLoginWIthValues();
Assert.assertTrue(check1==true);
}
@Order(3)
@Test
void test3()
{
lPage=new LoginPage(driver);
boolean check1=lPage.loginTestCase();
Assert.assertTrue(check1==true);
}
@Order(4)
@Test
void test4()
{
lPage=new LoginPage(driver);
boolean check1=lPage.TestGotoHomePage();
Assert.assertTrue(check1==true);
}
@Order(5)
@Test
void test5()
{
mPage=new MainPage(driver);
boolean check1=mPage.goToTrainings();
Assert.assertTrue(check1);
}
@Order(6)
@Test
void test6()
{
p_page=new ProgrammesPage(driver);
boolean check1=p_page.verifyProgramCode();
Assert.assertTrue(check1);
}
@Order(7)
@Test
void test7()
{
p_page=new ProgrammesPage(driver);
boolean check1=p_page.verifyContinueBtnDisable();
Assert.assertTrue(check1);
}
@Order(8)
@Test
void test8()
{
p_page=new ProgrammesPage(driver);
boolean check1=p_page.verifyVideoNextBtnDIsable();
Assert.assertTrue(check1);
}
@Order(9)
@Test
void test9() throws InterruptedException
{
p_page=new ProgrammesPage(driver);
boolean check1=p_page.verifyWatchView_ClickonNextBtn();
Assert.assertTrue(check1);
}
@Order(10)
@Test
void test10()
{
p_page=new ProgrammesPage(driver);
boolean check1=p_page.verifyDocumentPageNextButton();
Assert.assertTrue(check1);
}
@Order(11)
@Test
void test11()
{
p_page=new ProgrammesPage(driver);
boolean check1=p_page.verifyViewDocument_NextBtn();
Assert.assertTrue(check1);
}
@Order(12)
@Test
void test12()
{
p_page=new ProgrammesPage(driver);
boolean check1=p_page.verifyLastSectionName();
Assert.assertTrue(check1);
}
} enter image description here
Solution
Use the @TestMethodOrder annotation to specify the desired method orderer implementation to use, in this case the OrderAnnotation. Add this annotation to your test class: @TestMethodOrder(MethodOrderer.OrderAnnotation.class)
. Like:
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
class TestClass {
@Order(1)
@Test
void test() {
...
Answered By - camtastic