Sikuli with Selenium: Combine the power of both desktop and web automation

//http://sikuli.org/docx/faq/030-java-dev.html 
//http://sikuli.org/doc/java-x/

import org.sikuli.script.*;
import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.Point;
import org.openqa.selenium.firefox.*;
public class SikuliWithSelenium {
 /**
  * @param args
  */
 public static void main(String[] args) {
  // TODO Auto-generated method stub
  try {
   //Selenium code
   FirefoxProfile profile = new FirefoxProfile();     
   profile.setPreference("javascript.enabled", true); 
   FirefoxDriver fd = new FirefoxDriver(profile);

   fd.manage().window().setPosition(new Point(0,0));
   //java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
   //Dimension dim = new Dimension((int) screenSize.getWidth(), (int) screenSize.getHeight());
   Dimension dim = new Dimension((int) 1600, (int) 860);
   fd.manage().window().setSize(dim);
   fd.navigate().to("http://www.amazon.com/gp/flex/sign-out.html/ref=pd_irl_gw_r/?%5Fencoding=UTF8&path=%2Fgp%2Fyourstore&signIn=1&useRedirectOnSuccess=1&action=sign-out");
   fd.findElement(By.id("ap_email")).clear();
   CharSequence cs[] = { "xxxxxxxxxxxxxxxxxxxxx"};
   fd.findElement(By.id("ap_email")).sendKeys(cs);
   fd.findElement(By.id("ap_password")).clear();
   cs = new CharSequence[] {"xxxxxxxx"};
   fd.findElement(By.id("ap_password")).sendKeys(cs); 
   fd.findElement(By.id("signInSubmit")).click();
   fd.navigate().to("https://www.amazon.com/gp/css/account/address/view.html");

   //Sikuli code
   Settings.MinSimilarity = 0.9;
   ImageLocator.addImagePath("C:/Users/saikatd/workspace/SikuliWithSelenium/src/");
   Screen s = new Screen();
   s.wait("YourAccount.png", 180);
   s.hover("YourAccount.png");
   s.wait("SignOut.png", 180);
   s.click("SignOut.png", 0);
   Thread.sleep(10000);
   //Image comparison code
   //Finder comp = new Finder("SignOutPage1.png");
   Finder comp = new Finder(s.capture(518, 140, 566, 497).getFilename());
   comp.find("Subset.png", 0.9);
   if(comp.hasNext()) {
    System.out.println("Image matched");
   } else {
    System.out.println("Image didn't match");
   }
   fd.close();

  } catch (Exception e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
 }
}
Advertisements
This entry was posted in Information Technology. Bookmark the permalink.

One Response to Sikuli with Selenium: Combine the power of both desktop and web automation

  1. baba says:

    Disadvantages of using SIKULI in Selnium
    1. It limits the selenium RC, we can not use it remotely and it we can use selenium with sikuli as a standalone server
    2. It decreases the speed of selenium as sikuli click takes much more time compared to selenium click as sikuli first searches and matches then click.
    3. Sikuli takes more CPU resources than selenium

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s