How to perform drag and drop in android application using Appium?

Download Drag-Sort Demos app from Google Play Store  to perform drag and drop operation in android device and install device or Genymotion emulator.
Please visit below URL to download apk file from Google play Store
https://hiromia.blogspot.com/2017/02/how-to-download-android-apk-file-from.html

Before drag and drop

After drag and drop

 import io.appium.java_client.MobileDriver;  
 import io.appium.java_client.TouchAction;  
 import io.appium.java_client.android.AndroidDriver;  
   
 import org.openqa.selenium.By;  
 import org.openqa.selenium.WebDriver;  
 import org.openqa.selenium.WebElement;  
 import org.openqa.selenium.remote.CapabilityType;  
 import org.openqa.selenium.remote.DesiredCapabilities;  
   
 import java.net.MalformedURLException;  
 import java.net.URL;  
 import java.util.concurrent.TimeUnit;  
   
   
 public class DrapandDrop {  
   
   private static AndroidDriver driver;  
   
   public static void main(String []arg) throws MalformedURLException, InterruptedException {  
       
     // Created object of DesiredCapabilities class.  
     DesiredCapabilities capabilities = new DesiredCapabilities();  
   
     // Set android deviceName desired capability. Set genymotion emulator name.  
     capabilities.setCapability("deviceName", "192.168.56.101:5555");  
   
     // Set android platformName desired capability. It's Android in our case here.  
     capabilities.setCapability("platformName", "Android");  
   
     // Set android VERSION desired capability. Set genymotion emulator OS version.  
     capabilities.setCapability(CapabilityType.VERSION, "6.0.0");  
   
     // Set BROWSER_NAME desired capability. It's Android in our case here.  
     capabilities.setCapability(CapabilityType.BROWSER_NAME, "Android");  
   
     // Java package of the tested Android app  
     capabilities.setCapability("appPackage", "com.mobeta.android.demodslv");  
   
     // An activity name for the Android activity you want to run from your package.  
     capabilities.setCapability("appActivity", "com.mobeta.android.demodslv.Launcher");  
   
     driver = new AndroidDriver(new URL("http://0.0.0.0:4723/wd/hub"), capabilities);  
   
     driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);  
   
     //Tap on first element.  
     driver.findElementById("com.mobeta.android.demodslv:id/activity_title").click();  
   
     //Locate 4th element from list to drag.  
     WebElement webElement1=(WebElement) driver.findElementsById("com.mobeta.android.demodslv:id/drag_handle").get(3);  
   
     //Locate 6th element to drop dragged element.  
     WebElement webElement2=(WebElement) driver.findElementsById("com.mobeta.android.demodslv:id/drag_handle").get(6);  
   
   
     //Perform drag and drop operation using TouchAction class.  
   
     //Created object of TouchAction class.  
     TouchAction action=new TouchAction((MobileDriver) driver);  
     //It will hold tap on 4th element and move to 7th position and then release tap.  
      action.longPress(webElement1).moveTo(webElement2).release().perform();  
   
      Thread.sleep(2000);  
   
      driver.quit();  
   
   }  
 }  
   

34 comments:

  1. Really i like this blog and i got lot of information's from your blog.And thanks for sharing!!!!
    Iperidigi
    SEO Company in Chennai
    SEO Company in India

    ReplyDelete
  2. Hi, your article really nice. That is so logical and clearly explained. Keep it up! I will follow up your blog for the future post.
    It was a wonderful chance to visit this kind of site and I am happy to know. thank you so much.
    Isoft Innovations Company Address
    Isoft Innovations Adyar
    Isoft Innovations Chennai
    Isoft Innovations

    ReplyDelete
  3. I’ve been browsing on-line greater than three hours today, but I never discovered any attention-grabbing article like yours. It is beautiful worth sufficient for me. Personally, if all webmasters and bloggers made good content material as you did, the net will be a lot more helpful than ever before.
    Logistic ERP
    Fleet Management Software
    Warehouse Management Software
    Human resources management software

    ReplyDelete
  4. Outstanding blog thanks for sharing such wonderful blog with us ,after long time came across such knowlegeble blog. keep sharing such informative blog with us.
    Airport Ground Staff Training Courses in Chennai | Airport Ground Staff Training in Chennai | Ground Staff Training in Chennai

    ReplyDelete
  5. I am really enjoying reading your well written articles.
    It looks like you spend a lot of effort and time on your blog.
    I have bookmarked it and I am looking forward to reading new articles. Keep up the good work..
    Best Spoken English Classes in Bangalore
    Best English Coaching Center in Chennai
    Spoken English in Bangalore
    Spoken English Institutes in Bangalore
    English Speaking Classes in Bangalore

    ReplyDelete
  6. Thanks for sharing,this blog makes me to learn new thinks.
    interesting to read and understand.keep updating it.
    AWS Courses in T nagar
    AWS Course in Anna Nagar
    AWS Course in Bangalore

    ReplyDelete
  7. This information is impressive. I am inspired with your post writing style & how continuously you describe this topic. Eagerly waiting for your new blog keep doing more.
    Android Training in Bangalore
    Android Course in Bangalore
    Angularjs Training Institute in Bangalore
    Angularjs Classes in Bangalore
    Angularjs Coaching in Bangalore

    ReplyDelete
  8. I wondered upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I’ll be subscribing to your feed and I hope you post again soon.
    Selenium Training in Chennai
    software testing training institute chennai
    Selenium testing training
    Selenium Courses in Chennai
    Best Software Testing Training Institute in Chennai
    Testing training

    ReplyDelete
  9. Thank you sharing this kind of noteworthy information. Nice Post.

    sustainable-hyderabad
    Guest posting sites

    ReplyDelete
  10. Very nice thanks for posting
    https://www.slajobs.com/advanced-excel-vba-training-in-chennai/

    ReplyDelete
  11. I learn some new stuff from it too, thanks for sharing your information. XE88

    ReplyDelete
  12. This is a great post I saw thanks to sharing. I really want to hope that you will continue to share great posts in the future.
    HRDF training

    ReplyDelete
  13. I am stunned by the information that you have on this blog. It shows how well you fathom this subject.
    training provider in malaysia

    ReplyDelete
  14. i am glad to discover this page : i have to thank you for the time i spent on this especially great reading !! i really liked each part and also bookmarked you for new information on your site.
    QA Companies
    Automation Testing Companies
    Mobile App Testing Companies
    Performance Testing Companies
    Security Testing Companies

    ReplyDelete
  15. You completely match our expectation and the variety of our information.
    cyber security training malaysia

    ReplyDelete