qileilove

          blog已經(jīng)轉(zhuǎn)移至github,大家請?jiān)L問 http://qaseven.github.io/

          iOS及Android自動(dòng)化實(shí)踐

           App:網(wǎng)易看游戲(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參數(shù)名稱改變
          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變化(提供更豐富的參數(shù)選擇)
            4.穩(wěn)定性提供,客戶端未崩潰過。
            等等
            接下來簡單講下具體實(shí)踐過程吧
            1.項(xiàng)目結(jié)構(gòu),如圖
            page:獲取UI元素類
            test:用例類,即測試
            util:封裝大部分的公共方法
            assertion:斷言類
            以testng框架為基礎(chǔ),ant編譯執(zhí)行,實(shí)現(xiàn)了每日構(gòu)建運(yùn)行。
          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[][] {
          { "正確的網(wǎng)易通行證登錄", "xxxxx@163.com", "xxxxx", "" },
          { "非網(wǎng)易賬號的網(wǎng)易通行證登錄", "xxx@qq.com", "xxxx", "" },
          { "網(wǎng)易通行證登錄,密碼錯(cuò)誤", "xxxx@163.com", "xxx",
          "用戶名或密碼錯(cuò)誤" },
          { "不輸入賬號和密碼", "", "", "用戶名不能為空" },
          { "不輸入密碼", "xxx@163.com", "", "密碼不能為空" },
          { "不輸入賬號", "", "xxxx", "用戶名不能為空" },
          { "錯(cuò)誤的網(wǎng)易通行證登錄", MyRandom.getRandomString(10) + "@163.com",
          MyRandom.getRandomString(6), "用戶名或密碼錯(cuò)誤" } };
          }
          @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("測試內(nèi)容:" + 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();
          }
          }
          }
          由于涉及到了多個(gè)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("網(wǎng)易通行證登錄"));
          driver.sendKeys(By.xpath("http://UIAApplication[1]/UIAWindow[1]/UIATextField[1]"),
          PropertiesHandle.readValue("passport_2"));
          driver.sendKeys(By.xpath("http://UIAApplication[1]/UIAWindow[1]/UIASecureTextField[1]"),
          PropertiesHandle.readValue("password"));
          driver.clickOnElement(By.xpath("http://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("網(wǎng)易通行證登錄"));
          driver.sendKeys(By.xpath("http://UIAApplication[1]/UIAWindow[1]/UIATextField[1]"), passport);
          driver.sendKeys(By.xpath("http://UIAApplication[1]/UIAWindow[1]/UIASecureTextField[1]"), password);
          driver.clickOnElement(By.xpath("http://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("http://UIAApplication[1]/UIAWindow[1]/UIATextField[1]"), passport);
          driver.sendKeys(By.xpath("http://UIAApplication[1]/UIAWindow[1]/UIASecureTextField[1]"), password);
          driver.clickOnElement(By.xpath("http://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("退出當(dāng)前帳號"));
          driver.clickOnElement(By.name("確定"));
          }
          }
            主要的公共類:Orange,主要借鑒了孔慶云同學(xué)已經(jīng)封裝好的方法,并進(jìn)行一些改進(jìn)后直接使用,方便快捷。
            目前Appium已經(jīng)到了1.1版本,這款自動(dòng)化工具還是不錯(cuò)的,跨平臺(tái),跨語言支持都比較好,穩(wěn)定性也在逐步提升。

          posted on 2014-06-25 11:30 順其自然EVO 閱讀(277) 評論(0)  編輯  收藏 所屬分類: selenium and watir webdrivers 自動(dòng)化測試學(xué)習(xí)android

          <2014年6月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          293012345

          導(dǎo)航

          統(tǒng)計(jì)

          常用鏈接

          留言簿(55)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 渑池县| 锡林郭勒盟| 东宁县| 增城市| 五寨县| 张家界市| 西城区| 扎赉特旗| 天等县| 嘉义市| 芷江| 延长县| 温泉县| 和静县| 大理市| 平远县| 嘉善县| 迭部县| 惠水县| 兴文县| 宁陵县| 广昌县| 阿巴嘎旗| 安国市| 红河县| 万源市| 延寿县| 尼木县| 抚顺县| 甘洛县| 密云县| 德阳市| 香港 | 顺昌县| 亚东县| 通辽市| 石城县| 新邵县| 武穴市| 建水县| 安仁县|