Search This Blog

Tuesday, October 28, 2014

Drag and Drop objects to a specific location using Sikuli

Sometimes we need to drag and drop objects in order to automate certain functionality.For Eg: dropping files into upload area in order to get uploaded. We use 'Actions' class in selenium whereas when we need to drop an image on a specific location on the screen, i prefer Sikuli. Below code describes it :

      @Test  
      public static void dragAndDrop() throws FindFailed{  
           Screen scr = new Screen();  
           Pattern pt=new Pattern("dest.png");  
           scr.wait(pt,10);  
           Region iregion=scr.find("dest.png");  
           iregion.dragDrop(iregion,iregion.offset(new Location(566,363)));  
      }  
     


Specific location on the screen can be indicated using 'Location' class.It accepts x-cord and y-cord and returns the region.It follows the below flow :

  • Prepare the pattern using the image
  • Wait for pattern to be visible on the screen
  • Create a Screen Object
  • Locate the image region using new Screen().find()
  • Use dragDrop() to move the region with the help of Location class.
Note: Please take a screenshot of the image and use it with the above code and use SIKULI-IDE to simulate before code.

No comments:

Post a Comment