Appium Android多重测试案例,它是如何运作的?

时间:2016-01-28 14:44:41

标签: android appium testcase

我正在尝试使用Appium在我的应用上自动化测试用例。

我设法运行一个简单的脚本,但我不理解运行多个测试用例的逻辑,如android生命周期。

测试用例的周期是什么?

因为当我运行下面的代码时,它不按以下顺序运行:firstTestsecondTestthirdTest ......

我们如何告诉testCase首先运行什么以及以什么顺序运行?感谢

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();
}

谢谢

2 个答案:

答案 0 :(得分:2)

对此的答案取决于您用于测试的测试框架。 如果您使用Junit进行测试,那么您可能无法按用户定义的顺序对它们进行优先级排序。 另一方面,如果您使用TestNG框架,则向Test annotation添加参数可以解决您的问题。 e.g。

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

虽然我建议,但你会按照this进行操作。

答案 1 :(得分:1)

您可以将dependsOnMethods与@Test注释一起使用来制作该流程:

@Test(dependsOnMethods = "methodName")