{"id":480,"date":"2010-08-16T11:35:15","date_gmt":"2010-08-16T01:35:15","guid":{"rendered":"\/blog\/?p=480"},"modified":"2011-07-05T11:55:17","modified_gmt":"2011-07-05T01:55:17","slug":"automating-flash-ajax-popups-and-more-using-ruby-watir-and-sikuli","status":"publish","type":"post","link":"http:\/\/www.software-testing.com.au\/blog\/2010\/08\/16\/automating-flash-ajax-popups-and-more-using-ruby-watir-and-sikuli\/","title":{"rendered":"Automating Flash, AJAX, Popups and more using Ruby, Watir and Sikuli"},"content":{"rendered":"<p><a href=\"http:\/\/www.kohl.ca\/\">Jonathan Kohl<\/a> pointed me at <a href=\"http:\/\/groups.csail.mit.edu\/uid\/sikuli\/\">Sikuli<\/a>, a Python-based tool for automating applications using image recognition.\u00a0 Unlike most tools, which attempt to identify objects via public APIs, Sikuli looks at the pixels on the screen and attempts to identify objects based on how they look.<\/p>\n<p>This isn&#8217;t exactly a new approach, as commercial tools have had this feature for a long time as a means of creating custom objects.\u00a0 So after playing with Sikuli, I wondered whether I could take advantage of it as a library to augment my Watir scripts in Ruby.<\/p>\n<p>It turns out, the answer is &#8216;yes&#8217;, with a caveat.\u00a0 You need to use JRuby (although you could probably do it in Ruby using the Ruby-Java bridge &#8211; It just looked a lot harder), and you also need to use Watir-Webdriver, a new implementation of Watir&#8217;s API which is used in a number of other automation frameworks.<\/p>\n<p>Below is a simple example script and instructions to get you started.\u00a0 It navigates to a website, then clicks on the flash control there. I&#8217;ve so far only tested this on Windows.\u00a0 It should work on OSX and Linux, but perhaps not quite so easily (I&#8217;m waiting on some feedback).\u00a0 Check the instructions for &#8216;Install OpenCV&#8217; at the <a href=\"http:\/\/sikuli.org\/trac\/wiki\/How%20to%20use%20Sikuli%20Script%20in%20your%20JAVA%20programs\">page with instructions for calling Sikuli from other tools<\/a>.<\/p>\n<p>Sikuli can be used to automate Flash components, any challenging AJAX elements of your web application, to dismiss pop-ups or probably even to inspect visual elements of the page (though I&#8217;d want to do this minimally).\u00a0 It&#8217;s a little slow, but an interesting and immediately useful add-on to Watir or your favourite java-based testing tool.<\/p>\n<p><code><br \/>\n#Install Java, or install the JRuby\/JRE bundle at the next step<br \/>\n#Install JRuby 1.5.1 - http:\/\/jruby.org\/download<br \/>\n#Install Sikuli - http:\/\/sikuli.org\/download.shtml<br \/>\n#Install watir-webdriver (eg. jgem install watir-webdriver)<br \/>\n#Update ssh - jgem install jruby-openssl<br \/>\n#Copy sikuli-script.jar to \\jruby-1.5.1\\lib<br \/>\n#Get the test image<br \/>\n#Download http:\/\/www.software-testing.com.au\/images\/flashmap_middleeast.png and put it in the image folder as below<br \/>\n#See http:\/\/sikuli.org\/trac\/wiki\/How to use Sikuli Script in your JAVA programs for examples<\/code><\/p>\n<p>require &#8216;rubygems&#8217;<br \/>\nrequire &#8216;watir-webdriver&#8217;<br \/>\nrequire &#8216;java&#8217;<\/p>\n<p>java_import &#8220;org.sikuli.script.SikuliScript&#8221;<br \/>\njava_import &#8220;org.sikuli.script.Region&#8221;<br \/>\njava_import &#8220;org.sikuli.script.Screen&#8221;<\/p>\n<p>start_page=&#8217;http:\/\/www.lonelyplanet.com&#8217;<br \/>\nimage_folder=&#8221;c:\/sikuli_icons\/&#8221;<\/p>\n<p>$screen=Screen.new<br \/>\n$browser=Watir::Browser.new :ie<br \/>\n$browser.goto start_page<\/p>\n<p>$screen.click(&#8220;#{image_folder}flashmap_middleeast.png&#8221;,0)<\/p>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 342px; width: 1px; height: 1px; overflow: hidden;\">http:\/\/sikuli.org\/download.shtml<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Jonathan Kohl pointed me at Sikuli, a Python-based tool for automating applications using image recognition.\u00a0 Unlike most tools, which attempt to identify objects via public APIs, Sikuli looks at the pixels on the screen and attempts to identify objects based on how they look. This isn&#8217;t exactly a new approach, as commercial tools have had [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[92,34,36,90],"tags":[98,96,99,100,95,97,139],"class_list":["post-480","post","type-post","status-publish","format-standard","hentry","category-technical-testing","category-test-automation","category-test-tools","category-tool-assisted-testing","tag-ajax","tag-flash","tag-pop-ups","tag-popups","tag-sikuli","tag-silverlight","tag-watir"],"_links":{"self":[{"href":"http:\/\/www.software-testing.com.au\/blog\/wp-json\/wp\/v2\/posts\/480","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.software-testing.com.au\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.software-testing.com.au\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.software-testing.com.au\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.software-testing.com.au\/blog\/wp-json\/wp\/v2\/comments?post=480"}],"version-history":[{"count":8,"href":"http:\/\/www.software-testing.com.au\/blog\/wp-json\/wp\/v2\/posts\/480\/revisions"}],"predecessor-version":[{"id":602,"href":"http:\/\/www.software-testing.com.au\/blog\/wp-json\/wp\/v2\/posts\/480\/revisions\/602"}],"wp:attachment":[{"href":"http:\/\/www.software-testing.com.au\/blog\/wp-json\/wp\/v2\/media?parent=480"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.software-testing.com.au\/blog\/wp-json\/wp\/v2\/categories?post=480"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.software-testing.com.au\/blog\/wp-json\/wp\/v2\/tags?post=480"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}