lunes, 11 de enero de 2021

Sikulix (3): Sikulix and Selenium for selecting a certificate (best option)

 1. Introduction

Here is an example where :

1. Get a browser window and open a web that expects a user certificate,


2. Click an image with Selenium




3. Use Sikulix to recognize the text "XIMO DANTE" and click it for selecting the certificate




4. Click on the image of the button. This image was obtained by the Sikulix IDE.

The ide was opened with:

java - jar path_to_sikulix.jar/sikulix-2.04.jar

And the image of the button was captured with the option of capturing images of the ide.


Here is the java code


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package mypack;

import java.time.Duration;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;

import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.Point;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.support.ui.FluentWait;
import org.openqa.selenium.support.ui.Wait;
import org.sikuli.script.Match;
import org.sikuli.script.Pattern;
import org.sikuli.script.Region;

import utils.SikulixUtils;

public class Myclass {

  public static void main(String[] args) {
    //1. URL
    String myUrl="https://sede.seg-social.gob.es/wps/portal/sede/sede/Ciudadanos/CiudadanoDetalle/!ut/p/z0/rU_LDoIwEPwVOHA02wIhciTGEJQmGkOEXkgDBeujPFqN_r3UO5y8TDKzk5kdoJADlewlWqZFJ9l94gUNSg8HPg4RTmOUbFGUkX0WekcvTjCcuIId0AWTG5gUdyQb0gLtmb6shGw6yA2OD66sj1XxUYtGVKzuFOQIz56gENdhoBHQqpOavzXkite8_DEpJo-DjOCgSjxrVjNplJk4B803LW-ahv_7FRfhdeBDf4vPh7QhKrLtLwe74DE!/";
		
    //2. Get the driver
    System.setProperty("webdriver.chrome.driver", "/home/ximodante/Selenium/chromedriver");
    WebDriver driver =null;
    ChromeOptions options=new ChromeOptions();
    driver = new ChromeDriver(options);
    driver.manage().deleteAllCookies();
    driver.manage().timeouts().implicitlyWait(10L, TimeUnit.SECONDS); //Set implicit wait
	    
    //3. Get the browser wait
    Wait<WebDriver> wait= new FluentWait<WebDriver>(driver)       
	.withTimeout(Duration.ofSeconds(4))
	.pollingEvery(Duration.ofSeconds(1))    
	.ignoring(NoSuchElementException.class); 
	   
    //4. click on the icon for accessing by certificatwe
    String myXpath= "//ul[@id='listServ_d1b8a537-f135-47cc-b77e-9597f62af41b']/li[@class='first pr1']/a[@target='_blank']";
    WebElement webElement=null;
    try {
	webElement=wait.until(new Function<WebDriver, WebElement>() {       
    	  public WebElement apply (WebDriver browser) { 
	    WebElement wE=null;
	    for( WebElement webElem: browser.findElements(By.xpath(myXpath))) {
	      System.out.println("WebElem="+webElem.toString());
	      wE=webElem;
	      if ((wE.isDisplayed() && wE.isEnabled()) )
		break;
	    }
	    return wE;
	 }  
	});
   } catch (Exception e) {e.printStackTrace();}
	    
   //Click the element
   webElement.click();
    
   //5. Now displays a window offering the available certificates
   //   and use Sikulix for selecting certificate for XIMO DANTE
   //   using OCR and click on button to accept the certificate
	 
   Point top=driver.manage().window().getPosition();
   Dimension dim=driver.manage().window().getSize();
   try {
        //  OCR recognition
	utils.SikulixUtils.click(top.getX(), top.getY(), dim.getWidth(), dim.getHeight(), "XIMO DANTE");
	Region region=new Region (top.getX(), top.getY(), dim.getWidth(), dim.getHeight());
	//The image of the button to click
	Pattern image=new Pattern("/myImages/bt_Dacord.jpg");
	Match match=region.find(image);
	match.click();
   } catch (Exception e) {e.printStackTrace();}
		
  }
}

