Selenium 在使用Appium从Mac运行测试时,无法在webview中执行触控操作
我被以下问题严重困扰,请帮助我找到一个可行的解决方案Selenium 在使用Appium从Mac运行测试时,无法在webview中执行触控操作,selenium,testng,appium,selendroid,Selenium,Testng,Appium,Selendroid,我被以下问题严重困扰,请帮助我找到一个可行的解决方案 对于我所有的触摸动作 org.openqa.selenium.WebDriverException:未实现的命令:session/537d48a9dcdfb38a12ff318a302c9a08/touch/scroll 命令持续时间或超时:8毫秒 构建信息:版本:“2.42.2”,修订版:“6A6995D31C7C56C340D6F45A7676D43506CD6CC”,时间:“2014-06-03 10:52:47” 系统信息:主机:'
对于我所有的触摸动作 org.openqa.selenium.WebDriverException:未实现的命令:session/537d48a9dcdfb38a12ff318a302c9a08/touch/scroll 命令持续时间或超时:8毫秒 构建信息:版本:“2.42.2”,修订版:“6A6995D31C7C56C340D6F45A7676D43506CD6CC”,时间:“2014-06-03 10:52:47” 系统信息:主机:'Praveen Prabhus MacBook Pro.local',ip:'192.168.0.42',os.name:'Mac os X',os.arch:'x86_64',os.version:'10.9.4',java.version:'1.7.0_65' 会话ID:bbe122fa-f325-4142-a555-9d2f4ea60e02 驱动程序信息:core.AppiumSwipeableDriver
公共类AppiumSwipeableDriver扩展了AppiumDriver实现了触摸屏{
公共遥控触摸屏;
公共AppiumSwipeableDriver(URL,能力上限){
超级(网址,上限);
触摸=新的远程触摸屏(getExecuteMethod());
}
@凌驾
公共触摸屏getTouch(){
回击;
}
}
if(browser.equalsIgnoreCase(“android”)){
DesiredCapabilities=新的DesiredCapabilities();
setCapability(CapabilityType.BROWSER_NAME,“”);
setCapability(“deviceName”、“Android”);
能力。设置能力(“设备”、“安卓”);
能力。设置能力(“takesScreenshot”、“true”);
能力。设置能力(“平台名”、“安卓”);
能力。设置能力(“平台版”、“4.4.2”);
能力.setCapability(CapabilityType.PLATFORM,“Mac”);
能力。设置能力(“appPackage”、“uk.co.ee.myee”);
设置能力(“appActivity”,“uk.co.ee.myee.Launcher”);
能力。设置能力(“udid”、“26d7be7b”);
驱动程序=新的AppiumSwipeableDriver(新的URL(“http://127.0.0.1:4723/wd/hub(能力),;
触摸=新触摸动作(驾驶员);
设置contextNames=driver.getContextHandles();
for(字符串contextName:contextName){
if(contextName.contains(“WEBVIEW_uk.co.ee.myee”)){
驱动程序上下文(contextName);
}
}
公共布尔值TopUpRegisteredCard(){
试一试{
waitForVisible(By.xpath(或.getProperty(“wblTopUpWidget”)),10);
driver.findElement(By.xpath(或.getProperty(“wblTopUpWidget”)))。单击();
waitForVisible(By.xpath(或.getProperty(“btnTopUpRegisteredCard”)),10);
driver.findElement(By.xpath(或.getProperty(“btnTopUpRegisteredCard”))。单击();
waitForVisible(By.xpath(或.getProperty(“txttouppaymentamt”)),10);
driver.findElement(By.xpath(或.getProperty(“txttouppaymentamt”)).sendKeys(“10”);
driver.findElement(By.xpath(或.getProperty(“txttopupcvnum”))).sendKeys(“123”);
flick(driver.findelelement(By.xpath(或.getProperty(“txttopupcvnum”))),0,-2501000.perform();
waitForVisible(By.xpath(或.getProperty(“btnTopUpMakePayment”)),10);
driver.findElement(By.xpath(或.getProperty(“btntoppupmakepayment”)))。单击();
返回true;
}捕获(例外e){
ReportTest.error(如getMessage());
返回false;
}
我也尝试过AppiumDriver-TouchAction,这让我
org.openqa.selenium.unsupportedCommand异常:未知命令:session/9e5f0b55fdfb2c98dd019f44a7bf9c8a/touch/perform
我已经在Windows机器上成功地运行了上面所示的相同脚本,但现在我已经将我的项目移动到MAC上,在它没有按预期运行之后
请帮助我修复此问题事实上,现在webview不支持触摸操作。但有一些解决方法可用;我将用longpress示例演示:我使用Pointoption,因为我将获得元素的坐标,并将其用于longpress
public void longpress(PointOption po) {
//first you need to switch to native view
driver.switchToNativeView();
TouchAction action = new TouchAction((PerformsTouchActions) driver);
action.longPress(po).waitAction(WaitOptions.waitOptions(Duration.ofSeconds(2)));
action.release();
action.perform();
driver.switchToDefaultWebView();
}
为了得到我在下面设计的元素的坐标
public PointOption getElementLocation(WebElement element) {
int elementLocationX;
int elementLocationY;
//get element location in webview
elementLocationX = element.getLocation().getX();
elementLocationY = element.getLocation().getY();
//get the center location of the element
int elementWidthCenter = element.getSize().getWidth() / 2;
int elementHeightCenter = element.getSize().getHeight() / 2;
int elementWidthCenterLocation = elementWidthCenter + elementLocationX;
int elementHeightCenterLocation = elementHeightCenter + elementLocationY;
//calculate the ratio between actual screen dimensions and webview dimensions
float ratioWidth = device.getDeviceScreenWidth() / ((MobileDevice) device)
.getWebViewWidth().intValue();
float ratioHeight = device.getDeviceScreenHeight() / ((MobileDevice) device)
.getWebViewHeight().intValue();
//calculate the actual element location on the screen , if needed you can increase this value,for example i used 115 for one of my mobile devices.
int offset = 0;
float elementCenterActualX = elementWidthCenterLocation * ratioWidth;
float elementCenterActualY = (elementHeightCenterLocation * ratioHeight) + offset;
float[] elementLocation = {elementCenterActualX, elementCenterActualY};
int elementCoordinateX, elementCoordinateY;
elementCoordinateX = (int) Math.round(elementCenterActualX);
elementCoordinateY = (int) Math.round(elementCenterActualY);
PointOption po = PointOption.point(elementCoordinateX, elementCoordinateY);
return po;
}
现在您有了longpress(PointOption po)和getElementLocation(Webelement element)方法,它们为您提供了在longpress方法中使用的po值。现在一切就绪,您可以按如下方式使用它们
longpress(getElementLocation(driver.findElement(By.id("the selector can be any of them(xpath,css,classname,id etc.)")));
我的直觉告诉我你的Appium驱动已经过时了,我正在POM io.Appium java客户端最新测试中使用以下内容
longpress(getElementLocation(driver.findElement(By.id("the selector can be any of them(xpath,css,classname,id etc.)")));