Some time we need to integrate different API with Selenium WebDriver to automate our application.
Here we learn how to integrate Sikuli with Selenium Web Driver.Now question should arise
1.What is sikuli?
Ans:-It is an image based GUI Automation tool.
2.How to integrate Sikuli with Selenium Webdriver?
Ans:-There is 2 way to integrate sikuli with selenium webdriver
i. Install Sikuli and add this jar(which is on installation path) into our selenium webdriver project.
ii. Another way is add sikuli-api-1.0.2-standalone.jar from Sikuli Java API download page.
We start with second one we may learn first one later.
Step1:
First of all we download sikuli-api-1.0.2-standalone.jar.
Step2:
Add this jar into our Selenium WebDriver project.
Step3:
We know that Sikuli is image based automation tool.So Sikuli understand only picture so on which element we want to click need to save as picture.
Step4:
Now we write the code as given below to automate the Google Search page. Here we type "abcd" on search box and click on search button then we click the link using sikuli.Here one thing should be considered that we should taken the screen shot of the link previously and screenshot text should be present on search.
public static void main(String args[]) throws IOException {
WebDriver driver = new FirefoxDriver();
driver.get("https://www.google.com");
driver.findElement(By.name("q")).sendKeys("abcd");
driver.findElement(By.id("gbqfb")).click();
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id='rso']/li[1]/div/h3/a")));
/*
* We Define the Screen region
* as Desktop Screen region.
*/
ScreenRegion s = new DesktopScreenRegion();
/*
* We need to capture the Image
* and save this as png file extention
*/
ImageIO.write(s.capture(), "png", new File("E:\\Sikuli\\saved.png"));
driver.manage().window().maximize();
/*
* We need to load the picture
* on which we click for automation
*/
Target tg=new ImageTarget(new File("E:\\Sikuli\\1.png"));
/*
* Again we Define the Screen region
* as Desktop Screen region because we
* maximize the screen.
*/
ScreenRegion sr=new DesktopScreenRegion();
/*
* Initialize the mouse to click on element
*/
Mouse mouse=new DesktopMouse();
mouse.click(sr.wait(tg, 5000).getCenter());
}