and the Utility class:

package utils;

import java.io.File;

import org.openqa.selenium.Dimension;
import org.openqa.selenium.Point;
import org.sikuli.script.FindFailed;
import org.sikuli.script.Match;
import org.sikuli.script.Pattern;
import org.sikuli.script.Region;
import org.sikuli.script.Screen;

public class SikulixUtils {

	/**
	 * Finds text in a region
	 * 
	 * @param leftTop
	 * @param widthHeight
	 * @param text
	 * @throws Exception
	 */
	public static void click(Point leftTop, Dimension widthHeight, String text) throws Exception {
		click(leftTop.getX(), leftTop.getY(), widthHeight.getWidth(), widthHeight.getHeight(), text);
	}

	public static void click(int left, int top, int width, int height, String text) throws FindFailed {
		Region region = new Region(left, top, width, height);
		// Match match=region.findWord("ACCVCA-120");
		// Match match=region.findT(text);
		Match match = region.findLine(text);
		match.click();
	}

	/**
	 * Clicks on an image given by its path (from resource folder) and a region to
	 * look for the image
	 * 
	 * @param leftTop
	 * @param widthHeight
	 * @param isExecutedFromJar
	 * @param resourceFolder
	 * @param fileName
	 * @throws Exception
	 */
	public static void click(Point leftTop, Dimension widthHeight, boolean isExecutedFromJar, String subResourceFolder,
			String fileName) throws Exception {
		click(leftTop.getX(), leftTop.getY(), widthHeight.getWidth(), widthHeight.getHeight(), isExecutedFromJar,
				subResourceFolder, fileName);
	}

	public static void click(int left, int top, int width, int height, boolean isExecutedFromJar,
			String subResourceFolder, String fileName) throws Exception {
		String imgPath = "";
		boolean hasFolder = true;
		if (hasFolder && subResourceFolder != null)
			hasFolder = false;
		if (hasFolder && subResourceFolder.trim().length() == 0)
			hasFolder = false;

		if (!hasFolder)
			imgPath = FileUtils01.getFilePath(isExecutedFromJar, subResourceFolder.trim() + File.separator + fileName);
		else
			imgPath = FileUtils01.getFilePath(isExecutedFromJar, fileName);

		Region region = new Region(left, top, width, height);
		Pattern image = new Pattern(imgPath);

		// Match match=region.findWord("ACCVCA-120");
		Match match = region.find(image);
		match.click();

	}

	public static void clickCertificate() {
		String certificateZkhan = "C:/zkhan.PNG";
		String okButton = "C:/ok.PNG";
		Screen screen = new Screen();
		try {
			screen.click(certificateZkhan);
			screen.click(okButton);
		} catch (FindFailed findFailed) {
			findFailed.printStackTrace();
		}
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}

And another dependency

package utils;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.net.URLDecoder;
import java.security.CodeSource;

public class FileUtils01 {

	/**
	 * Folder that contains jar file or folder that contains project folder
	 * 
	 * @return
	 * @throws Exception
	 */
	public static String getJarContainingFolder() throws Exception {
		Class<?> aClass = MethodHandles.lookup().lookupClass();
		CodeSource codeSource = aClass.getProtectionDomain().getCodeSource();

		File jarFile;

		if (codeSource.getLocation() != null) {
			jarFile = new File(codeSource.getLocation().toURI());
		} else { // It is not a jar file
			String path = aClass.getResource(aClass.getSimpleName() + ".class").getPath();
			String jarFilePath = path.substring(path.indexOf(":") + 1, path.indexOf("!"));
			jarFilePath = URLDecoder.decode(jarFilePath, "UTF-8");
			jarFile = new File(jarFilePath);
		}
		String s = jarFile.getParentFile().getAbsolutePath();
		System.out.println("S------>:" + s);
		if (s.endsWith(File.separator + "target")) { // Maven target directory for compiled classes
			s = s.substring(0, s.lastIndexOf(File.separator));
			s = s.substring(0, s.lastIndexOf(File.separator));
		}
		return s;
	}

