Skip to main content

Working with Sikuli

 

Sikuli depends on processing of images and  can automate flash object and desktop application 

It  is mainly used for interacting with elements of webpages and handling windows based popups Sikuli uses the technique of "Image Recognition" and "Control GUI" to interact with elements of web pages and windows popups, all web elements are  taken as image and stored inside project.

1. if you want to upload a desktop file/image on the website.

2. You can run and change setting on your YouTube channel

add dependency of Sikuli in your POM  file and Sikuli jar will be added in you Maven dependencies 

<dependency>
    <groupId>org.sikuli</groupId>
    <artifactId>sikuli-api</artifactId>
    <version>1.2.0</version>
</dependency>

Automating Flash objects

Let's take example of automating a Youtube video using Sikuli. after opening the video lets suppose you want to click on Mute button then press stop and then go to setting and change video quality.



you can also add it manually by right click on project  Build path->Configure Build path->Add external Jar









In order to do this first take a snapshot of all mention buttons, copy all the images  add it in your project .



After adding all the images in the project



code for Sikuli

public class Sikuli {

@Test

public void test() throws SikuliException

{

    System.setProperty("Webdriver.chrome.driver","chromedriver");

WebDriver driver = new ChromeDriver();

   driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);

   driver.get("https://www.youtube.com/watch?v=569qoURhXoY");

   // create object of screen class

   Screen s = new Screen(); 

   //create object of pattern class

   

   

   Pattern Pause1 =new Pattern("Mypause.png");

   //wait till the image is visible

   s.wait(Pause1,2000);

   s.click();

   s.click();

   driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);


   

   Pattern Play1 = new Pattern("Myplay.png");

   s.wait(Play1,2000);

   s.click();

   s.click();

   driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);


    

   Pattern vol1 = new Pattern("Myvolume.png");

   s.wait(vol1,2000);

   s.click();

   s.click();

   driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);

 

   Pattern set1 = new Pattern("Mysetting.png");

   s.wait(set1, 2000);

   s.click();

   s.click();

   driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);

  

   Pattern qua1 = new Pattern("Auto1080p.png");

   s.wait(qua1,2000);

   s.click();

   s.click();

   driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);

  

   Pattern qua2 = new Pattern("144p.png");

   s.wait(qua2,2000);

   s.click();

   s.click();

}

}





Uploading a file using Sikuli

Open nauckri.com and click on uploading a file




All the images are saved at location Users\\priyankac\\Desktop\\Screenshot2


public class Sikuliupload {

@Test

public void test() throws SikuliException

{

    System.setProperty("Webdriver.chrome.driver","chromedriver");

WebDriver driver = new ChromeDriver();

   driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);

   driver.get("https://www.naukri.com");

driver.manage().window().maximize();

driver.findElement(By.xpath("//div[@class='wdgt-upload-btn']/label")).click();

driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);

//once "upload cv" is clicked  a new window will open to to identify the window take screenshot where the path is provided  and save it in below path

String imageFilepath = "Users\\priyankac\\Desktop\\Screenshot2\\";

//where the file to be uploaded location is present

String inputFilepath ="Users\\priyankac\\Desktop\\Screenshot2\\";

Screen sc = new Screen();

//search image

Pattern file = new Pattern(imageFilepath +"search.docx");

//open image

Pattern OB = new Pattern(imageFilepath +"OPEN.png");

sc.wait(file,20);

//file to be uploaded is pc.docx

sc.type(file,inputFilepath+"pc.docx");

// to click on open button so that file gets uploaded

sc.click(OB);

}

}





Comments

Popular posts from this blog

Cucumber - Execution of test cases and reporting

Before going through this blog please checkout blog on   Cucumber Fundamentals Cucumber is testing tool which implements BDD(behaviour driven development).It offers a way to write tests that  anybody can understand, regardless of there technical knowledge. It users Gherkin (business readable language) which helps to  describe behaviour without going into details of implementation It's helpful for  business stakeholders who can't easily read code ( Why cucumber tool,  is  called  cucumber , I have no idea if you ask me I could have named it "Potato"(goes well with everything and easy to understand 😂) Well, According to its founder..... My wife suggested I call it  Cucumber  (for no particular reason), so that's how it got its  name . I also decided to give the Given-When-Then syntax a  name , to separate it from the  tool . That's why it's  called  Gherkin ( small variety of a cucumber that's been pickled. I...

Jmeter 5.4.1- Config Elements - Part-03

  Part-01- Installation of Jmeter and HTTP's Recorder click  here Part 02--Previous blog on Assertion Config elements in Jmeter are used to configure or modify the samplers requests made to the server. These elements are added at the same or higher level of the samplers that we want to configure  Let' start with  CSV data config As the name suggest it used to read data from CSV first we need to put data in variables and then use the variables in sampler request. create a new test plan add CSV data set config Add a Thread Group and then add Sampler "Java Request"  Create a CSV file  with some data (Name and Data) and save it  Now go to Jmeter CSs data set config browse and upload the css file create Make few more changes in place of  variable name - Name and Dept Ignore first line - True Delimeter - \t (as suggested) Now move on the Sampler-" Java Request" and rename it with header elements of CSV As we have Name and d...

Beginners tutorial -:working with JMeter in Mac and windows - Part-01

  Prequisite   you should have Java downloaded in your system with Home path set under environment variables.(as of today Java version 8 and higher are required fro jmeter ) for help check out this link Note Always run the jmeter on your secondary browser,  if you give the primary browser for proxy settings then your internet connection will be disrupted for the browser as well as system For ex if you have chrome and firefox and your primary or default browser is chrome then do all the proxy setting in firefox so it won't hamper the system Internet connection  if you have safari as your default browser in your mac os then set proxy in chrome/firefox  MAC Download jmeter from the link  here click on the hypelink under section Binaries  "Apache JMeter( 5.3 ). tgz" file  for Mac   Tar file will get downloaded Double click on the tar file to unzip  once you open the folder  got to bin and search for jmeter.sh file this is a executa...