How to zoom in a mobile web using Appium

心已入冬 提交于 2019-12-12 04:43:02

问题


I have scenario in my project where I need to perform zoom in action Android Mobile web using Appium automation. I have used the following method.

try {
        Dimension size = driver.manage().window().getSize();
        int x0 = (int) (size.getWidth()*0.5);
        int y0 = (int) (size.getHeight()*0.5);
        System.out.println(x0+" "+y0);
        driver.zoom(100, 500);
        reportStep("The Application is zoomed.", "PASS");
    } catch (Exception e) {
        e.printStackTrace();
        reportStep("The Application could not be zoomed.", "FAIL");
    }

But this method working fine in Mobile apps and not working in Mobile web. Are there any specific method or alternate work around to handle the Mobile web zoom?

I am using Appium Java-client version 5.0.4 and Selenium version 3.6.0.

Zoom and Pinch methods are not available in the latest version.


回答1:


There are not many examples out there without zoom method, but using MultiTouchAction class in conjunction with TouchAction class should work as shown here. Note that using moveTo with WebElement and offset x,y coordinates instead of absolute is advised in that thread.

    driver = new AndroidDriver(new URL(nodeURL), capability);

    TouchAction  touchAction = new TouchAction(driver);
    MultiTouchAction  multiTouchAction = new MultiTouchAction(driver);

    WebElement search = (WebElement)   driver.findElement(MobileBy.AndroidUIAutomator("new UiSelector().resourceId(\"com.google.android.apps.maps:id/search_omnibox_container\")"));
     touchAction .tap(search).perform();

        int leftX = search.getLocation().getX();
        int rightX = search.getSize().getWidth() + leftX;


        int upperY = search.getLocation().getY();
        int lowerY = search.getSize().getHeight() + upperY;

       a1 = touchAction.press(search,x1,y1).waitAction(2000).moveTo(search,x3,y1).release();
       a2 = touchAction.press(search,x2,y1).waitAction(2000).moveTo(search,x4,y1).release();

       multiTouchAction.add(a1).add(a2).perform();

Also, look here for appium MultiTouch and here for passing offset x,y co-ordinates to moveTo



来源:https://stackoverflow.com/questions/47137607/how-to-zoom-in-a-mobile-web-using-appium

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!