gpt4 book ai didi

selenium - 如何将 Selenium TouchActions 与 RemoteWebDriver 结合使用

转载 作者:行者123 更新时间:2023-12-01 23:18:28 26 4
gpt4 key购买 nike

我使用 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 cannot be cast to org.openqa.selenium.interactions.HasTouchScreen

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

最佳答案

因此,为了能够做到这一点,需要首先向驱动程序添加移动功能(请参阅 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()... 任何您需要的操作。

关于selenium - 如何将 Selenium TouchActions 与 RemoteWebDriver 结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58339004/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com