<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      appium 滑動

      前些日子,配置好了appium測試環境,至于環境怎么搭建,參考:http://www.rzrgm.cn/tobecrazy/p/4562199.html

                          知乎Android客戶端登陸:http://www.rzrgm.cn/tobecrazy/p/4579631.html

                                                        appium實現截圖和清空EditText:http://www.rzrgm.cn/tobecrazy/p/4592405.html

       

             

      Appium 處理滑動 

      appium 處理滑動的方法是 swipe(int start-x, int start-y, int end-x, int end-y, int during) - Method in class io.appium.java_client.AppiumDriver
      此方法共有5個參數,都是整形,依次是起始位置的x y坐標和終點位子的x y坐標和滑動間隔時間,單位毫秒
      坐標是指:屏幕左上角為坐標系原點(0,0),屏幕分辨率為終點坐標,比如你手機分辨率1080*1920,那么該手機坐標系的終點是(1080*1920)
      ,每個元素都在坐標系中,可以用坐標系定位元素。
                
      比如這個登陸按鈕在坐標系中的位置是起始點 + 終點(32,1040) (351,1152)

      向上滑動

      向上滑動,就是從下到上,那么怎么進行從下到上的滑動呢?
      按照之前理解的坐標系,從上到下滑動,一般是垂直滑動,也就是X軸不變,Y軸從大變小的過程
      我們可以采取Y軸固定在屏幕正當中,Y軸滑動屏幕的1/2,Y軸的起始位置為屏幕的3/4,滑動終點為Y軸的1/4(盡量避免使用坐標系的起點和終點),滑動時間為1s,如果滑動時間過短,將會出現一次滑動多頁。
      需要提醒的是,很多app運行的時候并不是全屏,還有系統自帶工具欄和邊框,一定要避免!!!
        
          driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
      
              
              // find keyword 首頁 and verify it is display
              Assert.assertTrue(driver.findElement(By.name("首頁")).isDisplayed());
              snapshot((TakesScreenshot) driver, "zhihu_before_swipe.png");
              int width=driver.manage().window().getSize().width;
              int height=driver.manage().window().getSize().height;  
              driver.swipe(width/2,height*3/4, width/2,height/4, 1000);
              //wait for page loading
              
              snapshot((TakesScreenshot) driver, "zhihu_after_swipe.png");

       

       可以看出 ,為了讓apppium 更好的兼容不同分辨率的設備,在執行滑動前先獲取屏幕的分辨率
      接下來就可以封裝四個滑動的方法:
      /**
           * This Method for swipe up
           * 
           * @author Young
           * @param driver
           * @param during
           */
          public void swipeToUp(AndroidDriver driver, int during) {
              int width = driver.manage().window().getSize().width;
              int height = driver.manage().window().getSize().height;
              driver.swipe(width / 2, height * 3 / 4, width / 2, height / 4, during);
              // wait for page loading
          }
      
          /**
           * This Method for swipe down
           * 
           * @author Young
           * @param driver
           * @param during
           */
          public void swipeToDown(AndroidDriver driver, int during) {
              int width = driver.manage().window().getSize().width;
              int height = driver.manage().window().getSize().height;
              driver.swipe(width / 2, height / 4, width / 2, height * 3 / 4, during);
              // wait for page loading
          }
      
          /**
           * This Method for swipe Left
           * 
           * @author Young
           * @param driver
           * @param during
           */
          public void swipeToLeft(AndroidDriver driver, int during) {
              int width = driver.manage().window().getSize().width;
              int height = driver.manage().window().getSize().height;
              driver.swipe(width * 3 / 4, height / 2, width / 4, height / 2, during);
              // wait for page loading
          }
      
          /**
           * This Method for swipe Right
           * 
           * @author Young
           * @param driver
           * @param during
           */
          public void swipeToRight(AndroidDriver driver, int during) {
              int width = driver.manage().window().getSize().width;
              int height = driver.manage().window().getSize().height;
              driver.swipe(width / 4, height / 2, width * 3 / 4, height / 2, during);
              // wait for page loading
          }

       


       

      最后來測試一下這幾個滑動方法:
      package com.dbyl.core;
      
      import org.apache.commons.io.FileUtils;
      import org.openqa.selenium.By;
      import org.openqa.selenium.NoSuchElementException;
      import org.openqa.selenium.OutputType;
      import org.openqa.selenium.TakesScreenshot;
      import org.openqa.selenium.WebElement;
      import org.openqa.selenium.remote.CapabilityType;
      import org.openqa.selenium.remote.DesiredCapabilities;
      import org.testng.Assert;
      import org.testng.annotations.AfterClass;
      import org.testng.annotations.BeforeClass;
      import org.testng.annotations.Test;
      
      import io.appium.java_client.android.AndroidDriver;
      
      import java.io.File;
      import java.io.IOException;
      import java.net.URL;
      import java.util.List;
      import java.util.concurrent.TimeUnit;
      
      public class zhiHu {
          private AndroidDriver driver;
          private boolean isInstall = false;
      
          /**
           * @author Young
           * @throws IOException
           */
          public void startRecord() throws IOException {
              Runtime rt = Runtime.getRuntime();
              // this code for record the screen of your device
              rt.exec("cmd.exe /C adb shell screenrecord /sdcard/runCase.mp4");
      
          }
      
          @BeforeClass(alwaysRun = true)
          public void setUp() throws Exception {
              // set up appium
      
              DesiredCapabilities capabilities = new DesiredCapabilities();
              capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
              capabilities.setCapability("platformName", "Android");
              capabilities.setCapability("deviceName", "Android Emulator");
              capabilities.setCapability("platformVersion", "4.4");
              // if no need install don't add this
              if (isInstall) {
                  File classpathRoot = new File(System.getProperty("user.dir"));
                  File appDir = new File(classpathRoot, "apps");
                  File app = new File(appDir, "zhihu.apk");
                  capabilities.setCapability("app", app.getAbsolutePath());
              }
              capabilities.setCapability("appPackage", "com.zhihu.android");
              // support Chinese
              capabilities.setCapability("unicodeKeyboard", "True");
              capabilities.setCapability("resetKeyboard", "True");
              // no need sign
              capabilities.setCapability("noSign", "True");
              capabilities.setCapability("appActivity", ".ui.activity.GuideActivity");
              driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),
                      capabilities);
              startRecord();
          }
      
          public void login() {
      
              WebElement loginButton;
              if (isLoginPresent(driver, 60)) {
                  loginButton = driver.findElement(By
                          .id("com.zhihu.android:id/login"));
                  loginButton.click();
              }
      
              else {
                  Assert.assertTrue(false);
              }
      
              // wait for 20s
              driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
      
              // find login userName and password editText
              List<WebElement> textFieldsList = driver
                      .findElementsByClassName("android.widget.EditText");
              textFieldsList.get(0).sendKeys("seleniumcookies@126.com");
              textFieldsList.get(1).sendKeys("cookies123");
              driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
      
              // find ok button byName
              driver.findElementById("android:id/button1").click();
              driver.manage().timeouts().implicitlyWait(90, TimeUnit.SECONDS);
      
              // find keyword 首頁 and verify it is display
              Assert.assertTrue(driver.findElement(By.name("首頁")).isDisplayed());
      
          }
      
          public boolean isLoginPresent(AndroidDriver driver, int timeout) {
              boolean isPresent = new AndroidDriverWait(driver, timeout).until(
                      new ExpectedCondition<WebElement>() {
                          public WebElement apply(AndroidDriver d) {
                              return d.findElement(By
                                      .id("com.zhihu.android:id/login"));
                          }
      
                      }).isDisplayed();
              return isPresent;
          }
      
          @Test(groups = "swipeTest", priority = 1)
          public void swipe() {
      
              // find login button
              if (isInstall) {
                  login();
              }
              driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
      
              // find keyword 首頁 and verify it is display
              Assert.assertTrue(driver.findElement(By.name("首頁")).isDisplayed());
              snapshot((TakesScreenshot) driver, "zhihu_before_swipe.png");
              swipeToUp(driver, 500);
              snapshot((TakesScreenshot) driver, "zhihu_after_swipe.png");
      
              driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
      
              swipeToDown(driver, 1000);
              driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
              List<WebElement> titles = driver
                      .findElementsById("com.zhihu.android:id/title");
              titles.get(0).click();
              driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
              
              //swipe to right
              swipeToRight(driver, 100);
      
              driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
              // find keyword 首頁 and verify it is display
              Assert.assertTrue(driver.findElement(By.name("首頁")).isDisplayed());
          }
      
          /**
           * This Method for swipe up
           * 
           * @author Young
           * @param driver
           * @param during
           */
          public void swipeToUp(AndroidDriver driver, int during) {
              int width = driver.manage().window().getSize().width;
              int height = driver.manage().window().getSize().height;
              driver.swipe(width / 2, height * 3 / 4, width / 2, height / 4, during);
              // wait for page loading
          }
      
          /**
           * This Method for swipe down
           * 
           * @author Young
           * @param driver
           * @param during
           */
          public void swipeToDown(AndroidDriver driver, int during) {
              int width = driver.manage().window().getSize().width;
              int height = driver.manage().window().getSize().height;
              driver.swipe(width / 2, height / 4, width / 2, height * 3 / 4, during);
              // wait for page loading
          }
      
          /**
           * This Method for swipe Left
           * 
           * @author Young
           * @param driver
           * @param during
           */
          public void swipeToLeft(AndroidDriver driver, int during) {
              int width = driver.manage().window().getSize().width;
              int height = driver.manage().window().getSize().height;
              driver.swipe(width * 3 / 4, height / 2, width / 4, height / 2, during);
              // wait for page loading
          }
      
          /**
           * This Method for swipe Right
           * 
           * @author Young
           * @param driver
           * @param during
           */
          public void swipeToRight(AndroidDriver driver, int during) {
              int width = driver.manage().window().getSize().width;
              int height = driver.manage().window().getSize().height;
              driver.swipe(width / 4, height / 2, width * 3 / 4, height / 2, during);
              // wait for page loading
          }
      
          @Test(groups = { "profileSetting" }, priority = 2)
          public void profileSetting() {
      
              driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
              // find keyword 首頁 and verify it is display
              Assert.assertTrue(driver.findElement(By.name("首頁")).isDisplayed());
      
              driver.swipe(100, 400, 100, 200, 500);
              WebElement myButton = driver.findElement(By
                      .className("android.widget.ImageButton"));
              myButton.click();
              driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
              driver.swipe(700, 500, 100, 500, 10);
              driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
              List<WebElement> textViews = driver
                      .findElementsByClassName("android.widget.TextView");
              textViews.get(0).click();
              driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
      
              driver.findElementById("com.zhihu.android:id/name").click();
              driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
      
              // wait for 60s if WebElemnt show up less than 60s , then return , until
              // 60s
      
              By by = new By.ById("com.zhihu.android:id/showcase_close");
      
              snapshot((TakesScreenshot) driver, "zhihu_showClose.png");
              if (isElementPresent(by, 30)) {
                  driver.findElement(by).click();
              }
      
              Assert.assertTrue(driver
                      .findElementsByClassName("android.widget.TextView").get(0)
                      .getText().contains("selenium"));
      
              driver.findElementById("com.zhihu.android:id/menu_people_edit").click();
              driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
              WebElement intro = driver
                      .findElementById("com.zhihu.android:id/introduction");
              intro.click();
              driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
              WebElement content = driver
                      .findElementById("com.zhihu.android:id/content");
              String text = content.getAttribute("text");
              content.click();
              clearText(text);
              content.sendKeys("Appium Test. Create By Young");
      
              driver.findElementById("com.zhihu.android:id/menu_question_done")
                      .click();
      
              WebElement explanation = driver
                      .findElementById("com.zhihu.android:id/explanation");
              explanation.click();
              driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
              content = driver.findElementById("com.zhihu.android:id/content");
              text = content.getAttribute("text");
              content.click();
              clearText(text);
              content.sendKeys("Appium Test. Create By Young. This is an appium type hahahahah");
      
              driver.findElementById("com.zhihu.android:id/menu_question_done")
                      .click();
              snapshot((TakesScreenshot) driver, "zhihu.png");
      
          }
      
          /**
           * This method for delete text in textView
           * 
           * @author Young
           * @param text
           */
          public void clearText(String text) {
              driver.sendKeyEvent(123);
              for (int i = 0; i < text.length(); i++) {
                  driver.sendKeyEvent(67);
              }
          }
      
          @AfterClass(alwaysRun = true)
          public void tearDown() throws Exception {
              driver.quit();
          }
      
          /**
           * This Method create for take screenshot
           * 
           * @author Young
           * @param drivername
           * @param filename
           */
          public static void snapshot(TakesScreenshot drivername, String filename) {
              // this method will take screen shot ,require two parameters ,one is
              // driver name, another is file name
      
              String currentPath = System.getProperty("user.dir"); // get current work
                                                                      // folder
              File scrFile = drivername.getScreenshotAs(OutputType.FILE);
              // Now you can do whatever you need to do with it, for example copy
              // somewhere
              try {
                  System.out.println("save snapshot path is:" + currentPath + "/"
                          + filename);
                  FileUtils
                          .copyFile(scrFile, new File(currentPath + "\\" + filename));
              } catch (IOException e) {
                  System.out.println("Can't save screenshot");
                  e.printStackTrace();
              } finally {
                  System.out.println("screen shot finished, it's in " + currentPath
                          + " folder");
              }
          }
      
          /**
           * 
           * @param by
           * @param timeOut
           * @return
           */
          public boolean isElementPresent(final By by, int timeOut) {
              try {
                  new AndroidDriverWait(driver, timeOut)
                          .until(new ExpectedCondition<WebElement>() {
                              public WebElement apply(AndroidDriver d) {
                                  return d.findElement(by);
                              }
      
                          });
                  return true;
              } catch (Exception e) {
                  return false;
              }
      
          }
      }

      整個過程會按照先向下,向上,向右滑動。

      有了這個滑動方法,能不能做一些更高級的事?

      答案將在明天揭曉,swipe 

       
      posted @ 2015-07-01 23:12  to be crazy  閱讀(27670)  評論(7)    收藏  舉報
      主站蜘蛛池模板: 香港日本三级亚洲三级| 国产旡码高清一区二区三区| 中文日产幕无线码一区中文| 国产精品自拍实拍在线看| 久久男人av资源网站| 99精品人妻少妇一区| 成人精品一区日本无码网| 日韩一区二区三在线观看| 久久99热只有频精品6狠狠| 国产精品午夜福利在线观看 | 久久超碰色中文字幕超清| 日本一本正道综合久久dvd| 狠狠色丁香婷婷综合尤物| 国产青榴视频在线观看| 亚洲人妻一区二区精品| 老色鬼在线精品视频在线观看| 国产美女高潮流白浆视频| 欧美丰满妇大ass| 少妇仑乱a毛片无码| 亚洲成人av在线综合| 亚洲人成网线在线播放VA| 久久亚洲国产欧洲精品一| 美女胸18下看禁止免费视频| 亚洲国产精品一区二区三| 国产做爰xxxⅹ久久久精华液| 激情内射亚洲一区二区三区| 国产AV巨作丝袜秘书| 伊人久久大香线蕉网av| 亚洲国产精品一二三区| 永久免费无码网站在线观看| 亚洲熟女乱色一区二区三区| 97人妻天天爽夜夜爽二区 | 亚洲av高清一区二区三| 欧洲美熟女乱又伦免费视频| 欧美成人午夜在线观看视频| 一面膜上边一面膜下边视频| 色综合色狠狠天天综合网| 国产成人高清精品亚洲| 乌鲁木齐市| 久久精品国产久精国产| 一本色道国产在线观看二区|