Как прокрутить вид макета справа налево в Appium? - PullRequest
0 голосов
/ 09 мая 2019

Хочу смахнуть вид справа налево в Appium, я пытался с координатами, и динамически также пытался, но невозможно смахнуть вид, всякий раз, когда я смахну вид, появится один значок, я хочу, чтобыщелкните значок.

Мой тестовый пример выполнен, но я не могу смахнуть вид.Я попытался с TouchAction, используя co_ordinates.

         Boolean found_result = false;
         String a = "offlin";
         List<AndroidElement> listele = driver.findElementsByClassName("android.widget.LinearLayout");
         System.out.println("swipe = "+listele.size()); 

         int size=0;
         size = size+listele.size();
         AndroidElement slider = listele.get(0);
         Point startButtonPoint = slider.getLocation();
            Dimension startButtonDimenstion = slider.getSize();
         int y = startButtonPoint.getY() + startButtonDimenstion.getHeight()/2;
            int xStart = startButtonPoint.getX() + (int)(startButtonDimenstion.getWidth() * 0.7);
            int xEnd = (int)(startButtonPoint.getX() * 0.3);
         System.out.println("lists ele size"+size);
         for (int i = 0; i < size; i++) {

             String s = listele.get(i).getText();
             if (s.equals(a)) {

                 found_result =true;

                 driver.swipe(xStart, y, xEnd, y, 2000);
                  System.out.println("found : "+size);
                 break;
             }

         }
         if(!found_result){
             System.out.println("swipped cond");
      }

Как я и ожидал, хочу провести взглядом справа налево и после того, как один вид виден, Хотите нажать на представление, чтобы завершить задачу.

Ответы [ 3 ]

1 голос
/ 09 мая 2019
  1. Вы можете выполнить mobile:swipe команду , например:

    JavascriptExecutor js = (JavascriptExecutor) driver;
    Map<String, Object> params = new HashMap<>();
    params.put("direction", "down");
    params.put("element", ((RemoteWebElement) element).getId());
    js.executeScript("mobile: swipe", params);
    
  2. Если ваш тест только для Android, вы можете выполнить mobile:shell команду

    Map<String, Object> args = new HashMap<>();
    args.put("command", "input");
    args.put("args", Lists.newArrayList("swipe", "startX","startY","endX","endY"));
    driver.executeScript("mobile: shell", args);
    
  3. И последнее, но не по значению: вы можете использовать SeeTest Appium Extension , который предоставляет Swipe команду

    seetest.swipe("Right", 10, 500);
    
0 голосов
/ 15 мая 2019

Ниже приведен код, который я использую для прокрутки и пролистывания.Обратите внимание, что есть основной метод прокрутки, который вызывается с соответствующими параметрами, рассчитанными каждым из четырех методов направленной прокрутки / прокрутки.

/**
 * This method scrolls based upon the passed parameters
 * @author Bill Hileman
 * @param int startx - the starting x position
 * @param int starty - the starting y position
 * @param int endx - the ending x position
 * @param int endy - the ending y position
 */
@SuppressWarnings("rawtypes")
public void scroll(int startx, int starty, int endx, int endy) {

    TouchAction touchAction = new TouchAction(driver);

    touchAction.longPress(PointOption.point(startx, starty))
               .moveTo(PointOption.point(endx, endy))
               .release()
               .perform();

}

/**
 * This method does a swipe upwards
 * @author Bill Hileman
 */
public void scrollDown() {

    //The viewing size of the device
    Dimension size = driver.manage().window().getSize();

    //Starting y location set to 80% of the height (near bottom)
    int starty = (int) (size.height * 0.80);
    //Ending y location set to 20% of the height (near top)
    int endy = (int) (size.height * 0.20);
    //x position set to mid-screen horizontally
    int startx = (int) size.width / 2;

    scroll(startx, starty, startx, endy);

}

/**
 * This method does a swipe left
 * @author Bill Hileman
 */
public void swipeLeft() {

    //The viewing size of the device
    Dimension size = driver.manage().window().getSize();

    //Starting x location set to 95% of the width (near right)
    int startx = (int) (size.width * 0.95);
    //Ending x location set to 5% of the width (near left)
    int endx = (int) (size.width * 0.05);
    //y position set to mid-screen vertically
    int starty = size.height / 2;

    scroll(startx, starty, endx, starty);

}

/**
 * This method does a swipe right
 * @author Bill Hileman
 */
public void swipeRight() {

    //The viewing size of the device
    Dimension size = driver.manage().window().getSize();

    //Starting x location set to 5% of the width (near left)
    int startx = (int) (size.width * 0.05);
    //Ending x location set to 95% of the width (near right)
    int endx = (int) (size.width * 0.95);
    //y position set to mid-screen vertically
    int starty = size.height / 2;

    scroll(startx, starty, endx, starty);

}

/**
 * This method does a swipe downwards
 * @author Bill Hileman
 */
public void scrollUp() {

    //The viewing size of the device
    Dimension size = driver.manage().window().getSize();

    //Starting y location set to 20% of the height (near bottom)
    int starty = (int) (size.height * 0.20);
    //Ending y location set to 80% of the height (near top)
    int endy = (int) (size.height * 0.80);
    //x position set to mid-screen horizontally
    int startx = size.width / 2;

    scroll(startx, starty, startx, endy);

}
0 голосов
/ 10 мая 2019

Выполните пролистывание вправо в доступном виде, используя код ниже.

MobileElement element_to_be_swiped=driver.findElement("//xpathtothelinearpath")
Point elementLoc = elememt_to_be_swiped.getLocation();
int eleX = elementLoc.getX() + 5;
int eleY = elementLoc.getY() + 5;
Dimension elementDimen = elememt_to_be_swiped.getSize();
int eleH = elementDimen.getHeight();
int eleW = elementDimen.getWidth();
Dimension size = driver.manage().window().getSize();
int x = (int)(eleX + eleW * 0.5D);
int y = (int)(eleY + eleH * 0.5D);

TouchAction<?> action = new TouchAction(driver);
action.press(PointOption.point(x, y)).moveTo(PointOption.point(width - 5, y)).release().perform();
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...