	public static byte[] readFile(String fileName) throws IOException {
		File file = new File(fileName);// filename should be with complete path
		FileInputStream fis = new FileInputStream(file);
		byte[] b = new byte[(int) file.length()];
		fis.read(b);
		fis.close();
		;
		return b;
	}

	public static void writeToFile(String fileName, String myString) throws IOException {
		BufferedWriter writer = new BufferedWriter(new FileWriter(fileName));
		writer.write(myString);
		// do stuff
		writer.close();
	}

	public static String getFilePath(boolean isExecutedFromJAR, String relativeFilePath) throws Exception {
		if (isExecutedFromJAR)
			return FileUtils01.getJarContainingFolder() + File.separator + relativeFilePath;
		else {
			return System.getProperty("user.dir") + File.separator + "src" + File.separator + "main" + File.separator
					+ "resources" + File.separator + relativeFilePath;
		}
	};

	/**
	 * 
	 * @param filePath
	 * @return
	 * @throws Exception
	 * 
	 *                   Example
	 *                   ExcelFile=getRelativeFromJarFile("excel\MyExcel.xlsx")
	 */
	public static String getRelativeFromJarFile(String filePath) throws Exception {
		return FileUtils01.getJarContainingFolder() + File.separator + filePath;
	}

	/**
	 * test in main class
	 * 
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			System.out.println(getJarContainingFolder());
			System.out.println(System.getProperty("java.class.path"));
			System.out.println(System.getProperty("user.dir"));
			byte[] b = readFile("/home/eduard/Audit.0.log");
			String sb = new String(b);
			System.out.println(sb);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

}

Sikulix(2): IDE installation

1. Installation

1. Download the latest jar version for java from Sikulix. (in my case: sikulix-2.0.5.jar)

2. Execute from the command line

  java -jar path-to/sikulix.jar 

or if you have some problems:

  java -jar path-to/sikulix.jar -v -c


2. Test

Here is a screen with a simple script. Note the comments with the symbol "#"


It is very useful as you can capture images.

It is also very useful for testing certain commands and then import them to java. 



miércoles, 13 de marzo de 2019

Selenium (2): Wait until manual selection of the certificate

0. Introduction


As we said in a previous entry in this blog, we are considering automatically use Selenium for the automatic use of web pages.

The only drawback is to manually select the certificate for authentication as it seems rather difficult for Selenium.

As Anuja Jain says in her blog there are mainly 3 ways to wait for a condition to get fulfilled.

1. First wait condition: Implicit wait

Anuja explains: "Implicit Wait means informing selenium web driver to wait for specific amount of time and if the web element is not visible after waiting for that specific point then throw "No such Element found Exception".


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
package test;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

public class ImplicitWait {
    public static void main(String[] args) throws Exception {
        //1. Get WebDriver
        String chromeDriverPath = "/home/eduard/Selenium/chromedriver" ;
        System.setProperty("webdriver.chrome.driver", chromeDriverPath);
        ChromeOptions options = new ChromeOptions();
        //options.addArguments("--headless", "--disable-gpu", "--window-size=1920,1200","--ignore-certificate-errors", "--silent");
        WebDriver driver = new ChromeDriver(options);
       
        driver.get("https://dantesquehtmlunit.blogspot.com");
        driver.manage().timeouts().implicitlyWait( 2000, TimeUnit.MILLISECONDS);
        driver.quit();
    }
}


2. Second wait condition: Implicit wait

In this case, Selenium is waiting until the condition is fulfilled within a max time waiting before throwing an "ElementNotVisibleException" (if the element is not found)


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package test;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class ExplicitWait {
    public static void main(String[] args) throws Exception {
    //1. Get WebDriver
    String chromeDriverPath = "/home/eduard/Selenium/chromedriver" ;
    System.setProperty("webdriver.chrome.driver", chromeDriverPath);
    ChromeOptions options = new ChromeOptions();
    //options.addArguments("--headless", "--disable-gpu", "--window-size=1920,1200","--ignore-certificate-errors", "--silent");
    WebDriver driver = new ChromeDriver(options);
  
    //Define a wait object with a max time  for waiting
    WebDriverWait wait = new WebDriverWait(driver,20);
       
    driver.get("https://dantesquehtmlunit.blogspot.com");
  
    WebElement title;
    //Wait untill title is available
    title= wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("title")));      
  
    System.out.println("condition fulfilled!");
    Thread.sleep(2000);
    driver.quit();
  }
}

A new object is created for managing the intelligent wait.

3. Third wait condition: Fluent wait. Valid for waiting to manually select Certificate for login.

By means of the fluent wait, two times are settled:

  1. First delay time
  2. repeat time cycle.
The cycle is repeated until the condition fulfils.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package test;

import java.time.Duration;
import java.util.function.Function;

import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.support.ui.FluentWait;
import org.openqa.selenium.support.ui.Wait;

public class SeleniumWaitForCertSelection {
 
    private static WebElement getWebElement(WebDriver driver,  Wait<WebDriver> wait, String xpathExpression) {
        WebElement myElement= wait.until(new Function<WebDriver, WebElement>() {       
     public WebElement apply(WebDriver driver) { 
         return driver.findElement(By.xpath(xpathExpression));     
     }  
 });
  
 return myElement;
    }
 
    public static void main(String[] args) {
  
        //1. Get WebDriver
 String chromeDriverPath = "/home/eduard/Selenium/chromedriver" ;
 System.setProperty("webdriver.chrome.driver", chromeDriverPath);
 ChromeOptions options = new ChromeOptions();
 //options.addArguments("--headless", "--disable-gpu", "--window-size=1920,1200","--ignore-certificate-errors", "--silent");
 WebDriver driver = new ChromeDriver(options);
     
 Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)       
     .withTimeout(Duration.ofSeconds(2))
     .pollingEvery(Duration.ofSeconds(1))    
     .ignoring(NoSuchElementException.class); 


 //1. Get the page
 driver.get("https://enguera.sedelectronica.es/carpetaelectronica.4");
      
   
 //2. fluent Wait and Look for the anchor element and click   (//a=anchor)
 //driver.findElement(By.xpath("//a[contains (@id, 'id2')]")).click();
 getWebElement(driver,wait,"//a[contains (@id, 'id2')]").click();


        // wait and get the second element
        getWebElement(driver,wait,"//a[contains (@id, 'id3')]").click();

        //Wait and the the nth element and meanwhile you can interact manually with the browser to get the dertificate
        getWebElement(driver,wait,"//a[contains (@id, 'idn')]").click();

        System.out.println("condition fulfilled!");
 Thread.sleep(2000);
 driver.quit();  
    }
}




Lines 16-25 a method for waiting and finding the desired element is created with yellow background

Lines 36-39 a fluent wait object is defined to manage delays

Line 46-48 explicit call to the method to find the desired element and click it,

Lines 53-54 You can interact manually with the browser until the desired element is visible. In this case, we can select manually a certificate before entering the next page






Sikulix(1): Installation for Java

0. Introduction

Sikuli seems to be an option for using certificate authentication in browsers due to the fact that the certificate selection is an OS task (see Stackoverflow) and not a browser specific action. So Selenium can hardly be useful alone for doing all tasks automatically.

Perhaps, a better solution can be select "by hand" the required certificate and tell selenium to wait until the desired page is loaded (the subsequent page after the certificate selection). See StackOverflow.



1. Installation

Reading Sikuli's docs, related to Ubuntu, it is advisable to use Ubuntu 18.04 (last releases) for avoiding problems with OpenCV installation.

I have not been able to install OpenCV version 3.2 on Ubuntu 16.04 so I have upgraded to 18.04.

These are the main prerequisites.


1
2
3
4
5
6
7
8
#1. Install libcanberra
sudo apt install libcanberra-gtk0 libcanberra-gtk-module

#2Install libopencv3.2-java
sudo apt install libopencv3.2-java

#3 Make a link with a known name for Sikuli
sudo ln -s /usr/lib/jni/libopencv_java320.so /usr/lib/libopencv_java.so

It is important to install Tesseract (version 4.1.1). Bharath Sivakumar explains how to do this task.  He also explains how to use OCR programmatically!. It is very good!

Basically (Please follow the last link!):

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#1. Check Tesseract version
tesseract --version

#2. Install prerequisite "leptonica2
sudo apt-get install -y libleptonica-dev

#3.Install dependencies
sudo apt-get update -y
sudo apt-get install automake
sudo apt-get install -y pkg-config
sudo apt-get install -y libsdl-pango-dev
sudo apt-get install -y libicu-dev
sudo apt-get install -y libcairo2-dev
sudo apt-get install bc

#get the source code and unzip it
wget https://github.com/tesseract-ocr/tesseract/archive/4.1.1.zip
unzip 4.1.1.zip

#go to tesseract-4.1.1 directory and execute
./autogen.sh
./configure
make
sudo make install
sudo ldconfig
make training
sudo make training-install

#test tesseract version
tesseract --version



2. Updating the pom.xml from the last project



  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>ximodante</groupId>
  <artifactId>HTMLFillForms</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>HTMLFillForms</name>
  <description>HTMLFillForms</description>
  
  <repositories>
    <repository>
      <!-- See https://github.com/RaiMan/SikuliX1 -->
      <id>repo-sikuli</id>
      <name>sonatype nightky bluids for sikuli</name>
      <url>http://oss.sonatype.org/content/groups/public</url>
    </repository>
  </repositories>
  
  <properties>
    <cxf.version>3.2.6</cxf.version>
    <jax.version>2.3.0</jax.version>
    <lombok.version>1.18.4</lombok.version>
    <jackson.version>2.9.6</jackson.version>
    <h2.version>1.4.196</h2.version>
    <hibernate.version>5.2.16.Final</hibernate.version>
    <selenium.version>3.141.59</selenium.version>
    <poi.version>4.0.1</poi.version>
    <sikulix.version>2.0.4</sikuli.version>
    
        
    <failOnMissingWebXml>false</failOnMissingWebXml>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <!-- Java version-->
    <java.version>13</java.version>
  </properties>  
  
  <dependencies>
  
    <!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
    <dependency>
      <groupId>org.projectlombok</groupId>
      <artifactId>lombok</artifactId>
      <version>${lombok.version}</version>
      <scope>provided</scope>
    </dependency>
    
    <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
    <dependency>
      <groupId>org.apache.commons</groupId>
      <artifactId>commons-lang3</artifactId>
      <version>3.8.1</version>
    </dependency>
    

    <!--  HTML Parser  -->
    <!--  See https://www.mkyong.com/java/how-to-automate-login-a-website-java-example/ -->
    <!-- https://mvnrepository.com/artifact/org.jsoup/jsoup -->
    <!-- 
    <dependency>
      <groupId>org.jsoup</groupId>
      <artifactId>jsoup</artifactId>
      <version>1.11.3</version>
    </dependency>
     -->

    <!-- Simulate a browser to fill forms !!! -->
    <!--  seehttps://stackoverflow.com/a/1383097/7704658   -->
    <!-- https://mvnrepository.com/artifact/net.sourceforge.htmlunit/htmlunit -->
    <!-- 
    <dependency>
      <groupId>net.sourceforge.htmlunit</groupId>
      <artifactId>htmlunit</artifactId>
      <version>2.33</version>
    </dependency>
     -->
     
    <!-- Seleniun -->
    <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
    <dependency>
      <groupId>org.seleniumhq.selenium</groupId>
      <artifactId>selenium-java</artifactId>
      <version>${selenium.version}</version>
    </dependency>
    
    <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-server -->
    <dependency>
      <groupId>org.seleniumhq.selenium</groupId>
      <artifactId>selenium-server</artifactId>
      <version>${selenium.version}</version>
    </dependency>
    
    <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-firefox-driver -->
    <dependency>
      <groupId>org.seleniumhq.selenium</groupId>
      <artifactId>selenium-firefox-driver</artifactId>
      <version>${selenium.version}</version>
    </dependency>
    
    <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-chrome-driver -->
    <dependency>
      <groupId>org.seleniumhq.selenium</groupId>
      <artifactId>selenium-chrome-driver</artifactId>
      <version>${selenium.version}</version>
    </dependency>
    
    
    
    <!-- Sikuli ???? -->
    <dependency>
     <groupId>com.sikulix</groupId>
     <artifactId>sikulixapi</artifactId>
     <version>${sikulix.version}</version>
    </dependency>
    
    <!--  Tess4J A Java JNA wrapper for Tesseract OCR API.  -->
    <!-- https://mvnrepository.com/artifact/net.sourceforge.tess4j/tess4j -->
    <!-- 
    <dependency>
      <groupId>net.sourceforge.tess4j</groupId>
      <artifactId>tess4j</artifactId>
      <version>4.3.1</version>
    </dependency>
    -->
    
    <!-- https://mvnrepository.com/artifact/org.bytedeco.javacpp-presets/opencv -->
    <!-- 
    <dependency>
      <groupId>org.bytedeco.javacpp-presets</groupId>
      <artifactId>opencv</artifactId>
      <version>4.0.1-1.4.4</version>
    </dependency>
    -->
  
    <!--  JPA  -->
    <!-- MS-SQL Server JDBC JTDS bo de 2013-->
    <!-- https://mvnrepository.com/artifact/net.sourceforge.jtds/jtds -->
    <dependency>
      <groupId>net.sourceforge.jtds</groupId>
      <artifactId>jtds</artifactId>
      <version>1.3.1</version>
    </dependency>
     
       
    
    <!-- JPA 2.1 Provider -->
    <!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
    <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-core</artifactId>
      <version>${hibernate.version}</version>
    </dependency>
    
    <!--  END JPA -->
    
    
    <!-- For using Excel Files -->
    <!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
    <dependency>
      <groupId>org.apache.poi</groupId>
      <artifactId>poi</artifactId>
      <version>${poi.version}</version>
    </dependency>
        
    
    <!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
    <dependency>
      <groupId>org.apache.poi</groupId>
      <artifactId>poi-ooxml</artifactId>
      <version>${poi.version}</version>
    </dependency>
    
  
    <!--BEGIN Java 9 references to JEE  not included in JDK9-->
    <!-- see http://openjdk.java.net/jeps/320-->
    
    <!-- https://mvnrepository.com/artifact/com.sun.xml.bind/jaxb-impl -->
    <dependency>
      <groupId>com.sun.xml.bind</groupId>
      <artifactId>jaxb-impl</artifactId>
      <version>${jax.version}</version>
    </dependency>
        
    <!-- https://mvnrepository.com/artifact/com.sun.xml.bind/jaxb-core -->
    <dependency>
      <groupId>com.sun.xml.bind</groupId>
      <artifactId>jaxb-core</artifactId>
      <version>${jax.version}</version>
    </dependency>
    
    
    <dependency>
      <groupId>com.sun.activation</groupId>
      <artifactId>javax.activation</artifactId>
      <version>1.2.0</version>
    </dependency>
    
    <dependency>
      <groupId>com.sun.xml.ws</groupId>
      <artifactId>jaxws-ri</artifactId>
      <version>${jax.version}</version>
      <type>pom</type>
    </dependency>
        
    <dependency>
      <groupId>com.sun.xml.bind</groupId>
      <artifactId>jaxb-ri</artifactId>
      <version>${jax.version}</version>
      <type>pom</type>
    </dependency>
    
    <!-- End of Dependencies required for JAVA 9!!!! -->
    
  </dependencies>
  
  <!-- COMPILER PLUGIN -->
  <!-- This is OK  http://crunchify.com/how-to-create-build-java-project-including-all-dependencies-using-maven-maven-resources-maven-dependency-maven-jar-plugin-tutorial/
  -->
  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.8.0</version>
          <configuration>
            <!-- release>10</release -->
            <source>10</source>
            <target>10</target>
            <showWarnings>true</showWarnings>
            <showDeprecation>true</showDeprecation>
          </configuration>
          
        </plugin>
      </plugins>
    </pluginManagement>
 
    <plugins>
      <plugin>
        <artifactId>maven-resources-plugin</artifactId>
        <version>3.1.0</version>
        <executions>
          <execution>
            <id>copy-resources</id>
            <phase>validate</phase>
            <goals>
              <goal>copy-resources</goal>
            </goals>
            <configuration>
              <outputDirectory>${basedir}/target/MyFolder</outputDirectory>
              <resources>
                <resource>
                  <directory>resources</directory>
                  <filtering>true</filtering>
                </resource>
              </resources>
            </configuration>
          </execution>
        </executions>
      </plugin>
 
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <version>3.1.1</version>
        <executions>
          <execution>
            <id>copy-dependencies</id>
            <phase>prepare-package</phase>
            <goals>
              <goal>copy-dependencies</goal>
            </goals>
            <configuration>
              <outputDirectory>${project.build.directory}/MyFolder/lib</outputDirectory>
              <overWriteReleases>false</overWriteReleases>
              <overWriteSnapshots>false</overWriteSnapshots>
              <overWriteIfNewer>true</overWriteIfNewer>
            </configuration>
          </execution>
        </executions>
      </plugin>
   
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>3.1.0</version>
        <configuration>
          <archive>
            <manifest>
              <addClasspath>true</addClasspath>
              <classpathPrefix>lib/</classpathPrefix>
              <mainClass>u.request.MyExecutableClass</mainClass>
            </manifest>
            <manifestEntries>
              <Class-Path>.</Class-Path>
            </manifestEntries>
          </archive>
 
          <finalName>MyFolder/MyJars</finalName>
        </configuration>
      </plugin>
    </plugins>
  
  </build>
  
</project>
  


The new changes are displayed on a yellow background:

Lines 9-16 indicates the new maven repository to find the latest Sikuli version as states in the "README.md" file in the  Sikuli github.

Line 27 indicates the Sikulix version

Lines 107-112 indicates the dependency to add to the project.


3. The easy example

This is a similar example to all tutorials!!!!
  1. Right-click on the desktop window and create a new folder and name it "TestFolder".
  2. Use Shutter screenshot for selecting the image of the folder. As this one
  3. Name this image as "TestFolderImage.png" 
  4. Put it in a folder like "/home/user/myImages"  (where "user" is your username!!!)
  5. This is the address of the patter to find in the desktop screen "/home/user/myImages/TestFolderImage.png"
  6. Let's create a Screen element and a Pattern element and let's double click on the part of the Desktop region that matches this pattern image.
Here is the code 


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
package test;

import org.sikuli.script.FindFailed;
import org.sikuli.script.Pattern;
import org.sikuli.script.Screen;

public class Sikuli02 {

  public static void main(String[] args) throws FindFailed {
    Screen s = new Screen();
    Pattern folderToFind = new Pattern("/home/ximo/myImages/TestFolderImage.png");
    // Finds the image on the desktop and doubleclick on it
    s.doubleClick(folderToFind);  
  }
}