如何使用Appium放大移动网络 [英] How to zoom in a mobile web using Appium

查看:131
本文介绍了如何使用Appium放大移动网络的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目中有一个场景,我需要使用Appium自动化功能来放大动作Android Mobile web.我使用了以下方法.

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");
    }

但是此方法在Mobile应用程序中工作正常,而在Mobile Web中不工作. 是否有任何特定方法或替代方法来处理移动网络缩放?

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?

我正在使用Appium Java客户端版本5.0.4和Selenium版本3.6.0.

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.

推荐答案

没有zoom方法但使用此处.请注意,建议在该线程中使用moveToWebElement并偏移x,y坐标,而不是绝对坐标.

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();

此外,请在此处适用于appium MultiTouch和此处,用于将偏移x,y坐标传递给moveTo

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

这篇关于如何使用Appium放大移动网络的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