Reputation: 919
public class MyFirstSikuliTest {
public static void main(String[] args) {
App.open("C:\\Program Files\\Mozilla Firefox\\firefox.exe");
Screen s = new Screen();
try{
s.click("How do I take the screenshot and pass the path of the PNG here?", 0);
s.wait("How do I take the screenshot and pass the path of the PNG here?");
s.type(null, "WEBSITE NAME", 0);
}
catch(FindFailed e){
e.printStackTrace();
}
}
}
How do I take the screenshot and pass the path of the PNG into click method and wait method?? kindly help.
PS: I want to open firefox browser, click in the address bar, enter a website name and click enter.
Thanks!
Upvotes: 4
Views: 10941
Reputation: 9568
public static void screenClipUser() throws IOException{
org.sikuli.script.Screen screen = Screen.getPrimaryScreen();
org.sikuli.script.Region region = screen.selectRegion("Select Area to capture as Image");
ScreenImage clip = region.getLastScreenImage(); // screen.userCapture();
ScreenImage printScreen = region.getScreen().capture();
javax.imageio.ImageIO.write(clip.getImage(), "PNG", new File("D:\\SikuliImages\\Clip.png"));
ImageIO.write(printScreen.getImage(), "PNG", new File("D:\\SikuliImages\\PrintScreen.png"));
screenCaptureRegion(screen);
}
public static void screenCaptureRegion(Screen screen) throws IOException{
java.awt.Point point = MouseInfo.getPointerInfo().getLocation();
System.out.println("Mouse Location Co-Ordinates Previous Selected : " + point);
//ScreenImage capturedRegion = screen.capture(point.x, point.y, 200, 200);
ScreenImage capturedRegion = screen.capture(clip.x, clip.y, clip.w, clip.h);
ImageIO.write(capturedRegion.getImage(), "PNG", new File("D:\\SikuliImages\\CapturedRegion.png"));
}
public static void screenClipOneNote(){
org.sikuli.script.IScreen scr = null;
org.sikuli.script.EventObserver ob = null;
final OverlayCapturePrompt oc = new org.sikuli.script.OverlayCapturePrompt(scr, ob);
oc.prompt("Select Area to capture as Image");
oc.addObserver(new org.sikuli.script.EventObserver() { // Inner calss
@Override
public void update(org.sikuli.script.EventSubject arg0) {
org.sikuli.script.ScreenImage capturedImg = oc.getSelection(); // To use oc object make as final.
try {
ImageIO.write(capturedImg.getImage(), "PNG", new File("D:\\SikuliImages\\ScreenClip.png"));
} catch (Exception e) { e.printStackTrace(); }
}
});
}
Upvotes: 0
Reputation: 46
public static void takePictureOfError(String Name) throws IOException,
AWTException {
new File("Errors").mkdir();
Toolkit toolkit = Toolkit.getDefaultToolkit();
Dimension screenSize = toolkit.getScreenSize();
Rectangle screenRect = new Rectangle(screenSize);
Robot robot = new Robot();
BufferedImage image = robot.createScreenCapture(screenRect);
utilsLogger.info(ImageIO.write(image, "png", new File("//"
+ Name)));
}
I hope this methode helps, it has worked for me ;)
Upvotes: 3
Reputation: 1016
A few lines of description:
Line 3: I open a new tab so that the address bar always looks the same (different urls in the bar might register as different images). This is a major programming requirement of Sikuli, ignoring areas of a display that might change slightly over the use of the program. You could also reduce the percent comparison of an image.
Line 4: Sikuli finds the address bar picture (image is from FF in Windows). You can adjust the location on the image that Sikuli clicks or make sure that your image is large enough that the middle is a click on the address bar location (ie instead of Sikuli clicking on the globe icon). The url text that I defined in line 1 is typed into the selected address bar. The \n in the url is the enter key.
Upvotes: 1