1.创建继承Junit的测试类,如下:
  示例代码:
  public class AppiumTest extends TestCase
  2.Appium测试环境准备,包括:待测app信息设置、测试机(真机/模拟器)信息设置,一般放在setUp()方法
  示例代码:
  public void setUp() throws MalformedURLException{
  //真机信息
  DesiredCapabilities capabilities= new DesiredCapabilities();
  capabilities.setCapability( "device", "Anroid");
  capabilities.setCapability( "deviceName", "Android");
  capabilities.setCapability(CapabilityType. BROWSER_NAME, "");
  capabilities.setCapability( "platformName", "Android");
  capabilities.setCapability( "platformVersion" , "4.4" );
  File classpathRoot= new File(System. getProperty( "user.dir"));
  //待测apk 存放路径
  File appDir= new File(classpathRoot, "apps");
  File app= new File(appDir, "Test.apk" );
  capabilities.setCapability( "app", app.getAbsolutePath());
  //待测apk 包名
  capabilities.setCapability( "app-package", "android.test" );
  //待测apk 入口类
  capabilities.setCapability( "app-activity", ".TestActivity");
  //AppiumDriver
  driver= new AppiumDriver( new URL("http://127.0.0.1:4723/wd/hub" ),capabilities);         
  }
  3.Appium用例执行完成后的环境清理,一般放在tearDown()方法
  示例代码:
  public void tearDown(){      
  driver.quit();         
  }
  4.测试用例编写,一般以testXX开头
  示例代码:
  public void testClick(){
  //findElementByName是通过控件上的文字识别
  WebElement el= driver.findElementByName( "buttonText");
  el.click();
  }
  结束:上述只是简单的用例结构,具体api请查看官方文档。