It's Sunday so good time for something new and today we'll check out Sikuli, definitely not the newest solution but yet pretty handy and useful one. As usually we start as average user - from setting up environment till writing code in IDE and actually running that.
1. Installing Sikuli.
First we have open: http://www.sikuli.org/download.html - and download setup.jar on our PC. As suggested on screen below we have to save it in folder named SikuliX and run. If You're getting errors it means something wrong with Your java installation (which is needed) in this case I'd recommend You to look into steps I & III from: http://tech-memories.blogspot.com/2014/07/you-first-test-in-java-vs-testng-vs.html.
During first setup run You'll see same screens as below so simply choose needed options and click setup.
2. Creating first Sikuli script with Sikuli IDE.
After finishing Sikuli installation let's create our project with Maven (it should be installed after step III from instructions above). What You need just open in console some folder in which Your project will be created and run next command: "mvn archetype:generate -DarchetypeGroupId=org.apache.maven.archetypes -DgroupId=com.testproject -DartifactId=FirstSikulliTest -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false" - that's it - Maven will create all what You'll need in future.
After that run siculi-ide.jar and save Your project in the same folder. After these two actions You should have same screen as one below. In case it's difficult - I'll add link for git repo with everything just ready for clone at the end of post.
This how main Sikuli window looks like during first run.
As for me Sikuli is pretty intuitive one and script creation process one of the easiest I ever seen. So You simply need to click on one option of the right panel, then Sikuli will prompt You to select area on the screen and will save a screenshot of needed element.
Here I'll just briefly describe test I've written (I won't go into details, because You can download that from repo, open in Sikuli and run by Your own).
Test Case:
- open firefox browser (You'll need to replace my firefox screens with Your own)
- go to allegro.pl (as always my favorite site for testing new tools)
- type in search bar - "laptop"
- choose sort by highest price
- choose first item
- add item to the bucket
- verify that Your bucket contains one item
As You can see test case is pretty straight forward but we don't need to create a complicated one to get familiar with Sikuli.
Once again - after replacing firefox screens save script and simply Run that.
You probably noticed and aware that such cases we can easily write in Java with WebDriver, by the way we can write our own code not just clicking in Sikuli itself using Jython (something like Java + Python). On the other side in real life there're several cases when WebDriver fails to solve our needs - and one of those - handling native system dialog windows, so here I'll show You how to combine WebDriver and Sikuli for such purpose.
3. Creating Java project with WebDriver + Sikuli combination.
Open IntelliJIDEA and import project(You should have that created from instructions described in previous step) as shown on screens below.
After importing project we have to open project settings and add "sikuli-java.jar" from installation folder to our classpath.
Now we can write a code. Again I won't explain all steps from code (cause it's on the repo as well) but I'll write a test steps for test scenario:
- open chrome browser (for browser start we're using WebDriver - so doesn't matter which You'll use, but don't forget to update needed screens for Sikuli)
- wait until pdf is loaded (I simply put delay here)
- press download button
- save book on desktop
- minimize all windows
- verify that book is saved to our desktop
As You can see process is pretty obvious and if something goes wrong - just try to check everything step by step from beginning (project definitely works for me) or just leave me a comment under post. Also You can look on Sikuli official page for more information (truly speaking their example doesn't work - or it's better to say doesn't described in the best way).
P.S. as promised github repo: https://github.com/operep/Sikulli_Test_Project.git . Enjoy!
Hi,
ReplyDeleteNow, Sikuli API can run directly on Android.
AnkuLua = Android + Sikuli + Lua
We are the developer of AnkuLua.
Welcome to try AnkuLua and give us feedbacks.
Thanks for mentioning - I'll give it a try
Delete