<<

Start of my journey and problems along the way @bgrgincic And the journey starts…

Goal: ◦ Automate GWT aplication regression tests Options? ◦ ? ⚫ Selenium IDE? ⚫ Selenium in Java? ◦ Watir (Web aplication testing in Ruby)? ◦ Something else? Let’s try Watir!

How to start? => https://leanpub.com/watirbook Selenium-webdriver Lost in xpaths

require "selenium-webdriver" b = Selenium::WebDriver.for :chrome … wait.until { b.find_element(:xpath, "///body/div[3]/div[2]/div/div/div[7]/table/tbody/tr[1]/td/table/tbody/tr[31] /td/table/tbody/tr[2]/td[2]/div") } b.find_element(:xpath, "//html/body/div[3]/div[2]/div/div/div[7]/table/tbody/tr[1]/td/table/tbody/tr[32]/td/table/tbody/tr [2]/td[2]/div/table/tbody/tr[1]/td/button/span").click p "Odabir razdoblja " b.find_element(:xpath, "//html/body/div[3]/div[2]/div/div/div[9]/div/div/table/tbody/tr/td/table/tbody/tr[1] /td/div/table/tbody/tr[2]/td/div/table/tbody/tr[1]/td/table/tbody/tr[1]/td[2]/table/tbody/tr/td/select").send_keys(„NAZIV") b.find_element(:xpath, "//html/body/div[3]/div[2]/div/div/div[9]/div/div/table/tbody/tr/td/table/tbody/tr[1] /td/div/table/tbody/tr[2]/td/div/table/tbody/tr[1]/td/table/tbody/tr[2]/td[2]/table/tbody/tr/td/select").send_keys("7") b.find_element(:xpath, "//html/body/div[3]/div[2]/div/div/div[9]/div/div/table/tbody/tr/td/table/tbody/tr[1] /td/div/table/tbody/tr[2]/td/div/table/tbody/tr[1]/td/table/tbody/tr[2]/td[3]/table/tbody/tr/td/select").send_keys("2013") b.find_element(:id, "button_btnTrazi_search").click b.find_element(:id, "button_btnOdaberi_select_calculation").click Watir-webdriver This seems like a nice API

require "watir" b = Watir::Browser.new :chrome …

b.span(:text, "Otvaranje").click b.select_list(:title, "Institucija").wait_until_present b.select_list(:title, "Institucija").select „Naziv" b.select_lists(:class, "spray-ComboBox spray-RequiredField spray-fld_plain")[1].click b.select_lists(:class, "spray-ComboBox spray-RequiredField spray-fld_plain")[1].select '7' b.select_lists(:class, "spray-ComboBox spray-RequiredField spray-fld_plain")[2].click b.select_lists(:class, "spray-ComboBox spray-RequiredField spray-fld_plain")[2].select "2013" b.button(:id, "button_btnTrazi_search").click b.button(:id, "button_btnOdaberi_select_calculation").click What seemed nice with Watir-webdriver API? Many different ways to access the elements ◦ :class, :css, :for, :href, :id, :index, :name, :src, :text, :value, : xpath Cool verification actions ◦ .exists?, .visible?, enabled?, present?, etc. Nice support for waits (good for ajax rich apps) And the problems begin… click of null- what?? 1/2

HTML: Watir test: b.button(:id, "button_btnTrazi_search").click click of null- what?? 2/2

Just close the console!

No problems afterwards The Devil’s in the details 1/2

Get select by class name The Devil’s in the details 2/2

Tip: click on a ‘select’ before ‘selecting’

of death 1/2

„loading”

of death 2/2

Solution #1: put check before every command?

Solution #2: define a „proxy” Quick final thoughts

Ruby is pretty fun and easy ◦ You can start using Watir without knowing much about Ruby Cheatsheets are useful ◦ https://github.com/watir/watir/wiki/Cheat-Sheet ◦ https://github.com/watir/watir/wiki/Cheat-Sheet-for-Ruby ◦ http://relevantcodes.com/watir-webdriver-cheat-sheet/ There’s also useful stuff on ◦ http://stackoverflow.com ◦ http://watirmelon.com/ ◦ http://filipin.eu/ The future?

Find a cool IDE instead of Notepad++ Get a Watir recorder? Do I need (behavior-driven development)? Use advanced patterns: page objects etc.