App:网易看游戏(Xone) 工具:appium 1.0 Appium 1.0较以往的版本有了比较大的变化。 1.xpath路径改变 Before:/window[1]/navigationBar[1]/button[4] Current://UIAApplication[1]/UIAWindow[1]/UIANavigationBar[1]/UIAButton[4] 2.Capability参数名称改变
Before: desiredCapabilities.setCapability(CapabilityType.PLATFORM, "iOS"); desiredCapabilities.setCapability(CapabilityType.VERSION, "7.0"); Current: desiredCapabilities.setCapability("platformVersion", "7.0");desiredCapabilities.setCapability("platformName", "iOS"); |
3.Appium客户端UI变化(提供更丰富的参数选择) 4.稳定性提供,客户端未崩溃过。 等等 接下来简单讲下具体实践过程吧 1.项目结构,如图
page:获取UI元素类 test:用例类,即测试类 util:封装大部分的公共方法 assertion:断言类 以testng框架为基础,ant编译执行,实现了每日构建运行。
2.编码,贴下通行证登录模块的代码,供参考 测试类:PassportLogin
public class PassportLogin extends BaseTest { private static Logger log = Logger.getLogger(PassportLogin.class); @DataProvider(name = "passportLoginData") public static Object[][] passportLoginData() { return new Object[][] { { "正确的网易通行证登录", "xxxxx@163.com", "xxxxx", "" }, { "非网易账号的网易通行证登录", "xxx@qq.com", "xxxx", "" }, { "网易通行证登录,密码错误", "xxxx@163.com", "xxx", "用户名或密码错误" }, { "不输入账号和密码", "", "", "用户名不能为空" }, { "不输入密码", "xxx@163.com", "", "密码不能为空" }, { "不输入账号", "", "xxxx", "用户名不能为空" }, { "错误的网易通行证登录", MyRandom.getRandomString(10) + "@163.com", MyRandom.getRandomString(6), "用户名或密码错误" } }; } @BeforeClass public void setUp() { driver = new Orange(); mainPage = new MainPage(driver); account = new Account(driver); as = new AssertSettings(driver); usPage = new UserSettingsPage(driver); homePage = new HomePage(driver); mainPage.enterMainPage(); mainPage.enterLogin(); account.logoutTrue(); } @AfterClass public void tearDown() { driver.quit(); } @AfterMethod public void end() throws InterruptedException { log.info("-------------------------------------------------------------------"); } @Test(dataProvider = "passportLoginData") public void passportLoginTest(String testName, String passport, String password, String errorCode) throws InterruptedException { log.info("测试内容:" + testName); mainPage.enterLogin(); account.login(passport, password); if (errorCode != "") { boolean b = as.assertLogin(errorCode); driver.sleep(3000); mainPage.flickToRight(); mainPage.closePage(); Assert.assertTrue(b); } else { mainPage.enterLogin(); homePage.settingsClick(); usPage.passportClick(); account.logout(); } } } |
由于涉及到了多个page,这里只贴部分Page类,如Account类,用于获取登录操作
public class Account extends BasePage { /** * @Title: Account * @Description: TODO * @param @param driver * @throws */ public Account(Orange driver) { super(driver); // TODO Auto-generated constructor stub } /** * @Title: login * @Description: TODO * @param @param driver * @return void * @throws */ public void login() { driver.clickOnElement(By.name("网易通行证登录")); driver.sendKeys(By.xpath("//UIAApplication[1]/UIAWindow[1]/UIATextField[1]"), PropertiesHandle.readValue("passport_2")); driver.sendKeys(By.xpath("//UIAApplication[1]/UIAWindow[1]/UIASecureTextField[1]"), PropertiesHandle.readValue("password")); driver.clickOnElement(By.xpath("//UIAApplication[1]/UIAWindow[1]/UIAButton[1]")); } /** * @Title: login * @Description: TODO * @param @param driver * @param @param passport * @param @param password * @return void * @throws */ public void login(String passport, String password) { driver.clickOnElement(By.name("网易通行证登录")); driver.sendKeys(By.xpath("//UIAApplication[1]/UIAWindow[1]/UIATextField[1]"), passport); driver.sendKeys(By.xpath("//UIAApplication[1]/UIAWindow[1]/UIASecureTextField[1]"), password); driver.clickOnElement(By.xpath("//UIAApplication[1]/UIAWindow[1]/UIAButton[1]")); } /** * @Title: login * @Description: TODO * @param @param type * @param @param passport * @param @param password * @return void * @throws */ public void login(String type, String passport, String password) { driver.clickOnElement(By.name(type)); driver.sendKeys(By.xpath("//UIAApplication[1]/UIAWindow[1]/UIATextField[1]"), passport); driver.sendKeys(By.xpath("//UIAApplication[1]/UIAWindow[1]/UIASecureTextField[1]"), password); driver.clickOnElement(By.xpath("//UIAApplication[1]/UIAWindow[1]/UIAButton[1]")); } /** * @Title: login * @Description: TODO * @param @param type * @return void * @throws */ public void login(String type) { driver.clickOnElement(By.name(type)); } /** * @Title: logout * @Description: TODO * @param @param driver * @return void * @throws */ public void logout() { driver.clickOnElement(By.name("退出当前帐号")); driver.clickOnElement(By.name("确定")); } } |