Saturday 18 November 2017

Sikuli integration with Selenium webdriver-Java for upload functionality

Steps:

1. Capture 3 snapshot(Try it,Browse,Open) for below url using sikuli ide or snipping tool or  copy paste below images  in mentioned folder

https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_fileupload_create





2. Create a file test.txt in your default window folder (for me - desktop)

3. Add Sikulix jar and selenium jar in your project build path
4. create a testng class - SikuliProj in your project and run the test.

//Codes


import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.sikuli.script.FindFailed;
import org.sikuli.script.Pattern;
import org.sikuli.script.Screen;
import org.testng.annotations.Test;

public class SikuliProj {

@Test
public void functionName() throws FindFailed, InterruptedException {


// Create a new instance of the Firefox driver

WebDriver driver = new FirefoxDriver();

//navigate to websie
driver.get("https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_fileupload_create");

Screen sc=new Screen();

//Create object for all 3 captured images
Pattern image1 = new Pattern("E:\\test\\tryit.png");
Pattern image2 = new Pattern("E:\\test\\browse.png");
Pattern image3 = new Pattern("E:\\test\\open.png");

//Perform action using sikuli
sc.wait(image1,10);
sc.click(image1);
sc.wait(image2,5);
sc.click(image2);
Thread.sleep(5000);
sc.type("test.txt");
sc.wait(image3,5);
sc.click(image3);

  }

}


No comments:

Post a Comment