How to use Selenium TouchActions with a RemoteWebDriver

前端 未结 1 2033
长情又很酷
长情又很酷 2021-01-28 02:32

I wrote some Javascript code with the touchstart and touchmove event. I want to test it using Selenium. I just discovered the TouchActions class with t

相关标签:
1条回答
  • 2021-01-28 02:55

    So, to be able to do that, one needs to first add the mobile capability to the driver (see 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);
    

    Then at the moment you need the touch actions, you need to "augment" the driver, to be able to cast it:

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

    Then from that builder you can do builder.down(), move(), scroll(), up()... whatever you need.

    0 讨论(0)
提交回复
热议问题