Create your first script using (Selenium + Sikuli) tool
Here I will be going to create a script using both Sikuli and Selenium WebDriver tool. Look at the scenario below :
Scenario :
1. Launch URL : http://www.ebay.com/ using Selenium.
2. Select “books” option from “All Categories” drop down list using Sikuli tool.
3. Click on Search button using Sikuli tool.
4. Print and verify the heading of next page(It should be Books). This will be be done by Selenium.
As I already said earlier in my previous post that Sikuli use image recognition algorithm to identify the elements. In order to perform clicks using Sikuli tool, we will have to take the screen shots of those particular elements and tell the sikuli to search for those images on the screen and perform actions on them.
Look at the web page below :
First screen shot :
Second Screen shot :
Third Screen shot :
Save all the screen shots into your project and we will give the path of these images to Sikuli to perform actions on them.
Program :
import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.sikuli.script.FindFailed; import org.sikuli.script.Screen; import org.testng.Assert; import org.testng.annotations.Test; public class SikuliTestScript { @Test public void testApp() throws FindFailed { //Initialize Firefox Driver WebDriver driver = new FirefoxDriver(); //Launch Ebay website driver.get("http://www.ebay.com/"); //Maximize the browser driver.manage().window().maximize(); //Apply implicit wait on driver instance driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); //Write sikuli script //Create an object of Screen class Screen screen = new Screen(); //Perform click on drop down list screen.click("C:/Users/workspace/SikuliProject/src/Blogs/Allcategories.png"); //Click on Book option screen.click("C:/Users/workspace/SikuliProject/src/Blogs/BooksOption.png"); //Click on Search button screen.click("C:/Users/workspace/SikuliProject/src/Blogs/SearchButton.png"); //Fetch the heading from the web page String text = driver.findElement(By.tagName("h1")).getText(); System.out.println(text); Assert.assertTrue(text.equalsIgnoreCase("Books"), "Books page is not opened"); } }
If you really like the information provided above, please don’t forget to like us on Facebook, you can also leave the comment.