Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Automating interface testing with JRuby and Sikuli

Automating interface testing with JRuby and Sikuli

Creating a Diablo 3 bot and pwning your friends by showin! off your superior intelect and amazing coding skills

5dedfa2aa296b09ffa0a8b013491a5bb?s=128

Rodrigo Franco

November 03, 2012
Tweet

Transcript

  1. (^o^)

  2. None
  3. Automatin interface testin with JRuby e Sikuli UI (^o^) (

    bјct ab 3)
  4. @caffo http://rodri ofranco.com/ @caffo

  5. i apolo ize

  6. None
  7. None
  8. None
  9. no spanish, just brazilian portu uese :-)

  10. None
  11. None
  12. None
  13. None
  14. slow down, dammit!

  15. What is an interface test?

  16. “interface testin is the process of testin a product's user

    interface to ensure it meets its written specifications.” http://en.wikipedia.or /wiki/Graphical_user_interface_testin
  17. - unit testin - inte ration testin

  18. TestUnit rSpec Cucumber - unit testin - inte ration testin

  19. interfaces are complex

  20. Capybara Web Form DSL

  21. Selenium / Watir WebDriver

  22. interface testin == manual

  23. be able to see

  24. Project Sikuli http://sikuli.or

  25. None
  26. None
  27. None
  28. .rb ?

  29. .rb ? .applescript ?

  30. .rb ? .applescript ? .brainf#ck ?

  31. Empty the ***** trashcan!

  32. Project Sikuli http://sikuli.or

  33. None
  34. None
  35. None
  36. None
  37. None
  38. et back to the topic, shall we?

  39. None
  40. http://jruby.or

  41. Creatin a Diablo 3 bot and pwnin your friends by

    showin off your superior intelect and amazin codin skills
  42. None
  43. banned :(

  44. Diablo Runs

  45. Cellar Run

  46. None
  47. None
  48. None
  49. None
  50. None
  51. None
  52. None
  53. None
  54. None
  55. None
  56. None
  57. None
  58. slow down, dammit!

  59. in sum

  60. None
  61. None
  62. None
  63. None
  64. None
  65. exit

  66. (^o^)/

  67. 1 - initializin the bot 2 - clickin at fixed

    points 3 - auto-movement 4 - findin the cellar 5 - restartin the run 6 - creatin lo s 7 - enterin the cellar 8 - attackin the demons 9 - ettin the old today’s menu
  68. initializin the bot step 1 of 9

  69. require 'rubygems' require 'java'

  70. $CLASSPATH << "~/Sikuli-IDE.app/Contents/Resources/Java/" install packa e available at http://sikuli.or

  71. require "sikuli-script.jar"

  72. java_import 'org.sikuli.script.Region' java_import 'org.sikuli.script.Screen' java_import 'org.sikuli.script.Settings' java_import 'org.sikuli.script.SikuliEvent' java_import 'org.sikuli.script.SikuliScript'

  73. include Java

  74. class DiabloBot attr_accessor :screen, :image_path, :sikuli def initialize screen =

    Screen.new sikuli = SikuliScript.new image_path = File.dirname( File.expand_path($0) ) end end
  75. clickin at fixed points step 2 of 9

  76. @screen.click(Sikuli::Location.new(370,300))

  77. @screen.click(Sikuli::Location.new(370,300)) [about the coordinates]

  78. @sikuli.switch_app("Diablo III")

  79. def cellar_run @sikuli.switch_app("Diablo III") @screen.click(Sikuli::Location.new(370,300)) end

  80. None
  81. auto-movement step 3 of 9

  82. - define X key for auto-move - press X ->

    walk - press X -> stop auto-movement
  83. def move(delay = 0.5) @screen.key_down("x") sleep(delay) @screen.key_up("x") end

  84. def mm(times = 5) times.downto(0).each { move } end

  85. def cellar_run @sikuli.switch_app("Diablo III") @screen.click(Sikuli::Location.new(370,300)) mm(7) end

  86. None
  87. slow down, dammit!

  88. @screen.click(Sikuli::Location.new(720,493)) mm(3) (aÝ t t tה Î r_ n t

    d) leavin it in a better spot
  89. None
  90. d-(*o*)-b

  91. findin the cellar step 4 of 9

  92. def cellar_opened? @screen.find("#{self.image_path}/cellar_opened.png") end

  93. def cellar_closed? @screen.find("#{self.image_path}/cellar_closed.png") end

  94. if cellar_opened? enter_cellar else restart_run end

  95. ima e files (screenshots) ( вd tה sc pt c

    )
  96. restartin a run step 5 of 9

  97. exemple: manual execution

  98. None
  99. - press ESC - click at ‘Leave Game’ - wait

    - click at ‘Resume Game’ - wait a bit more
  100. def restart press(Sikuli::Key::ESC) click_coord(800,570) sleep(13) click("resume") sleep(6) cellar_run end

  101. def restart press(Sikuli::Key::ESC) click_coord(800,570) sleep(13) click("resume") sleep(6) cellar_run end ?

    ? ?
  102. def press(key, delay = 0.5) @screen.key_down(key) sleep(delay) @screen.key_up(key) end

  103. def click_coord(x, y) @screen.click(Sikuli::Location.new(x,y)) end

  104. def click(pattern) @screen.wait("#{image_path}/#{pattern}.png") @screen.click("#{image_path}/#{pattern}.png",0) end

  105. lo in the execution step 6 of 9

  106. require 'ostruct'

  107. stats = OpenStruct.new( :runs => 0, :closed => 0, :opened

    => 0, :not_found => 0 )
  108. if cellar_opened? stats.opened += 1 enter_cellar elsif cellar_closed? stats.closed +=

    1 restart else stats.not_found += 1 restart end
  109. <OpenStruct runs=220, closed=90, opened=130, not_found=0>

  110. enterin the cellar step 7 of 9

  111. None
  112. def enter_cellar click_coord(600,450) sleep(2) if @screen.find("#{self.image_path}/inside_cellar.png") stats.entered += 1 else

    restart end end
  113. None
  114. x click_coord(340,820) sleep(5)

  115. None
  116. attackin the demons step 8 of 9

  117. None
  118. - position the character - activate ran ed attack -

    wait enou h time - deactivate the attack - collect the money! $$$
  119. def attack_enemies @screen.key_down(Sikuli::Key::SHIFT) @screen.mouse_down(Sikuli::Button.LEFT) sleep(20) @screen.key_up(Sikuli::Key::SHIFT) sleep(2) @screen.mouse_up(Sikuli::Button.LEFT) end

  120. collectin the old step 9 of 9

  121. def any_gold? press(Sikuli::Key::ALT) @screen.find("#{self.image_path}/gold.png") end

  122. def get_all_gold if any_gold? click("gold") get_all_gold else puts "all got

    acquired" restart end end
  123. now everythin to ether! step NaN of 9

  124. None
  125. ^_^b

  126. https:// ist. ithub.com/ d49f704f129a2db188f0 http://bit.ly/NfCGI9

  127. http://rodri ofranco.com/ t nk u! @caffo @caffo

  128. None
  129. None
  130. http://bookqueue.net

  131. http://moourl.com