Skip to content

Add touch actions to MobileDriver#487

Closed
kdaimiel wants to merge 12 commits into
appium:masterfrom
kdaimiel:master
Closed

Add touch actions to MobileDriver#487
kdaimiel wants to merge 12 commits into
appium:masterfrom
kdaimiel:master

Conversation

@kdaimiel

Copy link
Copy Markdown

Change list

Add support to TouchActions such as flick.

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Details

MobileDriver does not implement HasTouchScreen interface so TouchActions like flick get the error below. However, Appium supports this types of actions.

java.lang.ClassCastException: io.appium.java_client.android.AndroidDriver cannot be cast to org.openqa.selenium.interactions.HasTouchScreen
at org.openqa.selenium.interactions.touch.TouchActions.(TouchActions.java:38)
at amazon_tests.browser_test.SwipeCellsTest3.swipeCellsTestChromeDriverPatched(SwipeCellsTest3.java:45)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

@SrinivasanTarget

Copy link
Copy Markdown
Member

@kdaimiel I don't think so the above addition would really enable support for flick.

@SrinivasanTarget

Copy link
Copy Markdown
Member

@kdaimiel

Copy link
Copy Markdown
Author

@SrinivasanTarget I don't understand your comments. I just wanted to use TouchActions with an AndroidDriver instance, but I get the error above.

Here is an example:

import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileBrowserType;
import io.appium.java_client.remote.MobileCapabilityType;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.interactions.touch.TouchActions;

import java.net.URL;

public class SwipeBrowserTest {
private AppiumDriver driver;

@Before
public void testCaseSetup()throws Exception {

    DesiredCapabilities capabilities = new DesiredCapabilities();

    capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, MobileBrowserType.BROWSER);
    capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME,"Android");
    capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android device");
    capabilities.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, "30000");

    driver = new AndroidDriver<WebElement>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}

@Test
public void swipeTest()throws Exception {
    String swipeElement = "swipe";
    TouchActions action = new TouchActions(driver);
    action.flick(driver.findElementById(swipeElement), -100, 0, 1000);
    action.perform();
}

@After
public void testCaseTearDown() {
    driver.quit();
}

}

@SrinivasanTarget

Copy link
Copy Markdown
Member

@kdaimiel I was saying we aren't consuming TouchScreen API for any of our gestures. Also presently touchActions wont work for web views.

@kdaimiel

Copy link
Copy Markdown
Author

@SrinivasanTarget Ok. However, it is possible to use TouchActions in Chrome, it is supported after ChromeDriver 2.16. You can ckeck it on https://sites.google.com/a/chromium.org/chromedriver/downloads

@SrinivasanTarget

Copy link
Copy Markdown
Member

@kdaimiel Thats cool. Have you tried it?

@kdaimiel

kdaimiel commented Dec 7, 2016

Copy link
Copy Markdown
Author

@SrinivasanTarget Yes, I have tried it. I opened a similar pull request to Selenium project and it was accepted, SeleniumHQ/selenium#2694.

@SrinivasanTarget

Copy link
Copy Markdown
Member

Hmm ok @kdaimiel Fix the merge conflicts to port it and also can you add some tests?

@SrinivasanTarget

Copy link
Copy Markdown
Member

@SrinivasanTarget

Copy link
Copy Markdown
Member

@kdaimiel As said it would be great if you add some tests here webview + touchactions.

@kdaimiel

Copy link
Copy Markdown
Author

@SrinivasanTarget Where exactly do I add my tests? That will take me some time.

@SrinivasanTarget

Copy link
Copy Markdown
Member

@kdaimiel You can add one here

@SrinivasanTarget SrinivasanTarget left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May i know the reason for this removal? Do you have any other solutions or thoughts in mind? If so feel free to share.

@kdaimiel

Copy link
Copy Markdown
Author

@SrinivasanTarget Sorry, first I added TouchActions tests with others, however I decided to create a new class for this tests but I forgot to remove them from the other class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants