2017-01-31 5 views
0

Я пытаюсь пронестись слева направо от первого содержания (нет содержимого слева) До сих пор я использую ниже, но он не работает ,Левый или правый салфетка не работает в appium для приложения для Android

public void swipeRightToLeft() { 
    JavascriptExecutor js = (JavascriptExecutor) driver; 
    HashMap<String, Double> swipeObject = new HashMap<String, Double>(); 
    swipeObject.put("startX", 0.9); 
    swipeObject.put("startY", 0.5); 
    swipeObject.put("endX", 0.01); 
    swipeObject.put("endY", 0.5); 
    swipeObject.put("duration", 3.0); 
    js.executeScript("mobile: swipe", swipeObject); 

} журнал

Ошибка: org.openqa.selenium.WebDriverException: Not yet implemented. Please help us: http://appium.io/get-involved.html (WARNING: The server did not provide any stacktrace information)

ответ

0
public void swipe(String direction, int offset, int time) { 

     int y = appiumDriver.manage().window().getSize().getHeight(); 
     int x = appiumDriver.manage().window().getSize().getWidth(); 
     TouchAction touchAction = new TouchAction(appiumDriver); 
     System.out.println(x + " " + y); 
     System.out.println("Entering swipe"); 
     if ("right".equalsIgnoreCase(direction)) { 
      System.out.println("Swipe Right"); 
      touchAction.press(x - offset, y/2).moveTo(-(x - (2 * offset)), 0).release().perform(); 
     } else if ("left".equalsIgnoreCase(direction)) { 
      System.out.println("Swipe Left"); 
      touchAction.press(offset, y/2).moveTo((x - (2 * offset)), 0).release().perform(); 
     } else if ("up".equalsIgnoreCase(direction)) { 
      System.out.println("Swipe Up"); 
      touchAction.press(x/2, offset).moveTo(0, y - (2 * offset)).release().perform(); 
     } else if ("down".equalsIgnoreCase(direction)) { 
      System.out.println("Swipe Down"); 
      touchAction.press(x/2, y - offset).moveTo(0, -(y - (2 * offset))).release().perform(); 
     } else { 
      throw new FrameworkException("Invalid direction"); 
     } 
     try { 
      Thread.sleep(2000); 
     } catch (InterruptedException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 
    } 

or 
    public void swipe(int startx, int starty, int endx, int endy, int duration) { 
     TouchAction touchAction = new TouchAction(appiumDriver); 
     System.out.println(startx + " " + starty); 
     System.out.println("Entering swipe"); 

     System.out.println("Swipe from " + startx + " " + starty + "to" + endx + " " + endy); 
     touchAction.press(startx, starty).waitAction(duration).moveTo(endx, endy).release().perform(); 
starty + "to" + endx + " " + endy); 
    }