0

I am stuck badly with the following issue, please help me out with a working solution.


For all touch actions I am getting

org.openqa.selenium.WebDriverException: unimplemented command: session/537d48a9dcdfb38a12ff318a302c9a08/touch/scroll Command duration or timeout: 8 milliseconds Build info: version: '2.42.2', revision: '6a6995d31c7c56c340d6f45a76976d43506cd6cc', time: '2014-06-03 10:52:47' System info: host: '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' Session ID: bbe122fa-f325-4142-a555-9d2f4ea60e02 Driver info: core.AppiumSwipeableDriver


public class AppiumSwipeableDriver extends AppiumDriver implements HasTouchScreen{ 
 public RemoteTouchScreen touch; 
 public AppiumSwipeableDriver(URL URL, Capabilities Cap) { 
 super(URL, Cap); 
 touch = new RemoteTouchScreen(getExecuteMethod()); 
} 

 @Override 
 public TouchScreen getTouch() { 
 return touch; 
 }
}

if(browser.equalsIgnoreCase("android")){
 DesiredCapabilities capabilities = new DesiredCapabilities();
 capabilities.setCapability(CapabilityType.BROWSER_NAME,"");
 capabilities.setCapability("deviceName","Android");
 capabilities.setCapability("device","Android");
 capabilities.setCapability("takesScreenshot","true");
 capabilities.setCapability("platformName","Android");
 capabilities.setCapability("platformVersion","4.4.2");
 capabilities.setCapability(CapabilityType.PLATFORM,"Mac");
 capabilities.setCapability("appPackage","uk.co.ee.myee");
 capabilities.setCapability("appActivity","uk.co.ee.myee.Launcher");
 capabilities.setCapability("udid","26d7be7b");
 driver = new AppiumSwipeableDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);
 touch = new TouchActions(driver);
 Set<String> contextNames = driver.getContextHandles();

 for (String contextName : contextNames) {
     if (contextName.contains("WEBVIEW_uk.co.ee.myee")){
         driver.context(contextName);
     }
   }


    public boolean TopUpRegisteredCard(){
     try{
     waitForVisible(By.xpath(OR.getProperty("wblTopUpWidget")),10);
     driver.findElement(By.xpath(OR.getProperty("wblTopUpWidget"))).click();   
     waitForVisible(By.xpath(OR.getProperty("btnTopUpRegisteredCard")),10);
     driver.findElement(By.xpath(OR.getProperty("btnTopUpRegisteredCard"))).click();
     waitForVisible(By.xpath(OR.getProperty("txtTopUpPaymentAmt")),10);
     driver.findElement(By.xpath(OR.getProperty("txtTopUpPaymentAmt"))).sendKeys("10");
     driver.findElement(By.xpath(OR.getProperty("txtTopUpCVVNum"))).sendKeys("123");
      touch.flick(driver.findElement(By.xpath(OR.getProperty("txtTopUpCVVNum"))),0,-250,1000).perform();
     waitForVisible(By.xpath(OR.getProperty("btnTopUpMakePayment")),10);
     driver.findElement(By.xpath(OR.getProperty("btnTopUpMakePayment"))).click();
     return true;

     }catch(Exception e){
     ReportTest.error(e.getMessage());
     return false;
     }

I have also tried with AppiumDriver - TouchAction and that gives me

org.openqa.selenium.UnsupportedCommandException: unknown command: session/9e5f0b55fdfb2c98dd019f44a7bf9c8a/touch/perform

I have ran the same scripts shown above successfully in a Windows machine,but now I have moved my project to a MAC and there after its not functioning as expected.

Please help me to get this fixed

user3000021
  • 288
  • 2
  • 3
  • 12

1 Answers1

0

Actually now Touch Actions are not supported for webview. But some workarounds are available; I am going to show it with a longpress example : I am using Pointoption because i will get the coordinate of element and will use it for 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();
}

For to get the coordinate of element i designed below methood

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

now you have a longpress(PointOption po) and getElementLocation(Webelement element) methods that gives you po value to use in longpress method. Now everything is ready and you can use them as below..

longpress(getElementLocation(driver.findElement(By.id("the selector can be any of them(xpath,css,classname,id etc.)")));
 
Hacci56
  • 39
  • 5