【问题标题】:How to use Selenium TouchActions with a RemoteWebDriver如何将 Selenium TouchActions 与 RemoteWebDriver 一起使用
【发布时间】:2023-03-22 17:25:01
【问题描述】:

我用touchstarttouchmove 事件编写了一些Javascript 代码。我想使用 Selenium 对其进行测试。我刚刚发现了 TouchActions 类和 move 方法,这似乎正是我想要的。

我的测试使用RemoteWebDriver 运行:

RemoteWebDriver remoteWebDriver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);

驱动程序将是 ChromeDriver 或最终是 FirefoxDriver,而不是 AndroidDriver

当我尝试使用以下命令初始化操作时:

TouchActions builder = new TouchActions(remoteWebDriver);

我得到一个转换错误:

java.lang.ClassCastException: org.openqa.selenium.remote.RemoteWebDriver 无法转换为 org.openqa.selenium.interactions.HasTouchScreen

有人知道我应该做什么吗?有我需要添加的功能吗?

【问题讨论】:

    标签: selenium selenium-webdriver mobile selenium-chromedriver touch


    【解决方案1】:

    因此,要做到这一点,首先需要将移动功能添加到驱动程序(请参阅Mobile Emulation):

    Map<String, String> mobileEmulation = new HashMap<>();
    mobileEmulation.put("deviceName", "Galaxy S5"); // Choose a device available in your version of chromimum
    Map<String, Object> options = new HashMap<>();
    options.put("mobileEmulation", mobileEmulation);
    capabilities.setCapability(ChromeOptions.CAPABILITY, options);
    RemoteWebDriver remoteWebDriver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
    

    那么在您需要触摸动作的那一刻,您需要“增强”驱动程序,以便能够对其进行投射:

    TouchActions builder = new TouchActions(new Augmenter().augment(remoteWebDriver));

    然后,您可以通过该构建器执行 builder.down(), move(), scroll(), up()... 任何您需要的操作。

    【讨论】:

    • 它也支持真正的移动设备吗? safari 浏览器可以提到相同的功能吗?
    猜你喜欢
    • 2012-03-21
    • 1970-01-01
    • 2016-12-11
    • 2022-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-31
    • 1970-01-01
    相关资源
    最近更新 更多