Selenium test using Sikuli can't click on image when run from Jenkins

Asked by ale

I'm writing Selenium Webdrivr tests and I'm using Sikuli to click on a Browse button. I have an image of the button stored on the disk, and here is my code.

ScreenRegion screen = new DesktopScreenRegion();
Mouse mouse = new DesktopMouse();
Keyboard kb = new DesktopKeyboard();
String sikuliImagesPath = getSikuliImagesPath();

Target browseTarget = new ImageTarget(new File(sikuliImagesPath + "browse.jpg"));
ScreenRegion browseRegion = screen.wait(browseTarget, 5000);
mouse.click(browseRegion.getCenter());

The selenium tests project is a Maven project and here is the Sikuli dependency in my pom.xml file:

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

When I'm running the test from my IDE, a Firefox browser is launched and it's clicking on the button just fine. But when I run it from Jenkins, it's launching the browser on the same machine where it was previously working, but I get a NullPointerException, the button isn't found. It uses the exact same code, on the same machine and the same browser version and config.

Do you have any idea why it's not working, can I provide any additional information that might be helpful?

Thank you!

Question information

Language:
English Edit question
Status:
Expired
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
aidma (aidan-mahler13) said :
#1

Could the problem be that Jenkins is running the browser as a background service. If the browser is not being displayed during Jenkins Builds, then Sikuli won't be able to "see" it.

If this is the problem, you'll most likely need to run Jenkins from command prompt (java -jar jenkins.war) rather than as a windows service. See this link for more information: http://stackoverflow.com/questions/9618774/jenkins-selenium-gui-tests-are-not-visible-on-windows

Revision history for this message
ale (ale-nadasan) said :
#2

Thank you for the idea, but unfortunately I still could not solve my issue. The browser is displayed when ran from Jenkins. The machine where the test is running (QA2) is connected as a Jenkins Slave through this command:
java -jar slave.jar -jnlpUrl http://192.168.1.1:8081/computer/QA2/slave-agent.jnlp -secret [some hex value]

I made sure the image of the button i'm trying to click is valid by running the same test from my IDE on the same machine, and it's working.
Also, the test is passing when ran on another slave (WinXP) connected in the same way, so I guess that if Jenkins was running as a service the issue would reproduce on the other machine too. QA2 has Win7 on it, but I don't know if that's relevant.
I'm using UltraVNC Server to connect to QA2, and for some reason it's starting in Service mode.

Revision history for this message
aidma (aidan-mahler13) said :
#3

Could you try capturing a region? I'm curious what Sikuli is able to see. Try getting Jenkins to run a script with the following code:

====================== CODE START =========================
import shutil

bounds = Screen.getBounds(Screen())
img = capture(0, 0, bounds.width, bounds.height)
shutil.copy(img, "PATH\\TO\\WHERE\\YOU\\WANT\\IMG\\SAVED")
==========================================================

What does the image saved at PATH\\TO\\WHERE\\YOU\\WANT\\IMG\\SAVED look like after you run that?

Revision history for this message
ale (ale-nadasan) said :
#4

Hi,

I tried taking a screenshot just before the test is failing to check the button is visible. This is the code I used, in Java, because I integrated it in my test:

        BufferedImage capture = screen.capture();
        File f = new File("E:\\a.png");
        ImageIO.write(capture, "png", f);
        System.out.println(capture.getData());

The image contains the button just as I expected.

Revision history for this message
Launchpad Janitor (janitor) said :
#5

This question was expired because it remained in the 'Open' state without activity for the last 15 days.