Openn Login and check if image exists in Desktop application

Asked by yaya

Hello,

I'm a beginner in automation and I try to use Sikuli for automate a desktop application.
I create a new project in JAVA with Eclipse, i added external jar in JAVA Build Path : sikuli-script.jar/sikuli-api-1.0.2-standalone.jar
I want to open a Desktop application and fill the login and password and after that check if a picture exist in the application.

maestro.PNG is the screenshot of my icon application and i don't know how to do next steps.

package com.example.tests;
import java.awt.Desktop;
import java.io.File;
import org.sikuli.api.DesktopScreenRegion;
import org.sikuli.api.ImageTarget;
import org.sikuli.api.ScreenRegion;
import org.sikuli.api.Target;
import org.sikuli.api.robot.Mouse;
import org.sikuli.api.robot.desktop.DesktopMouse;
import org.sikuli.script.*;

public class maestro {
 public static void main(String[] args) {

   ScreenRegion s = new DesktopScreenRegion();
   Target tg=new ImageTarget(new File("C:\\TRAVAIL\\bandb\\POB\\maestro.PNG"));
   ScreenRegion sr= s.find(tg);
   System.out.println(sr);
   Mouse mouse=new DesktopMouse();
                 mouse.click(sr.getCenter());
   }
}

When i execute this code i get :

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.null

Exception in thread "main" java.lang.NullPointerException
 at com.example.tests.maestro.main(maestro.java:25)

Can you give me information about that ?

Thank you

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

goto http://sikulix.com, read carefully through home and quick start and then decide, what Sikuli flavor you want to use.

Revision history for this message
yaya (benoth) said :
#2

Hello RainMan,

I have followed exactly the same steps as defined in documentation and wiki for sikuli API, and finally i got this errors, I don't know what is exactly the problem

The steps are defined below :

1- Download sikuli-api-1.0.2-standalone.jar
2- Create a JAVA PROJECT in Eclipse
3- Add sikuli-api-1.0.2-standalone.jar to Build Path

Code :

package testsikuli;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import org.sikuli.api.*;
import org.sikuli.api.robot.Mouse;
import org.sikuli.api.robot.desktop.DesktopMouse;
import org.sikuli.api.visual.Canvas;
import org.sikuli.api.visual.DesktopCanvas;
import static org.sikuli.api.API.*;

public class testimage {
  public static void main(String[] args) throws MalformedURLException {

   ScreenRegion s = new DesktopScreenRegion();
   Target tg=new ImageTarget(new File("C:\\TRAVAIL\\bandb\\POB\\maestro.PNG"));
   ScreenRegion sr= s.find(tg);
   Canvas canvas = new DesktopCanvas();
   canvas.addBox(sr);
   canvas.addLabel(Relative.to(sr).above(30).getScreenRegion(), "Ecliiiipse!");
   canvas.display(3);
   //System.out.println(sr.getBounds());
        System.out.println(sr);
        Mouse mouse=new DesktopMouse();
        mouse.click(sr.getCenter());

    }
}

When i execute this code i got :

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" java.lang.NullPointerException
 at org.sikuli.api.visual.Canvas.addBox(Canvas.java:220)
 at testsikuli.testimage.main(testimage.java:20)

I want to use SikuliX for automate simple tests in my Desktop application.
1- Write login and Password to connect in application
2- Search a word
3- Check if the picture is ok

I don't know exacctly all steps and which library I must have.

Thank you for your help

Yassine

Revision history for this message
yaya (benoth) said :
#3

Hello,

I have found a solution for my problem but I don't know how a fill my login and password in a screenregion.
After many researches in sikuli forum, I find function type but this function does not work with DesktopScreenRegion

My code is :

package com.example.tests;
import java.io.File;
import java.net.MalformedURLException;
import java.awt.event.InputEvent;
import org.sikuli.api.*;
import org.sikuli.api.robot.Mouse;
import org.sikuli.api.robot.desktop.DesktopMouse;
import org.sikuli.api.visual.Canvas;
import org.sikuli.api.visual.DesktopCanvas;
import org.sikuli.script.FindFailed;
import org.sikuli.script.Key;
import org.sikuli.script.Screen;
import org.sikuli.script.Pattern;

public class maestro {
  public static void main(String[] args) throws MalformedURLException {

   ScreenRegion s = new DesktopScreenRegion();
   Target tg=new ImageTarget(new File("C:\\TRAVAIL\\bandb\\POB\\maestro.PNG");
   Target tg2=new ImageTarget(new File("C:\\TRAVAIL\\bandb\\POB\\login.PNG");
   ScreenRegion sr= s.find(tg);
   Canvas canvas = new DesktopCanvas();
   canvas.addBox(sr);
   canvas.addLabel(Relative.to(sr).above(30).getScreenRegion(), "Maestro!");
   canvas.display(3);

     Mouse mouse=new DesktopMouse();
      mouse.click(sr.getCenter());
        ScreenRegion s2 = new DesktopScreenRegion();
        ScreenRegion sr2= s2.find(tg2);
        mouse.click(sr2.getCenter());

     try {
    s2.type(tg2,"admin");
   } catch (FindFailed e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   }

    }

}

I got an error in Eclipse with s2.type. How can I write my login and password in a identified Desktop Screen Region.

Thanks

Revision history for this message
RaiMan (raimund-hocke) said :
#4

You are mixing 2 different Sikuli implementations - if you would have read carefully as recommended in comment #1, you would have understood.

Revision history for this message
Audus (carl-ridderstolpe) said :
#5

if type dont work its often that you dont have focus in the box youre going to type it in and your typing in thin air. i cant solve the class error but my comment might be something and btw you could actualyl simplify your code alot, for a that simple task it dont have to be that complex

Can you help with this problem?

Provide an answer of your own, or ask yaya for more information if necessary.

To post a message you must log in.