0

I am trying to use Appium to automate a test case on my app.

I managed to run a simple script, but I do NOT understand the logic of of the multiple testcases running process like android life-cycle.

What is the cycle for a testcase?

Because when I run the code below it does not run in order of: firstTest, secondTest, thirdTest...

How do we tell the testCase what to run first and in what order ? thanks

public class LoginTest {

AndroidDriver driver;

@BeforeClass
public void setUp() throws MalformedURLException{
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("device", "Android");
    capabilities.setCapability(CapabilityType.BROWSER_NAME, ""); //Name of mobile web browser to automate. Should be an empty string if automating an app instead.
    capabilities.setCapability(CapabilityType.VERSION, "5.0.2");
    capabilities.setCapability(CapabilityType.PLATFORM, "Android");
    capabilities.setCapability("app-package", "com.myapp"); //Replace with your app's package
    capabilities.setCapability("app-activity", ".myapp"); //Replace with app's Activity
    driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}

@Test
public void firstTest() throws InterruptedException
{     

   List<WebElement> textFieldsList =        driver.findElements(By.className("android.widget.EditText")); 
   int size = textFieldsList.size();
   textFieldsList.get(0).sendKeys("test@test.com");
   textFieldsList.get(1).sendKeys("12345");
   Thread.sleep(1000);


   WebElement btnLogin=driver.findElement(By.name("Login"));
   String login = btnLogin.getText();
   Assert.assertTrue(login.contains("Login"));
   System.out.println(login);
   btnLogin.click();
   Thread.sleep(1000);

  }

 @Test
 public void secondTest() throws InterruptedException {
 WebElement btnHome=driver.findElement(By.name("Home"));
 String login_1 = btnHome.getText();
 Assert.assertTrue(login_1.contains("Home"));
 System.out.println(login_1);
 btnHome.click();
 Thread.sleep(1000);
 }
 @Test
 public void thirdTest() throws InterruptedException {
 WebElement btnSecond=driver.findElement(By.name("Second"));
 String login_2 = btnSecond.getText();
 Assert.assertTrue(login_2.contains("Second"));
 System.out.println(login_2);
 btnSecond.click();
 Thread.sleep(1000);
}
@AfterClass
public void tearDown() {
driver.quit();
}

Thank you

Cindy Meister
  • 25,071
  • 21
  • 34
  • 43

2 Answers2

2

Well the answer to this depends on the Test framework you are using to for your Test. If you are using Junit for your tests, then you might not be able to prioritise them in a user defined order. On the other end using if you are using TestNG framework, adding parameter to Test annotation would solve your problem. e.g.

 @Test(groups = {"checklist1"}, priority = 1, testName = "firstTest", description = "My First Test")

Though I would suggest, you go through and follow this.

Community
  • 1
  • 1
Naman
  • 27,789
  • 26
  • 218
  • 353
  • For junit there are options you use right above the class name @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class NameOfClass { ... } There are not too many options and would recommend switching to TestNG if you require a particular sequence when running your tests – plosco Jan 28 '16 at 19:17
  • 1
    @plosco : thats what i suggested to go through and follow but only when read and understood completely :) – Naman Jan 28 '16 at 19:20
1

You can use dependsOnMethods with @Test annotation to make that flow:

@Test(dependsOnMethods = "methodName")
Gaurav
  • 1,332
  • 11
  • 22