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());
}
Hello friend,,
ReplyDeleteIt is really nice post, but do u have example towards selenium and getting a log report, keeping property file .
Hello , Its a fun tasting starting with Sikuli and webdriver integration , But this information is not enough for anybody to understand easily , Need to explain about all jar files , and which are all require to import for . What are the possibilities are available for this tool . Give some more explanation and
ReplyDeleteexamples . Give some examples for Video players , Canvas image , etc...
Thank You so much
Hello, How we can enter the input data into text box using the sikuli api? ex: enter search value into google search box
ReplyDeleteI am very very sorry for late reply. I open my blog after a long time and when I getting your query do some POC on that and I paste some code here for Keyboard but I will try another post for this later.
Deletepublic class SikuliJavaExample {
/**
* @param args the command line arguments
* @throws java.io.IOException
*/
public static void main(String[] args) throws IOException {
// TODO code application logic here
/*
* We Define the Screen region
* as Desktop Screen region.
*/
browse(new URL("http://www.google.com"));
ScreenRegion s = new DesktopScreenRegion();
Keyboard kb=new DesktopKeyboard();
Target tg=new ImageTarget(new File("./resources/googleSearchBox.JPG"));
Mouse mouse=new DesktopMouse();
mouse.click(s.wait(tg, 5000).getCenter());
//kb.paste("ABCD");
kb.type("ABCD");
}
}
This comment has been removed by the author.
DeleteIt is really nice post.But it's showing java.lang.NullPointerException in
Deletemouse.click(s.wait(tg, 5000).getCenter()); line. have you any solutions.
Thanks in advanced.
As per your error I think sikuli cannot find the searchbox field where text will be typed. It may be possible that browser is not open or google page not opened so sikuli can not find this searchbox.If you share your email i will drop my project?
DeleteSorry for late reply.
Thanks for this post Arjun, indeed helpful.
ReplyDelete