├── test_results └── .empty ├── features ├── .DS_Store ├── fixtures │ └── test_data.yml ├── support │ ├── create_screenshot_folder.rb │ ├── read_config.rb │ ├── paths.rb_example │ ├── check_missing_translations.rb │ ├── screenshot.rb │ ├── env.rb │ └── watircuke.rb ├── sample.feature └── step_definitions │ └── watircuke_steps.rb ├── TextMateBundles └── WatirCuke.tmbundle.zip ├── .gitignore ├── lib └── popup_killer_ie.rb ├── config ├── geminstaller.yml └── config.yml_example ├── WatirCuke.rb └── README /test_results/.empty: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /features/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gs/watircuke/master/features/.DS_Store -------------------------------------------------------------------------------- /features/fixtures/test_data.yml: -------------------------------------------------------------------------------- 1 | data_example: 2 | id: 1 3 | name: foo 4 | job: bar 5 | -------------------------------------------------------------------------------- /TextMateBundles/WatirCuke.tmbundle.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gs/watircuke/master/TextMateBundles/WatirCuke.tmbundle.zip -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | config/config.yml 2 | features/*.feature 3 | features/fixtures/* 4 | features/support/paths.rb 5 | dictionary 6 | .DS_Store 7 | .features-3XzR 8 | *.sh 9 | *.html 10 | test_results/* 11 | .redcar/* 12 | features/step_definitions/* 13 | watir/* 14 | config/config.yml 15 | -------------------------------------------------------------------------------- /features/support/create_screenshot_folder.rb: -------------------------------------------------------------------------------- 1 | require 'fileutils' 2 | 3 | def create_screenshot_folder(folder, t) 4 | begin 5 | FileUtils.mkpath("test_results/#{folder}_#{t}/screenshots") 6 | rescue Exception => ex 7 | puts "#{ex}".red 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /features/support/read_config.rb: -------------------------------------------------------------------------------- 1 | require 'yaml' 2 | def read_config 3 | begin 4 | config_file = YAML.load_file("#{Dir.pwd}/config/config.yml") 5 | @browser = config_file['config']['browser'] 6 | @translation_tag = config_file['config']['translation_tag'] 7 | @check_translation = config_file['config']['check_translation'] 8 | @fixtures = config_file['config']['fixtures'].split(" ") 9 | rescue Exception => e 10 | puts "#{e}".red 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /lib/popup_killer_ie.rb: -------------------------------------------------------------------------------- 1 | require 'rubygems' 2 | require 'win32ole' 3 | 4 | begin 5 | autoit = WIN32OLE.new('AutoItX3.Control') 6 | loop do 7 | autoit.ControlClick("Windows Internet Explorer","", "OK") 8 | autoit.ControlClick("Security Information","", "&Yes") 9 | autoit.ControlClick("Security Alert","", "&Yes") 10 | autoit.ControlClick("Security Warning","", "Yes") 11 | autoit.ControlClick("Message from webpage","", "OK") 12 | sleep 1 13 | end 14 | rescue Exception => e 15 | puts e 16 | end 17 | -------------------------------------------------------------------------------- /features/sample.feature: -------------------------------------------------------------------------------- 1 | Feature: Try it out 2 | 3 | Scenario: Click a Button 4 | Given I am on the watircuke page 5 | And I click the "Rubyist" button 6 | Then I should see the sentence "Who am I?" 7 | 8 | Scenario: Select a Value 9 | Given I am on the watircuke page 10 | And I select "Ruby" from "class_select" # @browser.select_list(:class, /(^|\s)#{what}(\s|$)/).set(option) 11 | And I select "Cucumber" from "post_category" # @browser.select_list(:id, what).select(option) 12 | Then I should NOT see the text "FOOBAR" -------------------------------------------------------------------------------- /config/geminstaller.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # 3 | # This is a GemInstaller config file (http://geminstaller.rubyforge.org) 4 | # 5 | # This is a list of all gems needed to work with watircuke 6 | # 7 | defaults: 8 | install_options: --include-dependencies 9 | gems: 10 | - name: cucumber 11 | - name: watir 12 | - name: firewatir 13 | - name: rb-appscript 14 | - name: safariwatir 15 | - name: syntax 16 | - name: colorize 17 | - name: chronic 18 | - name: win32console 19 | - name: ruby-debug 20 | - name: watir-webdriver 21 | - name: rspec 22 | - name: nokogiri -------------------------------------------------------------------------------- /config/config.yml_example: -------------------------------------------------------------------------------- 1 | config: 2 | #browser can be -> firefox, ie, chrome, safari 3 | browser: ie 4 | #fixtures are languages.yml files 5 | fixtures: test_data 6 | #test urls 7 | server_lang: staging home pl 8 | server_login_lang: staging login pl 9 | mybusiness_url: staging.qype.pl/mybusiness/ 10 | admin_login: admin staging login 11 | #true/false = check if there are missing translations on scenario end 12 | check_translation: true 13 | #this is a regexp template for validation on page for missing translations 14 | translation_tag: "@[0-9a-zA-Z]+_[0-9a-zA-Z]+" 15 | -------------------------------------------------------------------------------- /features/support/paths.rb_example: -------------------------------------------------------------------------------- 1 | module Paths 2 | def path_to(page_name) 3 | case page_name 4 | # @environment comes from env.rb where it is set to "http://" 5 | #Test any external site 6 | 7 | when /the google home page/i 8 | @environment + "google.com" 9 | #Test any of your local apps 10 | when /the localhost page/i 11 | @environment + "localhost:3000" 12 | 13 | when /the youtube page/i 14 | @environment + "youtube.com" 15 | 16 | else 17 | raise "Can't find mapping from \"#{page_name}\" to a path.\n" + 18 | "Now, go and add a mapping in #{__FILE__}" 19 | end 20 | end 21 | end 22 | 23 | World(Paths) 24 | -------------------------------------------------------------------------------- /features/support/check_missing_translations.rb: -------------------------------------------------------------------------------- 1 | def check_missing_translations 2 | #create a hash and reads the url page content looking for given translation's missing template 3 | h = Hash.new 4 | if doc = Nokogiri.HTML(open(@browser.url)) 5 | doc.text.each_line { |line| 6 | words = line.split 7 | words.each { |w| 8 | if w.match(TRANSLATION_TAG) 9 | if h.has_key?(w) 10 | h[w] = h[w] + 1 11 | else 12 | h[w] = 1 13 | end 14 | end 15 | } 16 | } 17 | 18 | # sort the hash by value, and then print it in this sorted order 19 | h.sort{|a,b| a[1]<=>b[1]}.each { |elem| 20 | puts "     Missing translation: #{elem[0]} has #{elem[1]} occurrences on #{@browser.url.to_s} page    ->   " 21 | t = Time.new.to_i 22 | embed_screenshot("#{@screenshot_path}screenshot-#{t}", "screenshots/screenshot-#{t}") 23 | puts "" 24 | } 25 | else 26 | return {} 27 | end 28 | end 29 | -------------------------------------------------------------------------------- /features/support/screenshot.rb: -------------------------------------------------------------------------------- 1 | # This is an example of how you can set up screenshots for your 2 | # browser testing. Just run cucumber with --format html --out report.html 3 | # 4 | # The code below will work on OS X or Windows (with IE Watir only). 5 | # Adding support for other platforms should be easy - as long as there is a 6 | # ruby library or command line tool to take pictures. 7 | # 8 | module Screenshots 9 | if Cucumber::OS_X 10 | def embed_screenshot(id, to_html) 11 | `screencapture -t png #{id}.png` 12 | embed("#{to_html}.png", "image/png") 13 | end 14 | elsif Cucumber::WINDOWS 15 | # http://wtr.rubyforge.org/rdoc/classes/Watir/ScreenCapture.html 16 | require 'watir/screen_capture' 17 | include Watir::ScreenCapture 18 | def embed_screenshot(id, to_html) 19 | id = Dir.pwd.gsub("/","\\") + "\\" + id.gsub("/","\\") 20 | screen_capture("#{id}.jpg", true) 21 | embed("#{to_html}.jpg", "image/jpg") 22 | end 23 | else 24 | # Other platforms... 25 | def embed_screenshot(id, to_html) 26 | STDERR.puts "Sorry - no screenshots on your platform yet." 27 | end 28 | end 29 | end 30 | World(Screenshots) 31 | 32 | # After do |scenario| 33 | # embed_screenshot("#{@screenshot_path}screenshot-#{Time.new.to_i}") if scenario.failed? 34 | # end 35 | 36 | # Other variants: 37 | # 38 | # Only take screenshot on failures 39 | # 40 | # After do |scenario| 41 | # embed_screenshot("screenshot-#{Time.new.to_i}") if scenario.failed? 42 | # end 43 | # 44 | # Only take screenshot for scenarios or features tagged @screenshot 45 | # 46 | # After(@screenshot) do 47 | # embed_screenshot("screenshot-#{Time.new.to_i}") 48 | # end 49 | -------------------------------------------------------------------------------- /WatirCuke.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require 'rubygems' 3 | require 'cucumber' 4 | require 'colorize' 5 | 6 | require 'features/support/create_screenshot_folder' 7 | 8 | #this are the tests that have config_ files in config/machine/config_*.yml files - designed to work with sanity checks 9 | tests=%w/bbc_en bbc_de bbc_pl bbc_es staging_en staging_de staging_pl staging_es live_en live_de live_pl live_es/ 10 | 11 | class RunMe 12 | 13 | def initialize(tests) 14 | @tests = tests 15 | system "killall -9 firefox-bin" 16 | end 17 | 18 | def start 19 | if @tests.include?(ARGV[0]) 20 | test_name = name_the_test 21 | copy_config_yml_file 22 | folder = setup(ARGV[0]) 23 | system "cucumber --guess -t @#{test_name} -f html > #{folder}/../#{ARGV[0]}.html" 24 | elsif ("#{ARGV[0]}" =~/\@/) 25 | folder = setup(ARGV[1] ||= ARGV[0].gsub("\@","").gsub("\,","_")) 26 | system "cucumber --guess -t #{ARGV[0]} -f html > #{folder}/../#{ARGV[1]}.html" 27 | elsif ("#{ARGV[0]}" =~/features/) 28 | folder = setup(ARGV[1] ||= ARGV[0].gsub(/\w+\//,"").gsub(/\.\w+/,"")) 29 | system "cucumber --guess #{ARGV[0]} -f html > #{folder}/../#{ARGV[1]}.html" 30 | else 31 | puts "Did not found the test.".red 32 | puts 33 | puts "You could run me with:" 34 | puts "./WatirCuke.rb @tag output".green 35 | puts "or" 36 | puts "./WatirCuke.rb features/my_test.feature output".green 37 | puts " " 38 | @tests.collect! {|x| x + ", " } 39 | print "or with any of the tests: " 40 | print "#{@tests}".yellow 41 | puts 42 | puts "./WatirCuke.rb live_en".green 43 | end 44 | end 45 | 46 | def setup(folder) 47 | t=Time.now.strftime("%y%m%d%H%M") 48 | create_screenshot_folder("#{folder}", t) 49 | end 50 | 51 | def name_the_test 52 | ARGV[0].gsub(/\w+\_/,"") 53 | end 54 | 55 | def copy_config_yml_file 56 | config_name = "config_" + ARGV[0].to_s 57 | FileUtils.cp "./config/machines/#{config_name}.yml", "./config/config.yml" 58 | end 59 | 60 | end 61 | 62 | run = RunMe.new(tests) 63 | 64 | run.start 65 | -------------------------------------------------------------------------------- /features/support/env.rb: -------------------------------------------------------------------------------- 1 | require 'rubygems' 2 | require 'colorize' 3 | require 'fileutils' 4 | require 'ruby-debug' 5 | require 'chronic' 6 | require 'spec' 7 | require 'nokogiri' 8 | require 'open-uri' 9 | require 'test/unit/assertions' 10 | require 'features/support/read_config' 11 | require 'features/support/create_screenshot_folder' 12 | require 'features/support/screenshot' 13 | require 'features/support/check_missing_translations' 14 | require 'cucumber/formatter/unicode' 15 | include Test::Unit::Assertions 16 | 17 | 18 | begin 19 | #read the config.yml file found in config/config.yml 20 | ##-------------------------------------------------- 21 | read_config 22 | 23 | BROWSER = @browser 24 | CHECK_TRANSLATIONS = @check_translation 25 | TRANSLATION_TAG = @translation_tag 26 | LANGUAGES = @fixtures 27 | 28 | ##------------------------------------------------- 29 | 30 | 31 | if Dir['test_results/*'].select{|x| File.directory?(x)}.map{|x| [File.ctime(x), x]}.sort_by{|x| x.first}.last 32 | screenshot_path = (Dir['test_results/*'].select{|x| File.directory?(x)}.map{|x| [File.ctime(x), x]}.sort_by{|x| x.first}.last.last.inspect + "/screenshots/").gsub!("\"","") 33 | # screenshot_path += "/screenshots/" 34 | # screenshot_path.gsub!("\"","") 35 | else 36 | screenshot_path = "test_results/screenshots/" 37 | end 38 | 39 | case BROWSER 40 | when "safari" 41 | require 'safariwatir' 42 | Browser = Watir::Safari.new 43 | #Browser.set_fast_speed = true 44 | 45 | when "firefox" 46 | 47 | # require 'firewatir' 48 | 49 | # require 'watir/firewatir/lib/firewatir' 50 | # Browser = FireWatir::Firefox.new 51 | # 52 | require 'watir-webdriver' 53 | Browser = Watir::Browser.new :firefox 54 | # # # 55 | # require 'vapir-firefox' 56 | # Browser = Vapir::Firefox.new 57 | # 58 | # class Vapir::Firefox::Element 59 | # def type_keys 60 | # false 61 | # end 62 | # end 63 | 64 | when "chrome" 65 | require 'watir-webdriver' 66 | Browser = Watir::Browser.new :chrome 67 | 68 | when "ie" 69 | require 'watir' 70 | require 'watir/ie' 71 | require 'win32ole' 72 | require 'win32/process' 73 | Browser = Watir::IE.new 74 | Browser.speed = :zippy #browser speed :fast / :zippy 75 | 76 | when "celerity" 77 | require 'celerity' 78 | Browser = Celerity::Browser.new 79 | else 80 | raise "This platform is not supported (#{PLATFORM})" 81 | end 82 | 83 | 84 | #create screenshot folder function 85 | # screenshot_path = create_screenshot_folder 86 | 87 | browser = Browser 88 | # "before all" 89 | Before do 90 | @table = {} 91 | @screenshot_path = screenshot_path 92 | 93 | LANGUAGES.each { |table| @table.merge! YAML.load_file("features/fixtures/#{table}.yml") } 94 | @table.merge! YAML.load_file("config/config.yml") 95 | 96 | @browser = browser 97 | @environment = "http://" 98 | @time = Time.now 99 | end 100 | 101 | #after each scenario: checking for missing translation on page, count scenario time, makes screenshot if failed 102 | After do |scenario| 103 | t = Time.new.to_i 104 | check_missing_translations if CHECK_TRANSLATIONS 105 | embed_screenshot("#{@screenshot_path}screenshot-#{t}", "screenshots/screenshot-#{t}") if scenario.failed? 106 | scenario_time(@time) 107 | end 108 | 109 | # after each step which is called '@new_feature' make a screenshot 110 | AfterStep('@new_feature') do 111 | t = Time.new.to_i 112 | embed_screenshot("#{@screenshot_path}screenshot-#{t}", "screenshots/screenshot-#{t}") 113 | end 114 | rescue Exception => ex 115 | puts "#{ex}".red 116 | end 117 | -------------------------------------------------------------------------------- /features/step_definitions/watircuke_steps.rb: -------------------------------------------------------------------------------- 1 | Transform /^\:\w*\.\w*$/ do |step_arg| 2 | what = parse_from_yaml(step_arg) if fixture?(step_arg) 3 | end 4 | 5 | # Given /I click the "(.*)" button/ do |what| 6 | # find_button(what) 7 | # end 8 | 9 | Given /I click the "(.*)" button(.*)/ do |what, alert| 10 | if alert == " with alert" 11 | click_alert_button_ok 12 | end 13 | find_button(what) 14 | end 15 | 16 | 17 | Given /I click the "(.*)" checkbox/ do |what| 18 | find_checkbox(what) 19 | end 20 | 21 | Given /I click the "(.*)" div/ do |what| 22 | find_div(what) 23 | end 24 | 25 | Given /I click the "(.*)" image/ do |what| 26 | find_image(what) 27 | end 28 | 29 | Given /I click the "(.*)" link(.*)/ do |what, what2| 30 | if what2 == " with alert" 31 | click_alert_button_ok 32 | find_link(what) 33 | elsif what2 =~ /with index \d+/ 34 | index = what2.gsub(" with index ","") 35 | @browser.link(:text => what, :index => index.to_i).click 36 | else 37 | find_link(what) 38 | end 39 | end 40 | 41 | Given /I onmouseover the "(.*)" link$/ do |what| 42 | @browser.link(:text, /#{what}/).exists? 43 | @browser.link(:text, /#{what}/).fire_event('onmouseover') 44 | end 45 | 46 | Given /I click the "(.*)" radio button/ do |what| 47 | find_radio_button(what) 48 | end 49 | 50 | Given /I click row "(.*)" in the "(.*)" table/ do |row, column, what| 51 | find_table(row, column, what) 52 | end 53 | 54 | Given /I select "(.*)" from "(.*)"/ do |with, what| 55 | find_select_list(with, what) 56 | end 57 | 58 | Given /I fill in the text field "(.*)" with "(.*)"/ do |tf_name, what| 59 | find_text_field(tf_name, what) 60 | end 61 | 62 | Given /I fill in the date field "(.*)" with "(.*)"/ do |tf_name, what| 63 | find_text_field(tf_name, calculate_date(what)) 64 | end 65 | 66 | 67 | 68 | Given /I fill in the file field "(.*)" with "(.*)"/ do |ff_name, what| 69 | find_file_field(ff_name, what) 70 | end 71 | 72 | 73 | Then /I refresh the page/ do 74 | @browser.refresh 75 | # @browser.wait 76 | end 77 | 78 | Then /I should see the "(.*)" image/ do |what| 79 | assert(@browser.image(:src, /what/).height.to_i == 0) ? false : true 80 | end 81 | 82 | Then /I take a screenshot/ do 83 | t = Time.new.to_i 84 | embed_screenshot("#{@screenshot_path}screenshot-#{t}", "screenshots/screenshot-#{t}") 85 | end 86 | 87 | Then /I should see the span "(.*)" with "(.*)"/ do |span, what| 88 | find_span(span, what) 89 | end 90 | 91 | Then /^I should (NOT )?see the text "(.*)"$/ do |visibility, what| 92 | expected = (visibility.to_s.strip == 'NOT') ? @browser.text.index(what).should == nil : @browser.text.index(what).should >= 0 93 | end 94 | 95 | Then /^It should (NOT )?contains the html "([^\"]*)"$/ do |visibility, what| 96 | expected = (visibility.to_s.strip == 'NOT') ? @browser.html.index(what).should == nil : @browser.html.index(what).should >= 0 97 | end 98 | 99 | Then /I click the "(.*)" link until I see the text "(.*)"/ do |click_link, what_to_see| 100 | find_link(click_link) 101 | while !@browser.text.index(what_to_see) do 102 | @browser.back 103 | sleep 10 104 | find_link(click_link) 105 | end 106 | @browser.text.index(what_to_see) != nil 107 | end 108 | 109 | Then /^I debug$/ do 110 | debugger 111 | end 112 | 113 | Given /I am redirected to "(.*)"/ do |what| 114 | url = @browser.url 115 | assert_equal(@environment + what, url) 116 | end 117 | 118 | Given /^I am on the "(.+)" page$/ do |page_name| 119 | @browser.goto(path_to(page_name)) #This step links up with the "path_to" method found in support/paths.rb 120 | end 121 | 122 | Given /^I go to "([^\"]*)"$/ do |url| 123 | @browser.goto(url) #Links to generic urls like "google.com" 124 | end 125 | 126 | Given /^I sleep for "([^\"]*)"$/ do |seconds| 127 | sleep seconds.to_i 128 | end 129 | Given /^I check all objects$/ do 130 | create_output 131 | end 132 | 133 | Then /sleep until I see the text "(.*)"/ do |what| 134 | # expected = @browser.text.index(what).should >= 0 135 | while !@browser.text.index(what) do 136 | sleep 1 137 | end 138 | @browser.text.index(what) != nil 139 | end 140 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | INSTALL 2 | 3 | First be sure to have installed Ruby(1.8.7) and RubyGems 4 | 5 | Then install: 6 | 7 | gem install geminstaller 8 | 9 | Then checkout the WatirCuke git repo (if not yet done ;) ) and type 10 | 11 | geminstaller config/geminstaller.yml 12 | 13 | This will install all necessary gems. 14 | 15 | Then install JSSH for FireWatir: 16 | http://wiki.openqa.org/display/WTR/FireWatir+Installation 17 | 18 | 19 | TextMate or Redcar editor snippets: 20 | 21 | Any of the editors like TextMate or Redcar syntax recognition and snippets for Cucumber 22 | 23 | http://github.com/bmabey/cucumber-tmbundle 24 | 25 | 26 | To have WatirCuke support snippets just unpack the WatirCuke.tmbundle.zip which is in my github in TextMateBundles repo and place it in 27 | 28 | TextMate: 29 | ~/Library/Application Support/TextMate/Bundles 30 | 31 | Then in TextMate -> Bundles -> Bundle Editor -> Reload Bundles 32 | 33 | Redcar: 34 | ~/.redcar/Bundles/ 35 | 36 | 37 | Snippets should work for .feature files. 38 | 39 | Below are currently supported sentences: 40 | 41 | Actions: 42 | 43 | link[tab] I click the "some" button 44 | checkbox[tab] I click the "some" checkbox 45 | image[tab] I click the "some" image 46 | link[tab] I click/onmouseover the "some" link (with alert) 47 | radio[tab] I click the "some" radio button 48 | table[tab] I click row "some" in the "some" table 49 | list[tab] I select "some" from "from list" 50 | tf[tab] I fill in the text field "text field name" with "some text" 51 | df[tab] I fill in the date field "text field name" with "*fraze" *from http://chronic.rubyforge.org/ are supported 52 | ff[tab] I fill in the file field "file field name" with "file path" 53 | div[tab] I click the "some" div 54 | *screenshot[tab] I take a screenshot 55 | debug[tab] I debug 56 | refresh[tab] I refresh the page 57 | 58 | Check results: 59 | check_image[tab] Then I should see the "some image" image 60 | check_span[tab] Then I should see the span "some class" with "some text" 61 | check_sentence[tab] Then I should (NOT )?see the sentence "some sentence" 62 | check_text[tab] Then I should (NOT )?see the text "some text" 63 | check_all[tab] Then I check all objects (this will dump all page objects to file) 64 | 65 | Paths redirection: 66 | red[tab] I am redirected to "some" 67 | on[tab] I am on the "server" page 68 | goto[tab] I go to "some url" 69 | sleep[tab] I sleep for "some" 70 | sleepu[tab] sleep until I see the text "text" 71 | 72 | 73 | tag @new_feature - putted above the scenario will force watircuke to make a screenshot after each action. 74 | 75 | 76 | Configuration: 77 | 78 | Configuration is kept in the config/config.yml file 79 | 80 | - You can specify running browser using one of : ie, firefox, chrome, safari 81 | browser: ie 82 | 83 | - **Fixtures/Language files separated with " " (files which contains translations without the .yml extension) 84 | fixtures: login logout 85 | 86 | - true / false for check for missing translation 87 | check_translation: true 88 | 89 | - Only will work if above check_translation is set to true. 90 | Below is a template for regexp which will look after each scenario for missing translations ie: @ 91 | 92 | translation_tag: "@[0-9a-zA-Z]+_[0-9a-zA-Z]+" - this will match every string on page which fits to template 93 | 94 | 95 | 96 | 97 | How to run: 98 | 99 | 1) WatirCuke can be run with tags like: 100 | ./WatirCuke.rb @tag1,@tag2 output 101 | 102 | 2) Can be run with feature files: 103 | ./WatirCuke.rb features/file.feature output 104 | 105 | All above will produce the html output and move it into test_results folder 106 | 107 | 3) WatirCuke can be run with standard CUCUMBER : cucumber -t @tags -f format -o output 108 | 109 | *screenshot - will be dropped in test_results/test_datetime/screenshots/ - this structure is created each time cucumber is being run 110 | 111 | ** Fixtures/Language files can be dropped into : 'features/fixtures' path. 112 | They need to be in YML format like: 113 | login: 114 | login_button: Sign up 115 | 116 | Then in scenario you have to use it like: 117 | 118 | I click the ":login.login_button" button 119 | 120 | That will import the value from attached fixture file. 121 | 122 | 123 | ***cukewatir maximizes the Gherkin speak and minimizes the Watir code. 124 | 125 | License: 126 | 127 | MIT -------------------------------------------------------------------------------- /features/support/watircuke.rb: -------------------------------------------------------------------------------- 1 | module WatirCukeHelpers 2 | def find_button(what) 3 | case 4 | when @browser.button(:id, what).exists? 5 | then @browser.button(:id, what).click 6 | 7 | when @browser.button(:name, what).exists? 8 | then @browser.button(:name, what).click 9 | 10 | when @browser.button(:value, what).exists? 11 | then @browser.button(:value, what).click 12 | 13 | when @browser.button(:class, what).exists? 14 | then @browser.button(:class, what).click 15 | 16 | when @browser.button(:text, what).exists? 17 | then @browser.button(:text, what).click 18 | 19 | when @browser.button(:index, what.to_i).exists? 20 | then @browser.button(:index, what.to_i).click 21 | 22 | # when @browser.button(:text, /#{what}/).exists? 23 | # then @browser.button(:text, /#{what}/).click 24 | else 25 | fail("Sorry, I wasn't able to find the " + "'#{what}'" + " element ") 26 | end 27 | end 28 | 29 | def find_checkbox(what) 30 | case 31 | when @browser.checkbox(:id, what).exists? 32 | then @browser.checkbox(:id, what).click 33 | 34 | when @browser.checkbox(:name, what).exists? 35 | then @browser.checkbox(:name, what).click 36 | 37 | when @browser.checkbox(:value, what).exists? 38 | then @browser.checkbox(:value, what).click 39 | 40 | when @browser.checkbox(:text, what).exists? 41 | then @browser.checkbox(:text, what).click 42 | 43 | when @browser.checkbox(:class, what).exists? 44 | then @browser.checkbox(:class, what).click 45 | 46 | when @browser.checkbox(:index, what.to_i).exists? 47 | then @browser.checkbox(:index, what.to_i).click 48 | 49 | else 50 | fail("Sorry, I wasn't able to find the " + "'#{what}'" + " element ") 51 | end 52 | end 53 | 54 | def find_image(what) 55 | case 56 | when @browser.image(:src, what).exists? 57 | then @browser.image(:src, what).click 58 | 59 | when @browser.image(:id, what).exists? 60 | then @browser.image(:id, what).click 61 | 62 | when @browser.image(:name, what).exists? 63 | then @browser.image(:name, what).click 64 | 65 | when @browser.image(:text, what).exists? 66 | then @browser.image(:text, what).click 67 | 68 | when @browser.image(:alt, what).exists? 69 | then @browser.image(:alt, what).click 70 | 71 | when @browser.image(:class, what).exists? 72 | then @browser.image(:class, what).click 73 | 74 | when @browser.image(:index, what.to_i).exists? 75 | then @browser.image(:index, what.to_i).click 76 | 77 | else 78 | fail("Sorry, I wasn't able to find the " + "'#{what}'" + " element ") 79 | end 80 | end 81 | 82 | def find_link(what) 83 | case 84 | when @browser.link(:text, what).exists? 85 | then @browser.link(:text, what).click 86 | 87 | when @browser.link(:id, what).exists? 88 | then @browser.link(:id, what).click 89 | 90 | 91 | when @browser.link(:class, what).exists? 92 | then @browser.link(:class, what).click 93 | 94 | when @browser.link(:text, /#{what}/).exists? 95 | then @browser.link(:text, /#{what}/).click 96 | 97 | when @browser.link(:id, /#{what}/).exists? 98 | then @browser.link(:id, /#{what}/).click 99 | 100 | when @browser.link(:title, what).exists? 101 | then @browser.link(:title, what).click 102 | 103 | when @browser.link(:href, /#{what}/).exists? 104 | then @browser.link(:href, /#{what}/).click 105 | 106 | else 107 | fail("Sorry, I wasn't able to find the " + "'#{what}'" + " element ") 108 | end 109 | end 110 | 111 | def find_radio_button(what) 112 | case 113 | when @browser.radio(:id, what).exists? 114 | then @browser.radio(:id, what).click 115 | 116 | when @browser.radio(:name, what).exists? 117 | then @browser.radio(:name, what).click 118 | 119 | when @browser.radio(:value, what).exists? 120 | then @browser.radio(:value, what).click 121 | 122 | when @browser.radio(:text, what).exists? 123 | then @browser.radio(:text, what).click 124 | 125 | when @browser.radio(:class, what).exists? 126 | then @browser.radio(:class, what).click 127 | 128 | 129 | when @browser.radio(:index, what.to_i).exists? 130 | then @browser.radio(:index, what.to_i).click 131 | 132 | else 133 | fail("Sorry, I wasn't able to find the " + "'#{what}'" + " element ") 134 | end 135 | end 136 | 137 | def find_table(row, column, what) 138 | row = row.to_i 139 | column = column.to_i 140 | case 141 | when @browser.table(:id, what).exists? 142 | then @browser.table(:id, what)[row][column].click 143 | 144 | when @browser.table(:name, what).exists? 145 | then @browser.table(:name, what)[row][column].click 146 | 147 | when @browser.table(:class, what).exists? 148 | then @browser.table(:class, what)[row][column].click 149 | 150 | when @browser.table(:index, what.to_i).exists? 151 | then @browser.table(:index, what.to_i)[row][column].click 152 | 153 | else 154 | fail("Sorry, I wasn't able to find the " + "'#{what}'" + " element ") 155 | end 156 | end 157 | 158 | def find_select_list(option, what) 159 | case 160 | when @browser.select_list(:id, what).exists? 161 | then @browser.select_list(:id, what).select(option) 162 | 163 | when @browser.select_list(:name, what).exists? 164 | then @browser.select_list(:name, what).select(option) 165 | 166 | when @browser.select_list(:value, what).exists? 167 | then @browser.select_list(:value, what).select(option) 168 | 169 | when @browser.select_list(:text, what).exists? 170 | then @browser.select_list(:text, what).select(option) 171 | 172 | when @browser.select_list(:class, /(^|\s)#{what}(\s|$)/).exists? 173 | then @browser.select_list(:class, /(^|\s)#{what}(\s|$)/).set(option) 174 | 175 | when @browser.select_list(:index, what.to_i).exists? 176 | then @browser.select_list(:index, what.to_i).select(option) 177 | 178 | else 179 | fail("Sorry, I wasn't able to find the " + "'#{what}'" + " element ") 180 | end 181 | end 182 | 183 | def find_text_field(what, with) 184 | case 185 | when @browser.text_field(:id, what).exists? 186 | then @browser.text_field(:id, what).set(with) 187 | 188 | when @browser.text_field(:name, what).exists? 189 | then @browser.text_field(:name, what).set(with) 190 | 191 | when @browser.text_field(:value, what).exists? 192 | then @browser.text_field(:value, what).set(with) 193 | 194 | when @browser.text_field(:class, /(^|\s)#{what}(\s|$)/).exists? 195 | then @browser.text_field(:class, /(^|\s)#{what}(\s|$)/).set(with) 196 | 197 | when @browser.text_field(:index, what.to_i).exists? 198 | then @browser.text_field(:index, what.to_i).set(with) 199 | 200 | else 201 | fail("Sorry, I wasn't able to find the " + "'#{what}'" + " element ") 202 | end 203 | end 204 | 205 | def find_file_field(what, with) 206 | case 207 | when @browser.file_field(:id, what).exists? 208 | then @browser.file_field(:id, what).set(with) 209 | 210 | when @browser.field_field(:name, what).exists? 211 | then @browser.field_field(:name, what).set(with) 212 | 213 | when @browser.field_field(:value, what).exists? 214 | then @browser.field_field(:value, what).set(with) 215 | 216 | when @browser.field_field(:class, /(^|\s)#{what}(\s|$)/).exists? 217 | then @browser.field_field(:class, /(^|\s)#{what}(\s|$)/).set(with) 218 | 219 | when @browser.field_field(:index, what.to_i).exists? 220 | then @browser.field_field(:index, what.to_i).set(with) 221 | 222 | else 223 | fail("Sorry, I wasn't able to find the " + "'#{what}'" + " element ") 224 | end 225 | end 226 | 227 | def find_span(what,with) 228 | case 229 | when @browser.span(:id, what).exists? 230 | then @browser.span(:id, what).text == with 231 | 232 | when @browser.span(:name, what).exists? 233 | then @browser.span(:name, what).text == with 234 | 235 | when @browser.span(:value, what).exists? 236 | then @browser.span(:value, what).text == with 237 | 238 | when @browser.span(:class, /(^|\s)#{what}(\s|$)/).exists? 239 | then @browser.span(:class, /(^|\s)#{what}(\s|$)/).text == with 240 | 241 | when @browser.span(:index, what.to_i).exists? 242 | then @browser.span(:index, what.to_i).text == with 243 | 244 | else 245 | fail("Sorry, I wasn't able to find the " + "'#{what}'" + " element with " + "'#{with}'") 246 | end 247 | end 248 | 249 | def find_div(what) 250 | case 251 | when @browser.div(:id, what).exists? 252 | then @browser.div(:id, what).click 253 | 254 | when @browser.div(:text, what).exists? 255 | then @browser.div(:text, what).click 256 | 257 | when @browser.div(:name, what).exists? 258 | then @browser.div(:name, what).click 259 | 260 | when @browser.div(:value, what).exists? 261 | then @browser.div(:value, what).click 262 | 263 | when @browser.div(:class, what).exists? 264 | then @browser.div(:class, what).click 265 | 266 | when @browser.div(:index, what.to_i).exists? 267 | then @browser.div(:index, what.to_i).click 268 | 269 | else 270 | fail("Sorry, I wasn't able to find the " + "'#{what}'" + " element ") 271 | end 272 | end 273 | 274 | def click_alert_button_ok 275 | if @browser.class.to_s == "Watir::IE" 276 | Process.kill(9,$pid) if $pid 277 | $pid = Process.create(:app_name => "ruby #{Dir.pwd}/lib/popup_killer_ie.rb", :creation_flags => Process::DETACHED_PROCESS).process_id 278 | elsif @browser.class.to_s == "FireWatir::Firefox" 279 | @browser.startClicker("OK", 3) 280 | elsif @browser.class.to_s == "Watir::Safari" 281 | # $fail("JS clicking not availalble for Safari Watir currently...") 282 | else 283 | @browser.execute_script("window.alert = function(msg) { return true; }") 284 | @browser.execute_script("window.confirm = function(msg) { return true; }") 285 | end 286 | end 287 | 288 | def create_output 289 | begin 290 | File.open("all_objects.txt", "w") { |f| f.puts(@browser.show_all_objects) } 291 | rescue Exception => ex 292 | fail("Sorry could not load an object -> #{ex}") 293 | end 294 | end 295 | 296 | def parse_from_yaml(with) 297 | w = with.gsub(":","").split(".") 298 | puts "
  • Exchanged: #{with} => #{@table[w[0]][w[1]]}
  • " 299 | return @table[w[0]][w[1]] 300 | end 301 | 302 | def scenario_time(time) 303 | puts "

    Scenario took: #{Time.now - time}

    " 304 | end 305 | 306 | #validate if this is a fixture 307 | def fixture?(value) 308 | value =~ /^\:\w*\./ 309 | end 310 | 311 | def calculate_date(datevalue) 312 | return Chronic.parse(datevalue).strftime("%d-%m-%Y") if not Chronic.parse(datevalue).nil? 313 | end 314 | end 315 | 316 | World(WatirCukeHelpers) 317 | --------------------------------------------------------------------------------