├── .gitignore ├── .gitmodules ├── .yardopts ├── AUTHORS ├── CHANGES ├── Gemfile ├── LICENSE ├── README.md ├── Rakefile ├── VERSION ├── bin ├── desktopwatir └── operawatir ├── lib ├── operadriver │ ├── APACHE_2.0_LICENSE.txt │ ├── NEW_BSD_LICENSE.txt │ ├── commons-exec-1.1.jar │ ├── commons-jxpath-1.3.jar │ ├── guava-10.0.1.jar │ ├── operadriver-v0.8.1.jar │ ├── operalaunchers-0.3.jar │ ├── protobuf-java-2.4.1.jar │ └── selenium-java-2.13.0.jar ├── operawatir.rb └── operawatir │ ├── actions.rb │ ├── browser.rb │ ├── clickable_item.rb │ ├── collection.rb │ ├── compat.rb │ ├── compat │ ├── browser.rb │ ├── collection.rb │ ├── element.rb │ ├── element_finders.rb │ ├── selector.rb │ └── window.rb │ ├── desktop-waiter.rb │ ├── desktop_browser.rb │ ├── desktop_common.rb │ ├── desktop_container.rb │ ├── desktop_enums.rb │ ├── desktop_exceptions.rb │ ├── desktop_helper.rb │ ├── element.rb │ ├── exceptions.rb │ ├── helper.rb │ ├── keys.rb │ ├── platform.rb │ ├── preferences.rb │ ├── quickwidgets.rb │ ├── quickwidgets │ ├── quick_addressfield.rb │ ├── quick_button.rb │ ├── quick_checkbox.rb │ ├── quick_dialogtab.rb │ ├── quick_dropdown.rb │ ├── quick_dropdownitem.rb │ ├── quick_editfield.rb │ ├── quick_find.rb │ ├── quick_griditem.rb │ ├── quick_gridlayout.rb │ ├── quick_label.rb │ ├── quick_menu.rb │ ├── quick_menuitem.rb │ ├── quick_radiobutton.rb │ ├── quick_searchfield.rb │ ├── quick_tab.rb │ ├── quick_thumbnail.rb │ ├── quick_toolbar.rb │ ├── quick_treeitem.rb │ ├── quick_treeview.rb │ ├── quick_widget.rb │ └── quick_window.rb │ ├── screenshot.rb │ ├── selector.rb │ ├── spatnav.rb │ ├── utils.rb │ ├── version.rb │ └── window.rb ├── operawatir.gemspec ├── spec ├── fire_event │ ├── fire_event.rb │ └── interactive │ │ ├── onBlur.html │ │ ├── onChange.html │ │ ├── onClick.html │ │ ├── onDblClick.html │ │ ├── onFocus.html │ │ ├── onMouseDown.html │ │ ├── onMouseMove.html │ │ ├── onMouseOut.html │ │ ├── onMouseOver.html │ │ ├── onMouseUp.html │ │ └── onScroll.html ├── operawatir │ ├── README.md │ ├── core │ │ ├── actions_spec.rb │ │ ├── browser_spec.rb │ │ ├── element_spec.rb │ │ ├── keys_spec.rb │ │ ├── preferences_spec.rb │ │ ├── screenshot_spec.rb │ │ ├── spatnav_spec.rb │ │ ├── utils_spec.rb │ │ └── window_spec.rb │ ├── desktop │ │ ├── desktopbrowser_spec.rb │ │ ├── quickaddressfield_spec.rb │ │ ├── quickbutton_spec.rb │ │ ├── quickcheckbox_spec.rb │ │ ├── quickdialogtab_spec.rb │ │ ├── quickdropdown_spec.rb │ │ ├── quickeditfield_spec.rb │ │ ├── quickfind_spec.rb │ │ ├── quickgriditem_spec.rb │ │ ├── quickgridlayout_spec.rb │ │ ├── quicklabel_spec.rb │ │ ├── quickmenu_spec.rb │ │ ├── quickmenuitem_spec.rb │ │ ├── quickradiobutton_spec.rb │ │ ├── quicksearchfield_spec.rb │ │ ├── quicktab_spec.rb │ │ ├── quickthumbnail_spec.rb │ │ ├── quicktreeitem_spec.rb │ │ ├── quicktreeview_spec.rb │ │ ├── quickwidget_spec.rb │ │ ├── quickwindow_spec.rb │ │ └── shared │ │ │ └── shared.rb │ ├── fixtures │ │ ├── boxes.html │ │ ├── browsers.svg │ │ ├── draggableLists.html │ │ ├── formSelectionPage.html │ │ ├── frames.html │ │ ├── grid.html │ │ ├── input_fields_value.html │ │ ├── js │ │ │ ├── jquery-1.4.4.min.js │ │ │ └── jquery-ui-1.8.10.custom.min.js │ │ ├── keys.html │ │ ├── label_submit.html │ │ ├── mouse.html │ │ ├── onclick.html │ │ ├── paragraphs.html │ │ ├── simple.html │ │ └── two_input_fields.html │ ├── guards.rb │ ├── matchers.rb │ ├── server.rb │ ├── watirspec.rake │ ├── watirspec_desktophelper.rb │ └── watirspec_helper.rb └── watir2 │ ├── area_spec.rb │ ├── areas_spec.rb │ ├── browser_spec.rb │ ├── button_spec.rb │ ├── buttons_spec.rb │ ├── checkbox_spec.rb │ ├── checkboxes_spec.rb │ ├── collections_spec.rb │ ├── dd_spec.rb │ ├── dds_spec.rb │ ├── del_spec.rb │ ├── dels_spec.rb │ ├── div_spec.rb │ ├── divs_spec.rb │ ├── dl_spec.rb │ ├── dls_spec.rb │ ├── dt_spec.rb │ ├── dts_spec.rb │ ├── element_spec.rb │ ├── em_spec.rb │ ├── ems_spec.rb │ ├── filefield_spec.rb │ ├── filefields_spec.rb │ ├── fixtures │ ├── 2000_spans.html │ ├── bug_duplicate_attributes.html │ ├── bug_javascript_001.html │ ├── buttons_with_duplicate_ids.html │ ├── collections.html │ ├── definition_lists.html │ ├── euc-jp_text.html │ ├── forms_with_input_elements.html │ ├── frame_1.html │ ├── frame_2.html │ ├── frames.html │ ├── iframes.html │ ├── images.html │ ├── images │ │ ├── 1.gif │ │ ├── 2.gif │ │ ├── 3.gif │ │ ├── button.jpg │ │ ├── circle.jpg │ │ ├── map.gif │ │ ├── map2.gif │ │ ├── minus.gif │ │ ├── originaltriangle.jpg │ │ ├── plus.gif │ │ ├── square.jpg │ │ └── triangle.jpg │ ├── iso-2022-jp_text.html │ ├── javascript │ │ └── helpers.js │ ├── jquery.html │ ├── latin1_text.html │ ├── multiple_ids.html │ ├── non_control_elements.html │ ├── parser_bug_001.html │ ├── prevent_form_submit.html │ ├── right_click.html │ ├── shift_jis_text.html │ ├── tables.html │ ├── timeout.html │ ├── timeout_window_location.html │ ├── tiny_mce.html │ ├── utf8_text.html │ └── watirspec.css │ ├── form_spec.rb │ ├── forms_spec.rb │ ├── frame_spec.rb │ ├── frames_spec.rb │ ├── guards.rb │ ├── hidden_spec.rb │ ├── hiddens_spec.rb │ ├── hn_spec.rb │ ├── hns_spec.rb │ ├── image_spec.rb │ ├── images_spec.rb │ ├── ins_spec.rb │ ├── inses_spec.rb │ ├── label_spec.rb │ ├── labels_spec.rb │ ├── li_spec.rb │ ├── link_spec.rb │ ├── links_spec.rb │ ├── lis_spec.rb │ ├── map_spec.rb │ ├── maps_spec.rb │ ├── meta_spec.rb │ ├── metas_spec.rb │ ├── ol_spec.rb │ ├── ols_spec.rb │ ├── option_spec.rb │ ├── p_spec.rb │ ├── pre_spec.rb │ ├── pres_spec.rb │ ├── ps_spec.rb │ ├── radio_spec.rb │ ├── radios_spec.rb │ ├── select_list_spec.rb │ ├── select_lists_spec.rb │ ├── server.rb │ ├── span_spec.rb │ ├── spans_spec.rb │ ├── spec_helper.rb │ ├── strong_spec.rb │ ├── strongs_spec.rb │ ├── table_bodies_spec.rb │ ├── table_body_spec.rb │ ├── table_cell_spec.rb │ ├── table_cells_spec.rb │ ├── table_footer_spec.rb │ ├── table_footers_spec.rb │ ├── table_header_spec.rb │ ├── table_headers_spec.rb │ ├── table_row_spec.rb │ ├── table_rows_spec.rb │ ├── table_spec.rb │ ├── tables_spec.rb │ ├── text_field_spec.rb │ ├── text_fields_spec.rb │ ├── ul_spec.rb │ ├── uls_spec.rb │ ├── watir_compatibility_spec.rb │ └── watirspec_helper.rb └── utils ├── Rakefile └── formatters ├── new_spartan_formatter.rb ├── operahelper_formatter.rb └── spartan_formatter.rb /.gitignore: -------------------------------------------------------------------------------- 1 | pkg/* 2 | *.gem 3 | .bundle 4 | .DS_Store 5 | .yardoc 6 | spec/spec.opts 7 | doc 8 | Gemfile.lock 9 | .rvmrc 10 | probedata 11 | test_apc.txt 12 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "spec/watir3"] 2 | path = spec/watir3 3 | url = git://github.com/operasoftware/watir3-spec.git 4 | -------------------------------------------------------------------------------- /.yardopts: -------------------------------------------------------------------------------- 1 | --no-private 2 | --title "OperaWatir" 3 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Wilhelm Joys Andersen 2 | Jari Bakken 3 | Karianne Ekern 4 | Stuart Knightley 5 | James Livermont 6 | Chris Lloyd 7 | Adam Minchinton 8 | Maria Popova 9 | Andreas Tolf Tolfsen 10 | Deniz Turkoglu 11 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source :rubygems 2 | 3 | group :development do 4 | gem "bundler", "~> 1.0.0" 5 | gem "jeweler" 6 | gem "BlueCloth", "= 1.0.1" 7 | gem "yard" 8 | gem "mongrel", ">= 1.1.5" 9 | gem "sinatra", ">= 1.1" 10 | gem "rr" 11 | gem "clipboard" 12 | gem "rspec", "~> 2.6.0" 13 | gem "ci_reporter" 14 | gem "deprecated" 15 | gem "builder" 16 | end 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010-2011 Opera Software ASA 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are 6 | met: 7 | 8 | 1. Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the 14 | distribution. 15 | 16 | 3. Neither the name of Opera Software ASA nor the names of its 17 | contributors may be used to endorse or promote products derived 18 | from this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL OPERA SOFTWARE 24 | ASA BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | require 'rake/clean' 3 | require 'jeweler' 4 | require 'rspec/core/rake_task' 5 | require 'yard' 6 | require 'ci/reporter/rake/rspec' 7 | 8 | require './lib/operawatir/version' 9 | 10 | Jeweler::Tasks.new do |gem| 11 | gem.name = 'operawatir' 12 | gem.version = OperaWatir.version 13 | gem.date = Date.today.to_s 14 | 15 | gem.authors = ['Andreas Tolf Tolfsen', 'Chris Lloyd', 'Stuart Knightley', 'Deniz Turkoglu'] 16 | gem.email = ['andreastt@opera.com', 'christopherl@opera.com', 'stuartk@opera.com', 'dturkoglu@opera.com'] 17 | gem.homepage = 'http://www.opera.com/developer/tools/operawatir/' 18 | gem.summary = 'Toolkit for automating interactions with the Opera web browser.' 19 | gem.description = <<-EOF 20 | OperaWatir is a part of the Watir (pronounced water) family of 21 | free software Ruby libraries for automating web browsers. 22 | OperaWatir provides a querying engine and Ruby bindings for a 23 | backend Java library, OperaDriver, for driving the Opera web 24 | browser. It aims for full compliancy with the Watir 2 and Watir 3 25 | specifications. 26 | EOF 27 | 28 | gem.rubyforge_project = gem.name 29 | 30 | gem.platform = 'jruby' 31 | gem.has_rdoc = true 32 | gem.extra_rdoc_files = ['README.md'] 33 | 34 | gem.add_dependency 'rspec', '~> 2.6.0' # pessimistic operator, it actually means ['>= 2.6.0', '< 2.7.0'] 35 | gem.add_dependency 'deprecated' 36 | 37 | gem.add_development_dependency 'jeweler' 38 | gem.add_development_dependency 'rake' 39 | gem.add_development_dependency 'BlueCloth', '= 1.0.1' 40 | gem.add_development_dependency 'yard' 41 | gem.add_development_dependency 'mongrel', '>= 1.1.5' 42 | gem.add_development_dependency 'sinatra', '>= 1.1' 43 | gem.add_development_dependency 'rr' 44 | gem.add_development_dependency 'clipboard' 45 | 46 | gem.files.exclude '.gitignore' 47 | end 48 | 49 | CLEAN.add 'pkg' 50 | 51 | RSpec::Core::RakeTask.new(:spec) 52 | task :test => [:"ci:setup:rspec", :spec] 53 | 54 | YARD::Rake::YardocTask.new do |t| 55 | t.options = ['--no-private'] 56 | end 57 | 58 | task :doc => :yard 59 | 60 | CLEAN.add 'doc' 61 | -------------------------------------------------------------------------------- /VERSION: -------------------------------------------------------------------------------- 1 | 0.6.pre1 2 | -------------------------------------------------------------------------------- /lib/operadriver/NEW_BSD_LICENSE.txt: -------------------------------------------------------------------------------- 1 | protobuf-java-2.3.0.jar: 2 | ------------------------ 3 | 4 | Copyright 2008, Google Inc. 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are 9 | met: 10 | 11 | * Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | * Redistributions in binary form must reproduce the above 14 | copyright notice, this list of conditions and the following disclaimer 15 | in the documentation and/or other materials provided with the 16 | distribution. 17 | * Neither the name of Google Inc. nor the names of its 18 | contributors may be used to endorse or promote products derived from 19 | this software without specific prior written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 25 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 27 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | 33 | Code generated by the Protocol Buffer compiler is owned by the owner 34 | of the input file used when generating it. This code is not 35 | standalone and requires a support library to be linked with it. This 36 | support library is itself covered by the above license. 37 | -------------------------------------------------------------------------------- /lib/operadriver/commons-exec-1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/operasoftware/operawatir/0e9b9329512b1ca7863156a7bcff07bb9db05a27/lib/operadriver/commons-exec-1.1.jar -------------------------------------------------------------------------------- /lib/operadriver/commons-jxpath-1.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/operasoftware/operawatir/0e9b9329512b1ca7863156a7bcff07bb9db05a27/lib/operadriver/commons-jxpath-1.3.jar -------------------------------------------------------------------------------- /lib/operadriver/guava-10.0.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/operasoftware/operawatir/0e9b9329512b1ca7863156a7bcff07bb9db05a27/lib/operadriver/guava-10.0.1.jar -------------------------------------------------------------------------------- /lib/operadriver/operadriver-v0.8.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/operasoftware/operawatir/0e9b9329512b1ca7863156a7bcff07bb9db05a27/lib/operadriver/operadriver-v0.8.1.jar -------------------------------------------------------------------------------- /lib/operadriver/operalaunchers-0.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/operasoftware/operawatir/0e9b9329512b1ca7863156a7bcff07bb9db05a27/lib/operadriver/operalaunchers-0.3.jar -------------------------------------------------------------------------------- /lib/operadriver/protobuf-java-2.4.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/operasoftware/operawatir/0e9b9329512b1ca7863156a7bcff07bb9db05a27/lib/operadriver/protobuf-java-2.4.1.jar -------------------------------------------------------------------------------- /lib/operadriver/selenium-java-2.13.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/operasoftware/operawatir/0e9b9329512b1ca7863156a7bcff07bb9db05a27/lib/operadriver/selenium-java-2.13.0.jar -------------------------------------------------------------------------------- /lib/operawatir.rb: -------------------------------------------------------------------------------- 1 | $LOAD_PATH.unshift File.expand_path('..', __FILE__) 2 | require 'forwardable' 3 | require 'deprecated' 4 | require 'java' 5 | include Java 6 | 7 | %w(commons-jxpath-1.3.jar commons-exec-1.1.jar protobuf-java-2.4.1.jar 8 | selenium-java-2.13.0.jar operalaunchers-0.3.jar operadriver-v0.8.1.jar 9 | guava-10.0.1.jar).each { |jar| require "operadriver/#{jar}" } 10 | 11 | include_class org.openqa.selenium.WebDriver 12 | include_class org.openqa.selenium.remote.RemoteWebElement 13 | include_class org.openqa.selenium.NoSuchElementException 14 | include_class org.openqa.selenium.interactions.Actions 15 | include_class org.openqa.selenium.remote.DesiredCapabilities 16 | include_class com.opera.core.systems.OperaDriver 17 | include_class com.opera.core.systems.OperaWebElement 18 | include_class com.opera.core.systems.settings.OperaDriverSettings 19 | 20 | # Desktop stuff 21 | include_class com.opera.core.systems.OperaDesktopDriver 22 | include_class com.opera.core.systems.scope.protos.DesktopWmProtos 23 | include_class com.opera.core.systems.scope.protos.SystemInputProtos 24 | include_class com.opera.core.systems.QuickWidget 25 | include_class com.opera.core.systems.QuickMenu 26 | include_class com.opera.core.systems.QuickMenuItem 27 | 28 | $KCODE = 'u' # UTF-8 support 29 | 30 | class Object 31 | def truthy? 32 | self && [true, 'true', 'yes', 'y', '1', 1].include?(self) 33 | end 34 | end 35 | 36 | # TODO This should be replaced when we decide upon a better way of 37 | # enabling the Watir 3 API. 38 | module OperaWatir 39 | @current_api = 2 40 | 41 | # Set the API version you wish to use. Please note that setting 42 | # this after OperaWatir::Browser has been initialized will have no 43 | # affect. 44 | # 45 | # @param number [Integer] API version to use 46 | def self.api=(number) 47 | @current_api = number.to_i 48 | end 49 | 50 | # Queries which API to use. 51 | # 52 | # @return [Integer] Desired API version 53 | def self.api 54 | @current_api 55 | end 56 | end 57 | 58 | require 'operawatir/version' 59 | require 'operawatir/platform' 60 | require 'operawatir/keys' 61 | require 'operawatir/screenshot' 62 | require 'operawatir/preferences' 63 | require 'operawatir/spatnav' 64 | require 'operawatir/actions' 65 | require 'operawatir/utils' 66 | 67 | require 'operawatir/exceptions' 68 | require 'operawatir/selector' 69 | require 'operawatir/element' 70 | require 'operawatir/collection' 71 | require 'operawatir/window' 72 | require 'operawatir/browser' 73 | 74 | require 'operawatir/compat' 75 | 76 | # Desktop stuff 77 | require 'operawatir/desktop_enums' 78 | require 'operawatir/desktop_common' 79 | require 'operawatir/clickable_item' 80 | require 'operawatir/desktop_container' 81 | require 'operawatir/desktop_browser' 82 | require 'operawatir/quickwidgets' 83 | require 'operawatir/desktop_exceptions' 84 | -------------------------------------------------------------------------------- /lib/operawatir/actions.rb: -------------------------------------------------------------------------------- 1 | include_class org.openqa.selenium.interactions.Actions 2 | #include_class java.util.lang.CharSequence 3 | 4 | class OperaWatir::Actions 5 | 6 | attr_accessor :browser 7 | attr_accessor :driver 8 | attr_accessor :actions 9 | 10 | def initialize(browser) 11 | self.browser, self.driver = browser, browser.driver 12 | self.actions = Java::OrgOpenqaSeleniumInteractions::Actions.new(@driver) 13 | 14 | @sym_key_map = {} 15 | end 16 | 17 | # If only one argument is given then it is the key, and so we call the 18 | # method that accepts only the key 19 | def key_down(element, key = nil) 20 | if not key 21 | @actions.keyDown(sym_to_key(element)) 22 | else 23 | @actions.keyDown(element.node, sym_to_key(key)) 24 | end 25 | self 26 | end 27 | 28 | # If only one argument is given then it is the key, and so we call the 29 | # method that accepts only the key 30 | def key_up(element, key = nil) 31 | if not key 32 | @actions.keyUp(sym_to_key(element)) 33 | else 34 | @actions.keyUp(element.node, sym_to_key(key)) 35 | end 36 | self 37 | end 38 | 39 | # If only one argument is given then it is the key, and so we call the 40 | # method that accepts only the key 41 | def send_keys(element, keys_to_send = nil) 42 | if not keys_to_send 43 | @actions.sendKeys(element) 44 | else 45 | @actions.sendKeys(element.node, keys_to_send) 46 | end 47 | self 48 | end 49 | 50 | def click_and_hold(element) 51 | @actions.clickAndHold(element.node) 52 | self 53 | end 54 | 55 | def release(element) 56 | @actions.release(element.node) 57 | self 58 | end 59 | 60 | def click(element = nil) 61 | element ? @actions.click(element.node) : @actions.click() 62 | self 63 | end 64 | 65 | def double_click(element = nil) 66 | element ? @actions.double_click(element.node) : @actions.double_click() 67 | self 68 | end 69 | 70 | def move_to_element(element, x_offset = 0, y_offset = 0) 71 | @actions.moveToElement(element.node, x_offset, y_offset) 72 | self 73 | end 74 | 75 | def move_by_offset(x_offset, y_offset) 76 | @actions.moveByOffset(x_offset, y_offset) 77 | self 78 | end 79 | 80 | def context_click(element) 81 | @actions.contextClick(element.node) 82 | self 83 | end 84 | 85 | def drag_and_drop(source, target) 86 | @actions.dragAndDrop(source.node, target.node) 87 | self 88 | end 89 | 90 | def drag_and_drop_by(source, x_offset, y_offset) 91 | @actions.dragAndDrop(source, x_offset, y_offset) 92 | self 93 | end 94 | 95 | def perform() 96 | @actions.perform() 97 | end 98 | 99 | private 100 | 101 | def sym_to_key(sym) 102 | if @sym_key_map.empty? 103 | Java::OrgOpenqaSelenium::Keys.values().each do |k| 104 | @sym_key_map[k.name().downcase.to_sym] = k 105 | end 106 | end 107 | 108 | @sym_key_map[sym] 109 | end 110 | 111 | end 112 | -------------------------------------------------------------------------------- /lib/operawatir/clickable_item.rb: -------------------------------------------------------------------------------- 1 | module OperaWatir 2 | module ClickableItem 3 | 4 | ###################################################################### 5 | # Clicks the button, and waits for loading to finish 6 | # 7 | # @return [int] Window ID of the window shown or 0 if no window is shown 8 | # 9 | # @raise [DesktopExceptions::WidgetNotVisibleException] if the button 10 | # is not visible 11 | # 12 | def load_page_with_click 13 | wait_start 14 | click 15 | # Just wait for the load 16 | wait_for_window_loaded("") 17 | end 18 | 19 | ###################################################################### 20 | # Clicks the button, and waits for the window with window name 21 | # win_name to be shown 22 | # 23 | # @param [String] win_name name of the window that will be opened (Pass a blank string for any window) 24 | # 25 | # @return [int] Window ID of the window shown or 0 if no window is shown 26 | # 27 | # @raise [DesktopExceptions::WidgetNotVisibleException] if the button 28 | # is not visible 29 | # 30 | def open_window_with_click(win_name) 31 | wait_start 32 | click 33 | wait_for_window_shown(win_name) 34 | end 35 | alias_method :open_dialog_with_click, :open_window_with_click 36 | 37 | ###################################################################### 38 | # Clicks item and waits for the menu to close 39 | # 40 | # @return name of menu closed 41 | # 42 | def close_menu_with_click(menu_name) 43 | wait_start 44 | click 45 | wait_for_menu_closed(menu_name) 46 | end 47 | 48 | ###################################################################### 49 | # Clicks the item, and waits for the menu with menu with name 50 | # menu_name to be shown 51 | # 52 | # @param [String] name of menu that should open 53 | # 54 | # @raise [DesktopExceptions::WidgetNotVisibleException] if the button 55 | # is not visible 56 | # 57 | # @return name of menu opened if it matches the parameter menu_name, 58 | # otherwise returns empty string 59 | # 60 | def open_menu_with_click(menu_name) 61 | wait_start 62 | click 63 | wait_for_menu_shown(menu_name) 64 | end 65 | 66 | 67 | end 68 | end 69 | -------------------------------------------------------------------------------- /lib/operawatir/compat.rb: -------------------------------------------------------------------------------- 1 | module OperaWatir 2 | 3 | module Compat; end 4 | 5 | # Switches on compatibility layer (Watir 2 API). 6 | def self.compatibility! 7 | require 'operawatir/compat/browser' 8 | require 'operawatir/compat/element_finders' 9 | require 'operawatir/compat/window' 10 | 11 | Browser.send :include, Compat::Browser 12 | Window.send :include, Compat::ElementFinders 13 | Window.send :include, Compat::Window 14 | Collection.send :include, Compat::ElementFinders 15 | 16 | # TODO Ruby Modules can't override methods defined in their included klass 17 | # Requiring the files is OK, but there needs to be some way of detecting 18 | # that we are in compatibility mode. 19 | 20 | require 'operawatir/compat/selector' 21 | require 'operawatir/compat/collection' 22 | require 'operawatir/compat/element' 23 | end 24 | 25 | end 26 | -------------------------------------------------------------------------------- /lib/operawatir/compat/browser.rb: -------------------------------------------------------------------------------- 1 | module OperaWatir 2 | module Compat 3 | module Browser 4 | extend Forwardable 5 | 6 | def method_missing(method, *args, &blk) 7 | if active_window.respond_to? method 8 | active_window.send(method, *args, &blk) 9 | else 10 | super 11 | end 12 | end 13 | 14 | # Class#type is defined by Ruby, it will never reach 15 | # #method_missing. 16 | def_delegator :active_window, :type 17 | 18 | end 19 | end 20 | end 21 | -------------------------------------------------------------------------------- /lib/operawatir/compat/selector.rb: -------------------------------------------------------------------------------- 1 | class OperaWatir::Selector 2 | include Deprecated 3 | 4 | BASE_TYPES << :selector 5 | alias_method :selector, :css 6 | deprecated :selector, "element(:css, 'foo')" 7 | end 8 | -------------------------------------------------------------------------------- /lib/operawatir/compat/window.rb: -------------------------------------------------------------------------------- 1 | module OperaWatir 2 | module Compat 3 | module Window 4 | include Deprecated 5 | 6 | # 7 | # Checks whether the body has the given text in it. 8 | # 9 | # @param [String] str Text to search for. 10 | # @return [Boolean] true if the body contains the given text, 11 | # false otherwise 12 | # 13 | 14 | def contains_text(str) 15 | text.index(str) 16 | end 17 | 18 | 19 | # 20 | # Find elements that match the given XPath. 21 | # 22 | # @param [String] value The XPath expression to search for. 23 | # @return [OperaWatir::Collection] A collection of matching 24 | # elements. 25 | # 26 | 27 | def elements_by_xpath(value) 28 | find_by_xpath(value) 29 | end 30 | 31 | alias_method :element_by_xpath, :elements_by_xpath 32 | 33 | 34 | # 35 | # Opera specific 36 | # 37 | 38 | def get_hash 39 | visual_hash 40 | end 41 | 42 | deprecated :get_hash, 'browser.visual_hash' 43 | 44 | 45 | # 46 | # TODO This is a relic from the old OperaWatir implementation, 47 | # tests should be updated. 48 | # 49 | 50 | def frame(selector, argument) 51 | case selector 52 | when :name 53 | driver.switch_to.frame(argument) 54 | when :index 55 | driver.switch_to.frame(argument.to_i - 1) # index starts from 1 in Watir 56 | else 57 | raise OperaWatir::Exceptions::NotImplementedException, 58 | "We do not support the `#{selector}' selector yet" 59 | end 60 | end 61 | 62 | 63 | def switch_to_default 64 | driver.switch_to.default_content 65 | end 66 | 67 | 68 | def show_frames 69 | frames = driver.list_frames 70 | text = "There are #{frames.length.to_s} frames\n" 71 | frames.each_with_index { |frame, i| text << "frame index: #{(i.to_i + 1).to_s} name: #{frame.to_s}\n" } 72 | text 73 | end 74 | 75 | end 76 | end 77 | end 78 | -------------------------------------------------------------------------------- /lib/operawatir/desktop-waiter.rb: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | require 'operawatir/desktop_helper' 3 | -------------------------------------------------------------------------------- /lib/operawatir/desktop_enums.rb: -------------------------------------------------------------------------------- 1 | module OperaWatir 2 | # @private 3 | # Documentation doesn't work with these dynamic enums so just leave them out 4 | module DesktopEnums 5 | 6 | # Enum for the key/mouse modifiers 7 | KEYMODIFIER_ENUM_MAP = SystemInputProtos::ModifierPressed.constants.inject({}) do |acc, const| 8 | acc[const.to_s.downcase.to_sym] = SystemInputProtos::ModifierPressed.const_get(const) 9 | acc 10 | end 11 | 12 | # Enum for the mouse buttons 13 | MOUSEBUTTON_ENUM_MAP = SystemInputProtos::MouseInfo::MouseButton.constants.inject({}) do |acc, const| 14 | acc[const.to_s.downcase.to_sym] = SystemInputProtos::MouseInfo::MouseButton.const_get(const) 15 | acc 16 | end 17 | 18 | # Enum for the widget types 19 | WIDGET_ENUM_MAP = DesktopWmProtos::QuickWidgetInfo::QuickWidgetType.constants.inject({}) do |acc, const| 20 | acc[const.to_s.downcase.to_sym] = DesktopWmProtos::QuickWidgetInfo::QuickWidgetType.const_get(const) 21 | acc 22 | end 23 | 24 | # Enum for window types 25 | WINDOW_ENUM_MAP = DesktopWmProtos::DesktopWindowInfo::DesktopWindowType.constants.inject({}) do |acc, const| 26 | acc[const.to_s.downcase.to_sym] = DesktopWmProtos::DesktopWindowInfo::DesktopWindowType.const_get(const) 27 | acc 28 | end 29 | 30 | # Enum for search types 31 | WIDGET_SEARCHTYPE_ENUM_MAP = DesktopWmProtos::QuickWidgetSearch::QuickWidgetSearchType.constants.inject({}) do |acc, const| 32 | acc[const.to_s.downcase.to_sym] = DesktopWmProtos::QuickWidgetSearch::QuickWidgetSearchType.const_get(const) 33 | acc 34 | end 35 | 36 | # Enum for drop position types for dropping a widget onto another 37 | DROPPOSITION_ENUM_MAP = QuickWidget::DropPosition.constants.inject({}) do |acc, const| 38 | acc[const.to_s.downcase.to_sym] = QuickWidget::DropPosition.const_get(const) 39 | acc 40 | end 41 | end 42 | end 43 | -------------------------------------------------------------------------------- /lib/operawatir/desktop_exceptions.rb: -------------------------------------------------------------------------------- 1 | module OperaWatir::DesktopExceptions 2 | include OperaWatir::Exceptions 3 | 4 | # @example 5 | # begin 6 | # ... 7 | # rescue OperaWatirException 8 | # end 9 | 10 | # Raised when a method is called on a control that is not visible 11 | # corresponding element. 12 | class WidgetNotVisibleException < OperaWatirException; end 13 | class UnsupportedActionException < OperaWatirException; end 14 | class WidgetDisabledException < OperaWatirException; end 15 | 16 | end 17 | -------------------------------------------------------------------------------- /lib/operawatir/desktop_helper.rb: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # TODO 4 | # You need to set the OPERA_LAUNCHER and OPERA_PATH environment variables 5 | # for this Helper to work. 6 | 7 | require 'operawatir' 8 | require 'rspec' 9 | require 'rbconfig' 10 | 11 | require File.expand_path('../../../spec/operawatir/matchers', __FILE__) 12 | 13 | module OperaWatir::DesktopHelper 14 | extend self 15 | @@files = [] 16 | 17 | def settings 18 | OperaWatir::DesktopBrowser.settings 19 | end 20 | 21 | def browser 22 | @browser ||= OperaWatir::DesktopBrowser.new 23 | end 24 | 25 | def mac? 26 | Config::CONFIG['target_os'] == "darwin" 27 | end 28 | 29 | def linux? 30 | Config::CONFIG['target_os'] == "linux" 31 | end 32 | 33 | def configure_rspec! 34 | RSpec.configure do |config| 35 | 36 | 37 | 38 | if mac? 39 | config.filter_run_excluding :nonmac? => true 40 | end 41 | 42 | if linux? == false 43 | config.filter_run_excluding :nix? => true 44 | end 45 | 46 | # Set every RSpec option 47 | settings.each do |key, value| 48 | config.send("#{key}=", value) if config.respond_to?("#{key}=") 49 | if key.to_s.eql?("files_to_run") 50 | @@files = value 51 | end 52 | if key.to_s.eql?("files_or_directories_to_run") 53 | @@files = value 54 | end 55 | end 56 | 57 | config.include SpecHelpers 58 | 59 | config.before(:all) { 60 | if OperaWatir::DesktopHelper::settings[:no_restart] == false 61 | unless @@files.empty? 62 | path = File.join(Dir.getwd, @@files.shift) 63 | filepath = path.chomp(".rb") 64 | browser.reset_prefs(filepath) 65 | end 66 | else 67 | # Must create browser object here so that none of the 68 | # test is run before Opera has been launched 69 | browser 70 | end 71 | browser.set_preference("User Prefs", "Enable UI Animations", 0) 72 | } 73 | 74 | config.after(:suite) { 75 | # Use the @browser directly because we don't want 76 | # to launch Opera here if it's not running 77 | if @browser 78 | 79 | if settings[:no_quit] == false 80 | # Shutdown Opera 81 | @browser.quit_opera 82 | @browser.delete_profile 83 | end 84 | 85 | # Shutdown the driver 86 | @browser.quit_driver 87 | end 88 | } 89 | end 90 | end 91 | 92 | def run!(settings={}) 93 | OperaWatir::DesktopBrowser.settings = settings 94 | configure_rspec! 95 | RSpec::Core::Runner.autorun 96 | end 97 | 98 | private 99 | 100 | module SpecHelpers 101 | def browser 102 | OperaWatir::DesktopHelper.browser 103 | end 104 | 105 | def window 106 | browser.active_window 107 | end 108 | end 109 | end 110 | 111 | OperaWatir::DesktopHelper.run! 112 | -------------------------------------------------------------------------------- /lib/operawatir/exceptions.rb: -------------------------------------------------------------------------------- 1 | module OperaWatir::Exceptions 2 | 3 | # Superclass for all OperaWatir exceptions. 4 | # 5 | # @example 6 | # begin 7 | # ... 8 | # rescue OperaWatirException 9 | # end 10 | class OperaWatirException < RuntimeError; end 11 | 12 | # Raised when a method is called on an object which doesn't have a 13 | # corresponding element. 14 | class UnknownObjectException < OperaWatirException; end 15 | 16 | # Raised when specifying an unknown way of finding an element. 17 | # 18 | # @example browser.divs(:weird_method, 10) 19 | class MissingWayOfFindingObjectException < OperaWatirException; end 20 | 21 | # Raised when trying to switch to an unknown frame. 22 | class UnknownFrameException < OperaWatirException; end 23 | 24 | # Raised when performing an action which has not yet been 25 | # implemented by OperaWatir. 26 | class NotImplementedException < OperaWatirException; end 27 | 28 | # TODO Document this 29 | class NoValueFoundException < OperaWatirException; end 30 | 31 | # Raised when trying to perform an action on an element which is 32 | # disabled. 33 | class ObjectDisabledException < OperaWatirException; end 34 | 35 | # Raised when trying to access a table cell that doesn't exist. 36 | class UnknownCellException < OperaWatirException; end 37 | 38 | # Raised when pressing a modifier key that doesn't exist. 39 | class InvalidKeyException < OperaWatirException; end 40 | 41 | # Raised when an exception occurs in Preferences. 42 | class PreferencesException < OperaWatirException; end 43 | 44 | end 45 | -------------------------------------------------------------------------------- /lib/operawatir/helper.rb: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # TODO 4 | # You need to set the OPERA_LAUNCHER and OPERA_PATH environment variables 5 | # for this Helper to work. 6 | 7 | require 'operawatir' 8 | require 'rspec' 9 | require 'rbconfig' 10 | 11 | module OperaWatir::Helper 12 | extend self 13 | 14 | def settings 15 | OperaWatir::Browser.settings 16 | end 17 | 18 | def browser 19 | @browser ||= OperaWatir::Browser.new 20 | end 21 | 22 | def configure_rspec! 23 | RSpec.configure do |config| 24 | 25 | # Set every RSpec option 26 | settings.each do |key, value| 27 | config.send("#{key}=", value) if config.respond_to?("#{key}=") 28 | end 29 | 30 | config.include SpecHelpers 31 | 32 | config.after(:suite) do 33 | browser.quit if @browser 34 | abort 35 | end 36 | end 37 | end 38 | 39 | def run!(settings={}) 40 | OperaWatir::Browser.settings = settings 41 | configure_rspec! 42 | RSpec::Core::Runner.autorun 43 | end 44 | 45 | private 46 | 47 | module SpecHelpers 48 | def browser 49 | OperaWatir::Helper.browser 50 | end 51 | 52 | def window 53 | browser.active_window 54 | end 55 | end 56 | end 57 | 58 | OperaWatir::Helper.run! 59 | -------------------------------------------------------------------------------- /lib/operawatir/platform.rb: -------------------------------------------------------------------------------- 1 | require 'rbconfig' 2 | 3 | class OperaWatir::Platform 4 | def self.os 5 | @os ||= ( 6 | host_os = RbConfig::CONFIG['host_os'] 7 | case host_os 8 | when /mswin|msys|mingw|bccwin|wince|emc/ 9 | :windows 10 | when /darwin|mac os/ 11 | :macosx 12 | when /linux/ 13 | :linux 14 | when /solaris|bsd/ 15 | :unix 16 | else 17 | raise Exceptions::NotImplementedException, "#{host_os.inspect} not supported" 18 | end 19 | ) 20 | end 21 | end 22 | -------------------------------------------------------------------------------- /lib/operawatir/quickwidgets.rb: -------------------------------------------------------------------------------- 1 | %w(quick_widget quick_button quick_checkbox quick_editfield 2 | quick_dropdown quick_dialogtab quick_label quick_radiobutton quick_treeview quick_addressfield 3 | quick_searchfield quick_toolbar quick_window quick_tab quick_treeitem quick_thumbnail 4 | quick_find quick_griditem quick_gridlayout quick_menu quick_menuitem quick_dropdownitem).each {|widget| require "operawatir/quickwidgets/#{widget}"} 5 | -------------------------------------------------------------------------------- /lib/operawatir/quickwidgets/quick_addressfield.rb: -------------------------------------------------------------------------------- 1 | module OperaWatir 2 | class QuickAddressField < QuickEditField 3 | 4 | # Checks the type of the widget is correct 5 | # 6 | # @private 7 | def correct_type? 8 | @element.getType == WIDGET_ENUM_MAP[:addressfield] 9 | end 10 | 11 | # Enters the url into the address field, and waits for page loading 12 | # to finish 13 | # 14 | # @example (with RSpec) 15 | # addressfield.load_page_with_url("opera:debug").should == "opera:debug" 16 | # 17 | # @param [String] URL to load 18 | # @return [String] text in the address field after the page is loaded 19 | # or a blank string 20 | # @raise [Exceptions::UnknownObjectException] if the widget could not be found 21 | # using the specified method 22 | # 23 | def load_page_with_url(url) 24 | # Must focus field before calling enter_text... 25 | focus_with_click 26 | 27 | # Enters text in a field and then hits enter 28 | enter_text_and_hit_enter(url) 29 | end 30 | 31 | # 32 | # Gets the visible text in the address field 33 | # 34 | # @return [String] visible text in address field 35 | # 36 | # @raise [Exceptions::UnknownObjectException] if the widget could not be found 37 | # using the specified method 38 | # 39 | def visible_text 40 | element.getVisibleText() 41 | end 42 | 43 | # 44 | # Gets the highlighted text in the address field 45 | # 46 | # @return [String] higlighted text in address field, if any, else empty 47 | # 48 | # @raise [Exceptions::UnknownObjectException] if the widget could not be found 49 | # using the specified method 50 | # 51 | def highlighted_text 52 | element.getAdditionalText() 53 | end 54 | 55 | end 56 | end 57 | -------------------------------------------------------------------------------- /lib/operawatir/quickwidgets/quick_checkbox.rb: -------------------------------------------------------------------------------- 1 | module OperaWatir 2 | class QuickCheckbox < QuickWidget 3 | 4 | # @private 5 | # Checks the type of the widget is correct 6 | def correct_type? 7 | @element.getType == WIDGET_ENUM_MAP[:checkbox] 8 | end 9 | 10 | ###################################################################### 11 | # Checks if the checkbox is checked 12 | # 13 | # @return [Boolean] true if the checkbox is checked otherwise false 14 | # 15 | # @raise [Exceptions::UnknownObjectException] if the widget could not be found 16 | # using the specified method 17 | def checked? 18 | element.isSelected 19 | end 20 | 21 | ###################################################################### 22 | # Clicks a radio button or checkbox and toggles it state 23 | # 24 | # @return [Boolean] the new state of the radio button or checkbox, 25 | # false for not checked, or true for checked 26 | # 27 | # @raise [DesktopExceptions::WidgetNotVisibleException] if the checkbox 28 | # is not visible 29 | # 30 | def toggle_with_click 31 | click 32 | 33 | # Cheat since we don't have an even yet 34 | sleep(0.1) 35 | 36 | # is this guaranteed to be same as getValue? 37 | element(true).isSelected 38 | end 39 | 40 | 41 | ###################################################################### 42 | # Clicks the checkbox, and waits for the window with window name 43 | # win_name to be shown 44 | # 45 | # @param [String] win_name name of the window that will be opened (Pass a blank string for any window) 46 | # 47 | # @return [int] Window ID of the window shown or 0 if no window is shown 48 | # 49 | # @raise [DesktopExceptions::WidgetNotVisibleException] if the checkbox 50 | # is not visible 51 | # 52 | def open_dialog_with_click(win_name) 53 | wait_start 54 | click 55 | wait_for_window_shown(win_name) 56 | end 57 | 58 | end 59 | end -------------------------------------------------------------------------------- /lib/operawatir/quickwidgets/quick_dialogtab.rb: -------------------------------------------------------------------------------- 1 | module OperaWatir 2 | class QuickDialogTab < QuickWidget 3 | 4 | # @private 5 | # Checks the type of the widget is correct 6 | def correct_type? 7 | @element.getType == WIDGET_ENUM_MAP[:dialogtab] 8 | end 9 | 10 | ###################################################################### 11 | # Switches to the dialog tab by clicking on it 12 | # 13 | # @raise [DesktopExceptions::WidgetNotVisibleException] if the dialogtab 14 | # is not visible 15 | # 16 | def activate_tab_with_click 17 | click 18 | 19 | # No event yet so just cheat and sleep 20 | sleep(0.1); 21 | end 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /lib/operawatir/quickwidgets/quick_dropdown.rb: -------------------------------------------------------------------------------- 1 | module OperaWatir 2 | class QuickDropdown < QuickEditField #QuickWidget 3 | 4 | # @private 5 | # Checks the type of the widget is correct 6 | def correct_type? 7 | @element.getType == WIDGET_ENUM_MAP[:dropdown] 8 | end 9 | 10 | ###################################################################### 11 | # Checks if the item selected in the dropdown matches the text loaded 12 | # from Opera using the string_id 13 | # 14 | # @param [String] string_id String ID to use to load the string from the current 15 | # language file (e.g. "D_NEW_PREFERENCES_GENERAL") 16 | # 17 | # @return [Boolean] true if the dropdown has the item with the 18 | # string_id selected, otherwise false 19 | # 20 | # @raise [Exceptions::UnknownObjectException] if the widget could not be found 21 | # using the specified method 22 | # 23 | def selected?(string_id) 24 | element.isSelected(string_id) 25 | end 26 | 27 | ######################################################################### 28 | # 29 | # @example 30 | # browser.quick_dropdown(:name, "Close_tab_dropdown").dropped_down? 31 | # 32 | # @return true if dropdown is dropped_down/open, else false 33 | # 34 | def dropped_down? 35 | element.getValue() > 0 36 | end 37 | 38 | 39 | ############################################################################ 40 | # Click dropdown to open it 41 | # 42 | # @example 43 | # browser.quick_dropdown(:name, "Close_tab_dropdown").open_with_click 44 | # 45 | def open_with_click 46 | click 47 | sleep(0.1) 48 | end 49 | 50 | end 51 | end -------------------------------------------------------------------------------- /lib/operawatir/quickwidgets/quick_dropdownitem.rb: -------------------------------------------------------------------------------- 1 | module OperaWatir 2 | class QuickDropdownItem < QuickEditField #QuickWidget # QuickEditField? 3 | 4 | # @private 5 | # Checks the type of the widget is correct 6 | def correct_type? 7 | @element.getType == WIDGET_ENUM_MAP[:dropdownitem] 8 | end 9 | 10 | ###################################################################### 11 | # Checks if the item is selected 12 | # 13 | # @return [Boolean] true if the dropdown has the item with the 14 | # string_id selected, otherwise false 15 | # 16 | # @raise [Exceptions::UnknownObjectException] if the widget could not be found 17 | # using the specified method 18 | def selected? 19 | element(true).isSelected() 20 | end 21 | 22 | ########################################################################## 23 | # Select item by click 24 | # 25 | # @example 26 | # browser.quick_dropdownitem(:text, "Activate the next tab").select_with_click 27 | # 28 | # @return true if item is now selected, otherwise false 29 | # 30 | def select_with_click 31 | if mac_internal? 32 | press_menu 33 | else 34 | click 35 | end 36 | selected? 37 | end 38 | 39 | private 40 | 41 | # Selects an item from a drop down pop menu where you can't click them on Mac 42 | def press_menu 43 | driver.pressQuickMenuItem(text, true); 44 | end 45 | end 46 | end -------------------------------------------------------------------------------- /lib/operawatir/quickwidgets/quick_find.rb: -------------------------------------------------------------------------------- 1 | module OperaWatir 2 | class QuickFind < QuickDropdown 3 | 4 | # @private 5 | # Checks the type of the widget is correct 6 | def correct_type? 7 | @element.getType == WIDGET_ENUM_MAP[:quickfind] 8 | end 9 | 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /lib/operawatir/quickwidgets/quick_griditem.rb: -------------------------------------------------------------------------------- 1 | module OperaWatir 2 | class QuickGridItem < QuickWidget 3 | 4 | # @private 5 | # Checks the type of the widget is correct 6 | def correct_type? 7 | @element.getType == WIDGET_ENUM_MAP[:griditem] 8 | end 9 | 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /lib/operawatir/quickwidgets/quick_gridlayout.rb: -------------------------------------------------------------------------------- 1 | module OperaWatir 2 | class QuickGridLayout < QuickWidget 3 | 4 | # @private 5 | # Checks the type of the widget is correct 6 | def correct_type? 7 | @element.getType == WIDGET_ENUM_MAP[:gridlayout] 8 | end 9 | 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /lib/operawatir/quickwidgets/quick_label.rb: -------------------------------------------------------------------------------- 1 | module OperaWatir 2 | class QuickLabel < QuickWidget 3 | 4 | # @private 5 | # Checks the type of the widget is correct 6 | def correct_type? 7 | @element.getType == WIDGET_ENUM_MAP[:label] 8 | end 9 | 10 | end 11 | end 12 | 13 | -------------------------------------------------------------------------------- /lib/operawatir/quickwidgets/quick_radiobutton.rb: -------------------------------------------------------------------------------- 1 | module OperaWatir 2 | class QuickRadioButton < QuickCheckbox 3 | 4 | # @private 5 | # Checks the type of the widget is correct 6 | def correct_type? 7 | @element.getType == WIDGET_ENUM_MAP[:radiobutton] 8 | end 9 | 10 | end 11 | end -------------------------------------------------------------------------------- /lib/operawatir/quickwidgets/quick_searchfield.rb: -------------------------------------------------------------------------------- 1 | module OperaWatir 2 | class QuickSearchField < QuickEditField 3 | 4 | # @private 5 | # Checks the type of the widget is correct 6 | def correct_type? 7 | @element.getType == WIDGET_ENUM_MAP[:search] 8 | end 9 | 10 | ###################################################################### 11 | # Enters the search text into the search field, and waits for page 12 | # loading to finish 13 | # 14 | # @example (RSpec) 15 | # browser.quick_searchfield(:name, "tbs_MainSearch").search_with_text("old cars").should include "http://www.google" 16 | # 17 | # @param [String] url text to search with 18 | # 19 | # @return [String] text in the address field after the page is loaded 20 | # or a blank string 21 | # 22 | def search_with_text(search_text) 23 | # Must focus field before calling enter_text... 24 | focus_with_click 25 | 26 | # Enters text in a field and then hits enter 27 | t = enter_text_and_hit_enter(search_text) 28 | 29 | # return text in addressfield (in same window as search field) 30 | driver.findWidgetByName(WIDGET_ENUM_MAP[:addressfield], @window_id, "tba_address_field", "Document Toolbar").getText 31 | end 32 | 33 | end 34 | end -------------------------------------------------------------------------------- /lib/operawatir/quickwidgets/quick_tab.rb: -------------------------------------------------------------------------------- 1 | module OperaWatir 2 | class QuickTab < QuickButton 3 | 4 | # @private 5 | # Checks the type of the widget is correct 6 | def correct_type? 7 | @element.getType == WIDGET_ENUM_MAP[:tabbutton] 8 | end 9 | 10 | ###################################################################### 11 | # Drag and drop this tab on tab tab_target 12 | # 13 | # @param [QuickTab] tab button to drop this tab on 14 | # 15 | # @raise [DesktopExceptions::UnknownObjectException] if the target is not a tab 16 | # 17 | def move_with_drag(tab_target) 18 | raise(Exceptions::UnknownObjectException) unless tab_target.type == :tabbutton 19 | drag_and_drop_on(tab_target, :center) 20 | 21 | sleep(0.1) 22 | end 23 | 24 | ###################################################################### 25 | # Drag and drop this tab on another tab to add it to its tab group 26 | # 27 | # @param [QuickTab] tab (group) button to drop this tab on 28 | # 29 | # @raise [DesktopExceptions::UnknownObjectException] if the target is not a tab 30 | # 31 | # @return [int] the number of tabs in this tab group, or 1 if this is not a tab group button, 32 | # in which case it represents only 1 tab, itself 33 | def group_with_drag(tab_target) 34 | raise(Exceptions::UnknownObjectException) unless tab_target.type == :tabbutton 35 | 36 | # Drop on the edge of a tab to make the grouping work 37 | drag_and_drop_on(tab_target, :edge) 38 | 39 | sleep(0.1) 40 | 41 | #Get the number of tabs in the group 42 | element(true).value 43 | end 44 | 45 | 46 | ###################################################################### 47 | # Clicks the tab button, and waits for the tab to be shown / switches to the page 48 | # 49 | # @param [String] win_name name of the window that will be opened (Pass a blank string for any window) 50 | # 51 | # @return [int] Window ID of the window activated, 52 | # 0 if the window is already the active one, 53 | # or if no window is active 54 | # 55 | # @raise [DesktopExceptions::WidgetNotVisibleException] if the tab button 56 | # is not visible 57 | # 58 | def activate_tab_with_click 59 | wait_start 60 | click 61 | wait_for_window_activated("Document Window") 62 | end 63 | 64 | ########################################################################### 65 | # Double clicks the tab and waits for it to be closed 66 | # 67 | # @return [int] Window ID of the window that was closed 68 | # 69 | def close_window_with_doubleclick 70 | wait_start 71 | click(:left, 2) 72 | wait_for_window_close("Document Window") 73 | end 74 | 75 | end 76 | end -------------------------------------------------------------------------------- /lib/operawatir/quickwidgets/quick_thumbnail.rb: -------------------------------------------------------------------------------- 1 | module OperaWatir 2 | class QuickThumbnail < QuickButton 3 | 4 | # @private 5 | # Checks the type of the widget is correct 6 | def correct_type? 7 | @element.getType == WIDGET_ENUM_MAP[:thumbnail] 8 | end 9 | 10 | ###################################################################### 11 | # Drag and drop this speeddial onto the speed dial tab_target 12 | # 13 | # @param [QuickThumbnail] Thumbnail to drop this thumbnail on 14 | # 15 | # @raise [DesktopExceptions::UnknownObjectException] if the target is not a thumbnail 16 | # 17 | #@private 18 | def move_with_drag(tab_target) 19 | raise(Exceptions::UnknownObjectException) unless tab_target.type == :thumbnail 20 | drag_and_drop_on(tab_target, :center) 21 | 22 | sleep(0.1) 23 | end 24 | 25 | end 26 | end -------------------------------------------------------------------------------- /lib/operawatir/quickwidgets/quick_toolbar.rb: -------------------------------------------------------------------------------- 1 | module OperaWatir 2 | class QuickToolbar < QuickWidget 3 | 4 | # @private 5 | # Checks the type of the widget is correct 6 | def correct_type? 7 | @element.getType == WIDGET_ENUM_MAP[:toolbar] 8 | end 9 | 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /lib/operawatir/quickwidgets/quick_treeview.rb: -------------------------------------------------------------------------------- 1 | module OperaWatir 2 | class QuickTreeView < QuickWidget 3 | 4 | # @private 5 | # Checks the type of the widget is correct 6 | def correct_type? 7 | @element.getType == WIDGET_ENUM_MAP[:treeview] 8 | end 9 | 10 | #Should rather use what's already in browser 11 | # @private 12 | def treeitems 13 | treeitems = driver.getQuickWidgetList(driver.getQuickWindowName(window_id)).map do |java_widget| 14 | case java_widget.getType 15 | when QuickWidget::WIDGET_ENUM_MAP[:treeitem] 16 | QuickTreeItem.new(self,java_widget) 17 | end 18 | end.select { |item| item != nil } 19 | treeitems.select {|item| item.parent_name == name } 20 | end 21 | 22 | def num_treeitems 23 | treeitems.select { |item| item.position[1] == 0 }.length 24 | end 25 | 26 | end 27 | end 28 | 29 | -------------------------------------------------------------------------------- /lib/operawatir/screenshot.rb: -------------------------------------------------------------------------------- 1 | class OperaWatir::Screenshot 2 | 3 | attr_accessor :browser, :reply 4 | 5 | def initialize(parent) 6 | self.browser = parent.browser 7 | self.reply = driver.saveScreenshot(2, [].to_java(:string)) 8 | end 9 | 10 | # Saves screenshot to specified location. 11 | # 12 | # @param [String] Path to where you want the screenshot saved. 13 | # @return [String] The full path to the file that was saved. 14 | def save(filename) 15 | File.open(filename, 'w') { |f| f.write png } 16 | File.expand_path filename 17 | end 18 | 19 | # Is the screenshot blank? 20 | # 21 | # @return [Boolean] True/false depending on the screenshot is blank. 22 | def blank? 23 | reply.isBlank 24 | end 25 | 26 | # Returns the raw byte string of the screenshot in PNG format. 27 | # 28 | # @return [String] A png image in a raw byte string. 29 | def png 30 | String.from_java_bytes reply.getPng 31 | end 32 | 33 | # Lets you get a MD5 sum of the screen. 34 | # 35 | # @return [String] A hash. 36 | def md5 37 | reply.getMd5 38 | end 39 | 40 | private 41 | 42 | def driver 43 | browser.driver 44 | end 45 | 46 | end 47 | -------------------------------------------------------------------------------- /lib/operawatir/selector.rb: -------------------------------------------------------------------------------- 1 | class OperaWatir::Selector 2 | BASE_TYPES = [:id, :class_name, :tag_name, :css, :xpath, :name] 3 | COLLECTION_TYPES = [:index, :attribute] 4 | META_TYPES = [:join, :antijoin] 5 | 6 | TYPES = BASE_TYPES + COLLECTION_TYPES + META_TYPES 7 | 8 | attr_accessor :collection, :sexp 9 | 10 | def initialize(collection, sexp=nil) 11 | self.collection, self.sexp = collection, sexp 12 | end 13 | 14 | def eval(exp=sexp) 15 | exp.is_a?(Array) ? apply(*optimise(exp).map {|x| eval(x)}) : exp 16 | end 17 | 18 | def apply(fn, *args) 19 | elms = args.shift 20 | 21 | # Say hello to the the ol' send trick. 22 | # 23 | # Private methods can be called when using send. This "bug" was 24 | # briefly disabled in 1.9 but people complained because it's very 25 | # handy (but bad). 26 | if elms.nil? 27 | collection.parent.send("find_elements_by_#{fn}", *args) 28 | else 29 | collection.send(:_elms=, elms) 30 | if META_TYPES.include?(fn) 31 | send("apply_#{fn}", elms, args) 32 | else 33 | collection.send("find_elements_by_#{fn}", *args) 34 | end 35 | end 36 | end 37 | 38 | (BASE_TYPES + COLLECTION_TYPES).each do |name| 39 | define_method name do |val| 40 | self.sexp = [name, sexp, val] 41 | self 42 | end 43 | end 44 | 45 | META_TYPES.each do |name| 46 | define_method name do |&blk| 47 | list = BlockBuilder.new(self) 48 | blk.call(list) 49 | self.sexp = list.items.inject([name]) do |items, item| 50 | items << item.sexp 51 | end 52 | self 53 | end 54 | end 55 | 56 | # Handy shortcut 57 | 58 | alias_method :tag, :tag_name 59 | 60 | private 61 | 62 | def optimise(sexp) 63 | # [:attribute, [:tag_name, nil, TAG], {:id => ID}] 64 | # => 65 | # [:tag_name, [:id, nil, ID], TAG] 66 | if ( 67 | sexp.first == :attribute and 68 | sexp[1].first == :tag_name and sexp[1][1].nil? and 69 | sexp.last.length == 1 and sexp.last.has_key?(:id) and 70 | sexp.last[:id].is_a?(String) 71 | ) 72 | # Need to uppercase the tag name as Element.tag_name is alway uppercase 73 | [:attribute, [:id, nil, sexp.last[:id]], {:tag_name => sexp[1].last.to_s.upcase}] 74 | else 75 | sexp 76 | end 77 | end 78 | 79 | def apply_join(base, elms) 80 | elms.inject(base) do |col, elm| 81 | col | elm 82 | end 83 | end 84 | 85 | def apply_antijoin(base, elms) 86 | elms.inject(base) do |col, elm| 87 | col - elm 88 | end 89 | end 90 | 91 | def apply_antijoin(elms) 92 | elms.inject([]) do |result, elm| 93 | result - elm 94 | end 95 | end 96 | 97 | class BlockBuilder 98 | attr_accessor :selector, :items 99 | 100 | def initialize(selector) 101 | self.selector, self.items = selector, [] 102 | end 103 | 104 | def method_missing(*args, &blk) 105 | OperaWatir::Selector.new(selector.collection, selector.sexp).send(*args, &blk).tap do |s| 106 | items << s 107 | end 108 | end 109 | end 110 | 111 | end 112 | -------------------------------------------------------------------------------- /lib/operawatir/spatnav.rb: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | class OperaWatir::Spatnav 3 | 4 | attr_accessor :browser 5 | 6 | def initialize(browser) 7 | self.browser = browser 8 | end 9 | 10 | # FIXME: These should be implemented as proper methods in 11 | # OperaDriver. 12 | 13 | def up 14 | driver.operaAction('Navigate up') 15 | end 16 | 17 | def down 18 | driver.operaAction('Navigate down') 19 | end 20 | 21 | def left 22 | driver.operaAction('Navigate left') 23 | end 24 | 25 | def right 26 | driver.operaAction('Navigate right') 27 | end 28 | 29 | def activate 30 | driver.operaAction('Activate element') 31 | end 32 | 33 | private 34 | def driver 35 | browser.driver 36 | end 37 | 38 | end 39 | -------------------------------------------------------------------------------- /lib/operawatir/utils.rb: -------------------------------------------------------------------------------- 1 | class OperaWatir::Utils 2 | 3 | def initialize(browser) 4 | @utils = browser.driver.utils 5 | end 6 | 7 | def core_version 8 | @utils.getCoreVersion 9 | end 10 | 11 | def os 12 | @utils.getOS 13 | end 14 | 15 | def product 16 | @utils.getProduct 17 | end 18 | 19 | def binary_path 20 | @utils.getBinaryPath 21 | end 22 | 23 | def user_agent 24 | @utils.getUserAgent 25 | end 26 | 27 | def pid 28 | @utils.getPID 29 | end 30 | 31 | end 32 | -------------------------------------------------------------------------------- /lib/operawatir/version.rb: -------------------------------------------------------------------------------- 1 | module OperaWatir 2 | 3 | # @private 4 | VERSION = File.read(File.join(File.dirname(__FILE__), '../..', 'VERSION')).strip.freeze 5 | 6 | # 7 | # Fetches OperaWatir's version number. Note that this is not the same 8 | # as OperaDriver's version number. 9 | # 10 | # @return [String] Current version of OperaWatir. 11 | # 12 | def self.version 13 | VERSION 14 | end 15 | 16 | end 17 | -------------------------------------------------------------------------------- /spec/fire_event/interactive/onBlur.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | fire_event onBlur test case 4 | 5 |

6 | You should see the word “PASS” below. 7 |

8 | 9 |

FAIL

10 | 11 |
12 | 13 |
14 | 15 | 16 | 17 | 18 | foo 19 | 20 | 21 | 22 | 23 | 24 |

foo

25 |
26 | 27 | 45 | 46 | -------------------------------------------------------------------------------- /spec/fire_event/interactive/onChange.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | fire_event onChange test case 4 | 5 |

6 | You should see the word “PASS” below. 7 |

8 | 9 |

FAIL

10 | 11 |
12 | 13 |
14 | 15 | 16 | 17 | 18 | foo 19 | 20 | 21 | 22 | 23 | 24 |

foo

25 |
26 | 27 | 28 | 29 | 47 | 48 | -------------------------------------------------------------------------------- /spec/fire_event/interactive/onClick.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | fire_event onClick test case 4 | 5 |

6 | You should see the word “PASS” below. 7 |

8 | 9 |

FAIL

10 | 11 |
12 | 13 |
14 | 15 | 16 | 17 | 18 | foo 19 | 20 | 21 | 22 | 23 | 24 |

foo

25 |
26 | 27 | 45 | 46 | -------------------------------------------------------------------------------- /spec/fire_event/interactive/onDblClick.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | fire_event onDblClick test case 4 | 5 |

6 | You should see the word “PASS” below. 7 |

8 | 9 |

FAIL

10 | 11 |
12 | 13 |
14 | 15 | 16 | 17 | 18 | foo 19 | 20 | 21 | 22 | 23 | 24 |

foo

25 |
26 | 27 | 45 | 46 | -------------------------------------------------------------------------------- /spec/fire_event/interactive/onFocus.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | fire_event onFocus test case 4 | 5 |

6 | You should see the word “PASS” below. 7 |

8 | 9 |

FAIL

10 | 11 |
12 | 13 |
14 | 15 | 16 | 17 | 18 | foo 19 | 20 | 21 | 22 | 23 | 24 |

foo

25 |
26 | 27 | 45 | 46 | -------------------------------------------------------------------------------- /spec/fire_event/interactive/onMouseDown.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | fire_event onMouseDown test case 4 | 5 |

6 | You should see the word “PASS” below. 7 |

8 | 9 |

FAIL

10 | 11 |
12 | 13 |
14 | 15 | 16 | 17 | 18 | foo 19 | 20 | 21 | 22 | 23 | 24 |

foo

25 |
26 | 27 | 45 | 46 | -------------------------------------------------------------------------------- /spec/fire_event/interactive/onMouseMove.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | fire_event onMouseMove test case 4 | 5 |

6 | You should see the word “PASS” below. 7 |

8 | 9 |

FAIL

10 | 11 |
12 | 13 |
14 | 15 | 16 | 17 | 18 | foo 19 | 20 | 21 | 22 | 23 | 24 |

foo

25 |
26 | 27 | 45 | 46 | -------------------------------------------------------------------------------- /spec/fire_event/interactive/onMouseOut.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | fire_event onMouseOut test case 4 | 5 |

6 | You should see the word “PASS” below. 7 |

8 | 9 |

FAIL

10 | 11 |
12 | 13 |
14 | 15 | 16 | 17 | 18 | foo 19 | 20 | 21 | 22 | 23 | 24 |

foo

25 |
26 | 27 | 45 | 46 | -------------------------------------------------------------------------------- /spec/fire_event/interactive/onMouseOver.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | fire_event onMouseOver test case 4 | 5 |

6 | You should see the word “PASS” below. 7 |

8 | 9 |

FAIL

10 | 11 |
12 | 13 |
14 | 15 | 16 | 17 | 18 | foo 19 | 20 | 21 | 22 | 23 | 24 |

foo

25 |
26 | 27 | 45 | 46 | -------------------------------------------------------------------------------- /spec/fire_event/interactive/onMouseUp.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | fire_event onMouseUp test case 4 | 5 |

6 | You should see the word “PASS” below. 7 |

8 | 9 |

FAIL

10 | 11 |
12 | 13 |
14 | 15 | 16 | 17 | 18 | foo 19 | 20 | 21 | 22 | 23 | 24 |

foo

25 |
26 | 27 | 45 | 46 | -------------------------------------------------------------------------------- /spec/fire_event/interactive/onScroll.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | fire_event onScroll test case 4 | 5 | 10 | 11 | 12 |

FAIL

13 | 14 | 15 | -------------------------------------------------------------------------------- /spec/operawatir/README.md: -------------------------------------------------------------------------------- 1 | OperaWatir Specification 2 | ======================== 3 | 4 | This is the specification for Opera-only functionality which is not covered by the Watir 2 or 3 specifications. 5 | -------------------------------------------------------------------------------- /spec/operawatir/core/browser_spec.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path('../../watirspec_helper', __FILE__) 2 | 3 | describe OperaWatir::Browser do 4 | 5 | # Note: This method is deprecated, but still needs to be tested. 6 | describe '#opera_action' do 7 | it 'executes the specified action' do 8 | browser.url = fixture('input_fields_value.html') 9 | window.find_by_id('one').click 10 | browser.opera_action('Select all') 11 | window.eval_js('one = document.getElementById("one");') 12 | window.eval_js('one.value.substr(one.selectionStart, one.selectionEnd - one.selectionStart)').should == 'foobar' 13 | end 14 | end 15 | 16 | # Note: This method is deprecated, but still needs to be tested. 17 | describe '#opera_action_list' do 18 | it 'returns a list of available Opera actions' do 19 | browser.url = 'about:blank' 20 | browser.opera_action_list.should include 'copy' 21 | browser.opera_action_list.should include 'paste' 22 | end 23 | end 24 | 25 | # Note: This method is deprecated, but still needs to be tested. 26 | describe '#key' do 27 | it 'presses the specified key' do 28 | browser.url = fixture('two_input_fields.html') 29 | window.find_by_name('one').click 30 | browser.key 'a' 31 | window.find_by_name('one').value.should == 'a' 32 | end 33 | end 34 | 35 | # Note: This method is deprecated, but still needs to be tested. 36 | describe '#key_down' do 37 | it 'holds down the specfied key' do 38 | browser.url = fixture('grid.html') 39 | browser.key_down 'Shift' # This invokes spatnav on desktop browsers 40 | browser.key 'Down' 41 | browser.key 'Down' 42 | browser.key_up 'Shift' 43 | window.execute_script("document.activeElement.text;").should == 'C2' 44 | end 45 | end 46 | 47 | # Note: This method is deprecated, but still needs to be tested. 48 | describe '#key_up' do 49 | it 'releases the specfied key' do 50 | browser.url = fixture('grid.html') 51 | browser.key_down 'Shift' # This invokes spatnav on desktop browsers 52 | browser.key 'Down' 53 | browser.key 'Down' 54 | browser.key_up 'Shift' 55 | browser.key 'Down' 56 | window.execute_script("document.activeElement.text;").should == 'C2' 57 | end 58 | end 59 | 60 | # Note: This method is deprecated, but still needs to be tested. 61 | describe '#type' do 62 | it 'types a string of characters' do 63 | browser.url = fixture('two_input_fields.html') 64 | window.find_by_name('one').click 65 | browser.type 'foobar' 66 | window.find_by_name('one').value.should == 'foobar' 67 | end 68 | end 69 | 70 | describe '#desktop?' do 71 | it 'returns true or false' do 72 | [true, false].should include browser.desktop? 73 | end 74 | end 75 | 76 | describe '#version' do 77 | it 'fetches the version number of the driver' do 78 | browser.version.should_not be_empty 79 | end 80 | end 81 | 82 | end 83 | -------------------------------------------------------------------------------- /spec/operawatir/core/element_spec.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path('../../watirspec_helper', __FILE__) 2 | require 'tmpdir' 3 | 4 | describe OperaWatir::Element do 5 | 6 | describe '#click' do 7 | # TODO: Move to watirspec 8 | it 'clicks LABEL elements tied to form submit' do 9 | browser.url = fixture('label_submit.html') 10 | window.find_by_tag('label').click 11 | window.text.should include 'PASS' 12 | end 13 | end 14 | 15 | describe '#triple_click' do 16 | it 'clicks three times' do 17 | browser.url = fixture('onclick.html') 18 | window.find_by_tag('button').triple_click 19 | window.find_by_id('clicks').text.should == '3' 20 | end 21 | end 22 | 23 | describe '#quadruple_click' do 24 | it 'clicks four times' do 25 | browser.url = fixture('onclick.html') 26 | window.find_by_tag('button').quadruple_click 27 | window.find_by_id('clicks').text.should == '4' 28 | end 29 | end 30 | 31 | # This method is deprecated, but needs to be tested anyway. 32 | describe '#compare_hash' do 33 | 34 | before :each do 35 | browser.url = fixture('boxes.html') 36 | @one = window.find_by_id('one'); 37 | @two = window.find_by_id('two'); 38 | @three = window.find_by_id('three'); 39 | end 40 | 41 | it 'interprets two visually different elements as different' do 42 | @one.compare_hash(@two).should be_false 43 | end 44 | 45 | it 'interprets two visually identical elements as identical' do 46 | @one.compare_hash(@three).should be_true 47 | end 48 | end 49 | 50 | describe '#screenshot' do 51 | after (:each) do 52 | File.delete(Dir.tmpdir + '/screenshot.png') 53 | end 54 | 55 | it 'takes a screenshot of the specified element' do 56 | browser.url = fixture('boxes.html') 57 | window.find_by_id('one').screenshot(Dir.tmpdir + '/screenshot.png', 1000).should be_true 58 | end 59 | end 60 | 61 | describe '#visual_hash' do 62 | 63 | before :each do 64 | browser.url = fixture('boxes.html') 65 | @one = window.find_by_id('one'); 66 | @two = window.find_by_id('two'); 67 | @three = window.find_by_id('three'); 68 | @four = window.find_by_id('four'); 69 | end 70 | 71 | it 'returns a hash' do 72 | @one.visual_hash.should =~ /^(0x)[a-f0-9]{32}$/ 73 | end 74 | 75 | it 'returns identical hashes for visually identical elements' do 76 | @one.visual_hash.should == @three.visual_hash 77 | end 78 | 79 | it 'returns different hashes for visually different elements' do 80 | @one.visual_hash.should_not == @two.visual_hash 81 | end 82 | 83 | it 'returns correct hashes when querying several elements in sequence' do 84 | @one.visual_hash.should == @three.visual_hash 85 | @two.visual_hash.should == @four.visual_hash 86 | @one.visual_hash.should_not == @two.visual_hash 87 | @two.visual_hash.should_not == @three.visual_hash 88 | end 89 | 90 | it 'returns a hash of an SVG element' do 91 | browser.url = fixture('browsers.svg') 92 | window.find_by_tag('svg').visual_hash.should =~ /^(0x)[a-f0-9]{32}$/ 93 | end 94 | 95 | end 96 | 97 | end 98 | -------------------------------------------------------------------------------- /spec/operawatir/core/keys_spec.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path('../../watirspec_helper', __FILE__) 2 | 3 | # 4 | # TODO 5 | # 6 | 7 | =begin 8 | describe OperaWatir::Keys do 9 | 10 | before(:each) { browser.url = fixture('keys.html') } 11 | 12 | let(:keys) { browser.keys } 13 | let(:keyboard) { window.pre(:id => 'log').text } 14 | 15 | subject { keyboard } 16 | 17 | describe '#down' do 18 | it 'presses one key' do 19 | end 20 | 21 | it 'presses series of keys' do 22 | end 23 | end 24 | 25 | describe '#up' do 26 | it 'releases one key' do 27 | end 28 | 29 | it 'releases series of keys' do 30 | end 31 | end 32 | 33 | describe '#release' do 34 | it 'releases one key' do 35 | keys.down 'a' 36 | keyboard.should hold_down_keys 'a' 37 | keys.release 38 | keyboard.should_not hold_down_keys 'a' 39 | end 40 | 41 | it 'releases one modifier key' do 42 | keys.down :shift 43 | keyboard.should hold_down_keys :shift 44 | keys.release 45 | keyboard.should_not hold_down_keys :shift 46 | end 47 | 48 | it 'releases several keys' do 49 | keys.down 'a', 'b' 50 | keyboard.should hold_down_keys 'a', 'b' 51 | keys.release 52 | keyboard.should_not hold_down_keys 'a', 'b' 53 | end 54 | 55 | it 'releases several modifier keys' do 56 | keys.down :shift, :control 57 | keyboard.should hold_down_keys :shift, :control 58 | keys.release 59 | keyboard.should_not hold_down_keys :shift, :control 60 | end 61 | 62 | it 'releases a combination of keys and modifier keys' do 63 | keys.down :shift, :control, 'a' 64 | keyboard.should hold_down_keys :shift, :control, 'a' 65 | keys.release 66 | keyboard.should_not hold_down_keys :shift, :control, 'a' 67 | end 68 | end 69 | 70 | describe '#send' do 71 | end 72 | 73 | end 74 | =end 75 | -------------------------------------------------------------------------------- /spec/operawatir/core/screenshot_spec.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path('../../watirspec_helper', __FILE__) 2 | require 'tmpdir' 3 | 4 | RSpec::Matchers.define :save_file do 5 | match { |filename| File.exists? filename } 6 | end 7 | 8 | RSpec::Matchers.define :be_boolean do 9 | match { |variable| !!variable == variable } 10 | end 11 | 12 | describe 'Screenshot' do 13 | 14 | before :all do 15 | browser.url = fixture('boxes.html') 16 | @screenshot = window.screenshot 17 | @filename = "#{Dir.tmpdir}/screenshot.png" 18 | end 19 | 20 | describe '#new' do 21 | context 'given no argument' do 22 | it 'creates a new Screenshot object' do 23 | @screenshot.should be_kind_of OperaWatir::Screenshot 24 | end 25 | end 26 | 27 | context 'given an argument' do 28 | it 'saves a screenshot' do 29 | window.screenshot(@filename).should save_file 30 | end 31 | end 32 | end 33 | 34 | describe '#save' do 35 | it 'saves screenshot to disk' do 36 | @screenshot.save(@filename).should save_file 37 | end 38 | end 39 | 40 | describe '#blank?' do 41 | it 'returns a valid type' do 42 | @screenshot.blank?.should be_boolean 43 | end 44 | 45 | it 'is not blank' do 46 | @screenshot.blank?.should be_false 47 | end 48 | end 49 | 50 | describe '#png' do 51 | before(:all) { @png = @screenshot.png } 52 | 53 | it 'returns a valid type' do 54 | @png.should be_kind_of String 55 | end 56 | 57 | it 'is a real type PNG image' do 58 | @png.should match /PNG/ 59 | end 60 | end 61 | 62 | describe '#md5' do 63 | before(:all) { @md5 = @screenshot.md5 } 64 | 65 | it 'returns a valid type' do 66 | @md5.should be_kind_of String 67 | end 68 | 69 | it 'returns a hash' do 70 | @md5.should match /^(0x)[a-f0-9]{32}$/ 71 | end 72 | end 73 | 74 | after(:all) { File.delete @filename if File.exists? @filename } 75 | 76 | end 77 | -------------------------------------------------------------------------------- /spec/operawatir/core/spatnav_spec.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path('../../watirspec_helper', __FILE__) 2 | 3 | describe OperaWatir::Spatnav do 4 | 5 | before :each do 6 | browser.url = fixture('grid.html') 7 | @spatnav = browser.spatnav 8 | end 9 | 10 | describe '#up' do 11 | it 'selects the correct links when navigating up' do 12 | @spatnav.up 13 | window.execute_script("document.activeElement.text;").to_s.should == 'C1' 14 | @spatnav.up 15 | window.execute_script("document.activeElement.text;").to_s.should == 'C2' 16 | @spatnav.up 17 | window.execute_script("document.activeElement.text;").to_s.should == 'C3' 18 | end 19 | end 20 | 21 | describe '#down' do 22 | it 'selects the correct links when navigating down' do 23 | @spatnav.down 24 | window.execute_script("document.activeElement.text;").to_s.should == 'C3' 25 | @spatnav.down 26 | window.execute_script("document.activeElement.text;").to_s.should == 'C2' 27 | @spatnav.down 28 | window.execute_script("document.activeElement.text;").to_s.should == 'C1' 29 | end 30 | end 31 | 32 | describe '#left' do 33 | it 'selects the correct links when navigating left' do 34 | @spatnav.left 35 | window.execute_script("document.activeElement.text;").to_s.should == 'C1' 36 | @spatnav.left 37 | window.execute_script("document.activeElement.text;").to_s.should == 'B1' 38 | @spatnav.left 39 | window.execute_script("document.activeElement.text;").to_s.should == 'A1' 40 | end 41 | end 42 | 43 | describe '#right' do 44 | it 'selects the correct links when navigating right' do 45 | @spatnav.right 46 | window.execute_script("document.activeElement.text;").to_s.should == 'A1' 47 | @spatnav.right 48 | window.execute_script("document.activeElement.text;").to_s.should == 'B1' 49 | @spatnav.right 50 | window.execute_script("document.activeElement.text;").to_s.should == 'C1' 51 | end 52 | end 53 | 54 | describe '#activate!' do 55 | it 'activates the focused link' do 56 | @spatnav.down 57 | @spatnav.activate 58 | window.url.should include 'C3' 59 | end 60 | end 61 | 62 | end 63 | -------------------------------------------------------------------------------- /spec/operawatir/core/utils_spec.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path('../../watirspec_helper', __FILE__) 2 | 3 | describe OperaWatir::Utils do 4 | 5 | before(:all) { @utils = browser.utils } 6 | 7 | describe '#core_version' do 8 | it 'it matches a core version number' do 9 | @utils.core_version.should match /\d+\.\d+\.\d+/ 10 | end 11 | end 12 | 13 | describe '#os' do 14 | it 'is not empty' do 15 | @utils.os.should_not be_empty 16 | end 17 | end 18 | 19 | describe '#product' do 20 | it 'is not unknown' do 21 | @utils.product.should_not include 'unknown' 22 | end 23 | 24 | it 'is known' do 25 | @utils.product.should match /core-gogi|desktop/ 26 | end 27 | end 28 | 29 | describe '#binary_path' do 30 | it 'is not empty' do 31 | @utils.binary_path.should_not be_empty 32 | end 33 | end 34 | 35 | describe '#user_agent' do 36 | it 'is a User-Agent string' do 37 | @utils.user_agent.should match /Opera\/\d+\.\d+.+/ 38 | end 39 | end 40 | 41 | describe '#pid' do 42 | it 'is greater than zero' do 43 | @utils.pid.should > 0 44 | end 45 | end 46 | 47 | end 48 | -------------------------------------------------------------------------------- /spec/operawatir/core/window_spec.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path('../../watirspec_helper', __FILE__) 2 | require 'tmpdir' 3 | 4 | describe OperaWatir::Window do 5 | 6 | describe '#visual_hash' do 7 | before :each do 8 | browser.url = fixture('boxes.html') 9 | @reference = window.visual_hash 10 | end 11 | 12 | it 'returns a hash' do 13 | @reference.should match /^(0x)[a-f0-9]{32}$/ 14 | end 15 | 16 | it 'returns identical hashes for visually identical pages' do 17 | browser.url = fixture('boxes.html') 18 | window.visual_hash.should == @reference 19 | end 20 | 21 | it 'returns different hashes for visually different pages' do 22 | browser.url = fixture('grid.html') 23 | window.visual_hash.should_not == @reference 24 | end 25 | 26 | it 'returns a hash of an SVG document' do 27 | browser.url = fixture('browsers.svg') 28 | browser.visual_hash.should match /^(0x)[a-f0-9]{32}$/ 29 | end 30 | end 31 | 32 | 33 | # 34 | # This method is deprecated, but must be tested anyway. 35 | # 36 | 37 | describe '#eval_js' do 38 | it 'works the same way as execute_script' do 39 | window.eval_js('1+1').should == window.execute_script('1+1'); 40 | end 41 | end 42 | 43 | # 44 | # The frames implementation is a relic from the old OperaWatir. We 45 | # need to replace this with a better frames implementation in the 46 | # future. 47 | # 48 | 49 | describe '#frame' do 50 | before :all do 51 | require 'operawatir/compat/window' 52 | OperaWatir::Window.send :include, OperaWatir::Compat::Window 53 | browser.url = fixture('frames.html') 54 | end 55 | 56 | it 'will switch to the specified frame' do 57 | window.frame(:name, 'test') 58 | window.text.should include 'Lorem ipsum' 59 | window.text.should_not include 'foobar' 60 | end 61 | end 62 | 63 | describe '#switch_to_default' do 64 | before :all do 65 | browser.url = fixture('frames.html') 66 | window.frame(:name, 'test') 67 | end 68 | 69 | it 'will switch back to the default top frame' do 70 | window.switch_to_default 71 | window.text.should include 'foobar' 72 | window.text.should_not include 'Lorem ipsum' 73 | end 74 | end 75 | 76 | end 77 | -------------------------------------------------------------------------------- /spec/operawatir/desktop/quickaddressfield_spec.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path('../../watirspec_desktophelper', __FILE__) 2 | require File.expand_path('../shared/shared', __FILE__) 3 | 4 | describe 'QuickAddressfield' do 5 | 6 | let(:addressfield) { browser.quick_toolbar(:name, "Document Toolbar").quick_addressfield(:name, "tba_address_field") } 7 | let(:unknown_addressfield) { browser.quick_toolbar(:name, "Document Toolbar").quick_addressfield(:name, "no_address_field") } 8 | let(:widget) { browser.quick_toolbar(:name, "Document Toolbar").quick_addressfield(:name, "tba_address_field") } 9 | 10 | subject { addressfield } 11 | 12 | it_behaves_like 'a widget' 13 | it_behaves_like 'an editfield' 14 | 15 | describe '#quick_addressfield' do 16 | it 'constructs addressfield by its name' do 17 | browser.quick_toolbar(:name, "Document Toolbar").quick_addressfield(:name, "tba_address_field") 18 | end 19 | it 'constructs addressfield by its name' do 20 | browser.quick_toolbar(:name, "Document Toolbar").quick_addressfield(:name, "tba_address_field2") 21 | end 22 | end 23 | 24 | its(:type) { should == :addressfield } 25 | 26 | describe '#load_page_with_url' do 27 | it 'loads page' do 28 | addressfield.load_page_with_url("opera:debug").should == "opera:debug" 29 | end 30 | it 'throws exception if unknown addressfield' do 31 | expect { unknown_addressfield.highlighted_text }.to raise_error OperaWatir::Exceptions::UnknownObjectException 32 | end 33 | end 34 | 35 | describe '#text' do 36 | its(:text) { should == "opera:debug" } 37 | 38 | it 'throws exception if unknown addressfield' do 39 | expect { unknown_addressfield.highlighted_text }.to raise_error OperaWatir::Exceptions::UnknownObjectException 40 | end 41 | end 42 | 43 | describe '#visible_text' do 44 | its(:visible_text) { should == "debug" } 45 | 46 | it 'throws exception if unknown addressfield' do 47 | expect { unknown_addressfield.highlighted_text }.to raise_error OperaWatir::Exceptions::UnknownObjectException 48 | end 49 | end 50 | 51 | describe '#highlighted_text' do 52 | its(:highlighted_text) { should == "" } 53 | 54 | it 'throws exception if unknown addressfield' do 55 | expect { unknown_addressfield.highlighted_text }.to raise_error OperaWatir::Exceptions::UnknownObjectException 56 | end 57 | end 58 | 59 | end -------------------------------------------------------------------------------- /spec/operawatir/desktop/quickcheckbox_spec.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path('../../watirspec_desktophelper', __FILE__) 2 | require File.expand_path('../shared/shared', __FILE__) 3 | 4 | describe 'QuickCheckbox' do 5 | 6 | before(:each) do 7 | browser.open_dialog_with_action("New Preferences Dialog", "Show preferences", 4) 8 | browser.quick_treeview(:name, "Advanced_treeview").quick_treeitem(:string_id, "D_NEW_PREFS_SECURITY").activate_tab_with_click 9 | end 10 | 11 | after(:each) do 12 | browser.close_all_dialogs 13 | end 14 | 15 | let(:widget) { browser.quick_checkbox(:name, "Trust_info_checkbox") } 16 | subject { widget } 17 | 18 | it_behaves_like 'a checkbox' 19 | 20 | its(:type) { should == :checkbox } 21 | 22 | describe '#open_dialog_with_click' do 23 | it 'returns window id' do 24 | browser.quick_button(:name, "Set_password_button").open_dialog_with_click("Change Masterpassword Dialog").should > 0 25 | browser.quick_editfield(:name, "Password_edit").focus_with_click 26 | browser.quick_editfield(:name, "Password_edit").type_text("masterpass1").should == "masterpass1" 27 | browser.quick_editfield(:name, "Confirm_password_edit").focus_with_click 28 | browser.quick_editfield(:name, "Confirm_password_edit").type_text("masterpass1").should == "masterpass1" 29 | browser.quick_button(:name, "button_OK").close_dialog_with_click("Change Masterpassword Dialog").should close_dialog 30 | browser.quick_checkbox(:name, "Master_password_checkbox").open_dialog_with_click("Security Password Dialog").should > 0 31 | end 32 | end 33 | 34 | end 35 | 36 | 37 | -------------------------------------------------------------------------------- /spec/operawatir/desktop/quickdialogtab_spec.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path('../../watirspec_desktophelper', __FILE__) 2 | require File.expand_path('../shared/shared', __FILE__) 3 | 4 | describe 'QuickDialogTab' do 5 | before(:all) do 6 | browser.open_dialog_with_action("New Preferences Dialog", "Show preferences").should > 0 7 | end 8 | 9 | after(:all) do 10 | browser.close_all_dialogs 11 | end 12 | 13 | let(:widget) { browser.quick_dialogtab(:name, "tab_prefs_advanced") } 14 | subject { widget } 15 | 16 | it_behaves_like 'a widget' 17 | 18 | its(:type) { should == :dialogtab } 19 | 20 | describe '#activate_tab_with_click' do 21 | it 'activates a tab with click' do 22 | browser.quick_dialogtab(:name, "tab_prefs_advanced").activate_tab_with_click 23 | browser.quick_checkbox(:name, "Thumbnails_in_tab_cycle").should be_visible 24 | end 25 | end 26 | 27 | end 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /spec/operawatir/desktop/quickdropdown_spec.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path('../../watirspec_desktophelper', __FILE__) 2 | require File.expand_path('../shared/shared', __FILE__) 3 | 4 | describe 'QuickDropdown' do 5 | 6 | before(:all) do 7 | browser.open_dialog_with_action("New Preferences Dialog", "Show preferences", 0).should > 0 8 | end 9 | 10 | after(:all) do 11 | browser.close_all_tabs 12 | browser.close_all_dialogs 13 | end 14 | 15 | let(:widget) { browser.quick_dropdown(:name, "Startup_mode_dropdown") } 16 | subject { widget } 17 | 18 | it_behaves_like 'a widget' 19 | 20 | 21 | describe '#selected?'do 22 | it 'returns true for selected item' do 23 | browser.quick_dropdown(:name, "Startup_mode_dropdown").selected?("D_STARTUP_LAST_TIME").should be_true 24 | end 25 | 26 | it 'returns false for not selected item' do 27 | browser.quick_dropdown(:name, "Startup_mode_dropdown").selected?("D_STARTUP_SAVED_SESSIONS").should be_false 28 | end 29 | 30 | it 'raises an exception for not shown widget' do 31 | browser.close_all_dialogs 32 | expect { browser.quick_dropdown(:name, "Startup_mode_dropdown").selected?("D_STARTUP_SAVED_SESSIONS") }.to raise_error OperaWatir::DesktopExceptions::UnknownObjectException 33 | end 34 | 35 | end 36 | 37 | 38 | end 39 | 40 | -------------------------------------------------------------------------------- /spec/operawatir/desktop/quickeditfield_spec.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path('../../watirspec_desktophelper', __FILE__) 2 | require File.expand_path('../shared/shared', __FILE__) 3 | 4 | 5 | describe 'QuickEditField' do 6 | 7 | before(:all) do 8 | browser.open_dialog_with_action("New Preferences Dialog", "Show preferences", 1).should open_dialog 9 | end 10 | 11 | after(:all) do 12 | browser.close_all_tabs 13 | browser.close_all_dialogs 14 | end 15 | 16 | let(:url1) { "http://t/platforms/desktop/automated/resources/documents/page1.html" } 17 | let(:url2) { "http://t/platforms/desktop/automated/resources/documents/page2.html" } 18 | 19 | let(:widget) { browser.quick_editfield(:name, "Firstname_edit") } 20 | subject { widget } 21 | 22 | it_behaves_like 'a widget' 23 | it_behaves_like 'an editfield' 24 | 25 | its(:type) { should == :editfield } 26 | 27 | describe '#load_page_with_key_press(key, *modifiers)' do 28 | it 'loads page' do 29 | browser.close_all_dialogs 30 | browser.quick_window(:name, "Document Window").quick_toolbar(:name, "Document Toolbar").quick_addressfield(:name, "tba_address_field").focus_with_click 31 | browser.quick_window(:name, "Document Window").quick_toolbar(:name, "Document Toolbar").quick_addressfield(:name, "tba_address_field").clear 32 | browser.quick_window(:name, "Document Window").quick_toolbar(:name, "Document Toolbar").quick_addressfield(:name, "tba_address_field").type_text(url1).should == url1 33 | browser.load_page_with_key_press("Enter").should > 0 34 | browser.quick_window(:name, "Document Window").quick_toolbar(:name, "Document Toolbar").quick_addressfield(:name, "tba_address_field").text.should == url1 35 | browser.quick_window(:name, "Browser Window").quick_toolbar(:name, "Pagebar").quick_tab(:name, "Tab 0").text.should == "Test Page 1" 36 | end 37 | end 38 | 39 | =begin # it is a private method 40 | describe '#enter_text_and_hit_enter(text)' do 41 | it "type text and press enter in the same method" do 42 | browser.quick_window(:name, "Document Window").quick_toolbar(:name, "Document Toolbar").quick_addressfield(:name, "tba_address_field").focus_with_click 43 | browser.quick_window(:name, "Document Window").quick_toolbar(:name, "Document Toolbar").quick_addressfield(:name, "tba_address_field").clear 44 | browser.quick_window(:name, "Document Window").quick_toolbar(:name, "Document Toolbar").quick_addressfield(:name, "tba_address_field").enter_text_and_hit_enter(url2).should == url2 45 | browser.quick_window(:name, "Document Window").quick_toolbar(:name, "Document Toolbar").quick_addressfield(:name, "tba_address_field").text.should == url2 46 | browser.quick_window(:name, "Browser Window").quick_toolbar(:name, "Pagebar").quick_tab(:name, "Tab 0").text.should == "Test Page 2" 47 | end 48 | end 49 | =end 50 | 51 | end -------------------------------------------------------------------------------- /spec/operawatir/desktop/quickfind_spec.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path('../../watirspec_desktophelper', __FILE__) 2 | require File.expand_path('../shared/shared', __FILE__) 3 | 4 | describe 'QuickFind' do 5 | 6 | before(:all) do 7 | browser.open_dialog_with_action("New Preferences Dialog", "Show preferences", 4).should > 0 8 | browser.quick_treeview(:name, "Advanced_treeview").quick_treeitem(:text, "Downloads").activate_tab_with_click 9 | end 10 | 11 | after(:all) do 12 | browser.close_all_dialogs 13 | end 14 | 15 | let(:widget) { browser.quick_find(:name, "Filetypes_quickfind") } 16 | 17 | subject { widget } 18 | 19 | it_behaves_like 'an editfield' 20 | it_behaves_like 'a widget' 21 | 22 | its(:type) { should == :quickfind } 23 | 24 | describe '#quick_find' do 25 | it 'constructs quickfind by its name' do 26 | browser.quick_find(:name, "Filetypes_quickfind").should exist 27 | end 28 | end 29 | 30 | end -------------------------------------------------------------------------------- /spec/operawatir/desktop/quickgriditem_spec.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path('../../watirspec_desktophelper', __FILE__) 2 | 3 | describe 'QuickItem' do 4 | 5 | #let(:widget) { browser.quick_label(:name, "label_for_Name_edit") } 6 | #subject { widget } 7 | #it_behaves_like "a widget" 8 | #its(:type) { should == :griditem } 9 | 10 | describe '#quick_griditem' do 11 | it 'constructs grid_item by its name' do 12 | browser.quick_griditem(:name, "some_name") 13 | end 14 | end 15 | 16 | end -------------------------------------------------------------------------------- /spec/operawatir/desktop/quickgridlayout_spec.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path('../../watirspec_desktophelper', __FILE__) 2 | 3 | describe 'QuickLayout' do 4 | 5 | #let(:widget) { browser.quick_label(:name, "label_for_Name_edit") } 6 | #subject { widget } 7 | #it_behaves_like "a widget" 8 | #its(:type) { should == :gridlayout } 9 | 10 | describe '#quick_gridlayout' do 11 | it 'constructs grid_layout by its name' do 12 | browser.quick_gridlayout(:name, "some_name") 13 | end 14 | end 15 | end -------------------------------------------------------------------------------- /spec/operawatir/desktop/quicklabel_spec.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path('../../watirspec_desktophelper', __FILE__) 2 | require File.expand_path('../shared/shared', __FILE__) 3 | 4 | describe 'QuickLabel' do 5 | 6 | before(:all) do 7 | browser.open_dialog_with_key_press("Add Bookmark Dialog", 'd', :ctrl) 8 | end 9 | 10 | after(:all) do 11 | browser.close_all_dialogs 12 | end 13 | 14 | let(:widget) { browser.quick_label(:name, "label_for_Name_edit") } 15 | 16 | subject { widget } 17 | 18 | it_behaves_like "a widget" 19 | 20 | its(:type) { should == :label } 21 | 22 | describe '#quick_label' do 23 | it 'constructs label by its name' do 24 | browser.quick_label(:name, "label_for_Name_edit").should exist 25 | end 26 | end 27 | 28 | end -------------------------------------------------------------------------------- /spec/operawatir/desktop/quickmenu_spec.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path('../../watirspec_desktophelper', __FILE__) 2 | require File.expand_path('../shared/shared', __FILE__) 3 | 4 | describe 'QuickMenu' do 5 | let(:addressfield) { browser.quick_toolbar(:name, "Document Toolbar").quick_addressfield(:name, "tba_address_field") } 6 | let(:menu) { browser.quick_menu(:name, "Toolbar Edit Item Popup Menu") } 7 | 8 | subject { menu } 9 | 10 | before(:each) do 11 | addressfield.open_menu_with_rightclick("Toolbar Edit Item Popup Menu").should open_menu 12 | end 13 | after(:each) do 14 | browser.close_all_menus 15 | end 16 | 17 | its(:name) { should_not be_empty } 18 | its(:window_id) { should be_kind_of Integer } 19 | its(:to_s) { should_not be_empty } #should == menu.element.toString() 20 | its(:width) { should be_kind_of Integer } 21 | its(:height) { should be_kind_of Integer } 22 | its(:x) { should be_kind_of Integer } 23 | its(:y) { should be_kind_of Integer } 24 | 25 | describe '#exists'do 26 | it 'should return true' do 27 | menu.should exist 28 | end 29 | end 30 | 31 | describe '#parentmenu?' do 32 | it 'should return true or false' do 33 | menu.should be_parentmenu 34 | end 35 | end 36 | 37 | describe '#quick_menu' do 38 | it 'constructs a menu by its name' do 39 | menu.should exist 40 | end 41 | end 42 | 43 | describe '#quick_menus' do 44 | it 'lists all menus' do 45 | browser.quick_menus.should_not be_empty 46 | end 47 | end 48 | 49 | describe '#quick_menuitems' do 50 | it 'lists menuitems in this menu' do 51 | puts menu.quick_menuitems 52 | menu.quick_menuitems.select { |item| item.menu != menu.name }.should be_empty 53 | menu.quick_menuitems.select { |item| item.menu == menu.name }.should_not be_empty 54 | menu.quick_menuitems.select { |item| item.submenu_item? == true }.should_not be_empty 55 | end 56 | end 57 | end 58 | -------------------------------------------------------------------------------- /spec/operawatir/desktop/quickradiobutton_spec.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path('../../watirspec_desktophelper', __FILE__) 2 | require File.expand_path('../shared/shared', __FILE__) 3 | 4 | describe 'QuickRadiobox' do 5 | 6 | before(:all) do 7 | browser.open_dialog_with_action("New Preferences Dialog", "Show preferences", 4) 8 | browser.quick_treeview(:name, "Advanced_treeview").quick_treeitem(:string_id, "D_NEW_PREFS_COOKIES").activate_tab_with_click 9 | end 10 | 11 | after(:all) do 12 | browser.close_all_dialogs 13 | end 14 | 15 | let(:widget) { browser.quick_radiobutton(:name, "Accept_cookies_radio") } 16 | subject { widget } 17 | 18 | it_behaves_like 'a widget' 19 | it_behaves_like 'a checkbox' 20 | 21 | its(:type) { should == :radiobutton } 22 | 23 | 24 | end 25 | -------------------------------------------------------------------------------- /spec/operawatir/desktop/quicksearchfield_spec.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path('../../watirspec_desktophelper', __FILE__) 2 | require File.expand_path('../shared/shared', __FILE__) 3 | 4 | describe 'QuickSearchField' do 5 | 6 | let(:widget) { browser.quick_window(:name, "Document Window").quick_toolbar(:name, "Document Toolbar").quick_searchfield(:name, "tbs_MainSearch") } 7 | subject { widget } 8 | 9 | it_behaves_like "a widget" 10 | it_behaves_like "an editfield" 11 | 12 | its(:type) { should == :search } 13 | 14 | describe '#quick_searchfield' do 15 | it 'constructs searchfield by its name' do 16 | browser.quick_window(:name, "Document Window").quick_toolbar(:name, "Document Toolbar").quick_searchfield(:name, "tbs_MainSearch").should exist 17 | end 18 | end 19 | 20 | describe '#search_with_text' do 21 | it 'returns text in address field after loading of page' do 22 | browser.quick_window(:name, "Document Window").quick_toolbar(:name, "Document Toolbar").quick_searchfield(:name, "tbs_MainSearch").search_with_text("old cars").should include "http://www.google.no/search" 23 | end 24 | end 25 | 26 | end -------------------------------------------------------------------------------- /spec/operawatir/desktop/quickthumbnail_spec.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path('../../watirspec_desktophelper', __FILE__) 2 | require File.expand_path('../shared/shared', __FILE__) 3 | 4 | describe 'QuickThumbnail' do 5 | 6 | before(:all) do 7 | browser.open_window_with_key_press("Document Window", "t", :ctrl) 8 | end 9 | 10 | let(:widget) { browser.quick_thumbnail(:name, "Speed Dial 1") } 11 | 12 | subject { widget } 13 | 14 | it_behaves_like 'a widget' 15 | it_behaves_like 'a button' 16 | 17 | its(:type) { should == :thumbnail } 18 | 19 | #This is really on browser, widgets, and window 20 | describe '#quick_thumbnail' do 21 | it 'constructs thumbnail by its position' do 22 | browser.quick_thumbnail(:pos, 1).should exist 23 | end 24 | it 'constructs thumbnail by its name' do 25 | browser.quick_thumbnail(:name, "Speed Dial 1").should exist 26 | end 27 | it 'constructs thumbnail by its text' do #it won't be language independant and will depend on existed Speed Dials 28 | browser.quick_thumbnail(:text, "Opera Portal").should exist 29 | end 30 | end 31 | 32 | describe '#move_with_drag' do 33 | 34 | it 'moves thumbnail' #do #DSK-335945 bloacks this section 35 | # SD1 = browser.quick_window(:name, "Document Window").quick_thumbnail(:name, "Speed Dial 1").text 36 | # SD2 = browser.quick_window(:name, "Document Window").quick_thumbnail(:name, "Speed Dial 2").text 37 | # thumbnail_to_drop_on = browser.quick_window(:name, "Document Window").quick_thumbnail(:name, "Speed Dial 2") 38 | # browser.browser.quick_window(:name, "Document Window").quick_thumbnail(:name, "Speed Dial 1").move_with_drag(thumbnail_to_drop_on) 39 | # browser.quick_window(:name, "Document Window").quick_thumbnail(:name, "Speed Dial 1").text.should == SD2 40 | # browser.quick_window(:name, "Document Window").quick_thumbnail(:name, "Speed Dial 2").text.should == SD1 41 | #end 42 | 43 | context 'when target is not a thumbnail' do 44 | it 'raises UnknownObjectException' do 45 | expect { browser.quick_window(:name, "Document Window").quick_thumbnail(:name, "Speed Dial 1").move_with_drag(browser.quick_window(:name, "Browser Window")) }.to raise_error OperaWatir::DesktopExceptions::UnknownObjectException 46 | end 47 | end 48 | end 49 | 50 | end 51 | 52 | -------------------------------------------------------------------------------- /spec/operawatir/desktop/quicktreeview_spec.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path('../../watirspec_desktophelper', __FILE__) 2 | require File.expand_path('../shared/shared', __FILE__) 3 | 4 | describe 'QuickTreeView' do 5 | 6 | before(:all) do 7 | browser.open_dialog_with_action("New Preferences Dialog", "Show preferences", 4).should > 0 8 | end 9 | 10 | after(:all) do 11 | browser.close_all_dialogs 12 | end 13 | 14 | let(:widget) { browser.quick_treeview(:name, "Advanced_treeview") } 15 | subject { widget } 16 | 17 | it_behaves_like 'a widget' 18 | 19 | its(:type) { should == :treeview } 20 | 21 | 22 | describe '#num_treeitems' do 23 | it "returns numbers of treeitems in the treeview" do 24 | browser.quick_treeview(:name, "Advanced_treeview").num_treeitems.should > 0 25 | end 26 | 27 | end 28 | 29 | 30 | end 31 | -------------------------------------------------------------------------------- /spec/operawatir/fixtures/boxes.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Colorful boxes 4 | 17 | 18 |
19 |
20 | 21 |
22 |
23 | -------------------------------------------------------------------------------- /spec/operawatir/fixtures/draggableLists.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | jQuery UI Sortable - Connect lists 6 | 7 | 8 | 9 | 10 | 11 | 15 | 40 | 41 | 42 |
43 |
    44 |
  • LeftItem 1
  • 45 |
  • LeftItem 2
  • 46 |
  • LeftItem 3
  • 47 |
  • LeftItem 4
  • 48 |
  • LeftItem 5
  • 49 |
50 | 51 |
    52 |
  • RightItem 1
  • 53 |
  • RightItem 2
  • 54 |
  • RightItem 3
  • 55 |
  • RightItem 4
  • 56 |
  • RightItem 5
  • 57 |
58 | 59 |
60 | 61 |
62 |
63 |

Nothing happened.

64 |
65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /spec/operawatir/fixtures/formSelectionPage.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Testing Typing into body 5 | 26 | 27 | 28 | 29 |

Type Stuff

30 | 31 |
32 |   33 |
34 | 35 |
36 | 42 |
43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /spec/operawatir/fixtures/frames.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Frames 5 | 6 |

7 | foobar 8 |

9 | 10 | 13 | 14 | -------------------------------------------------------------------------------- /spec/operawatir/fixtures/grid.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | A grid of links with algebraic notation 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 |
A3B3C3
A2B2C2
A1B1C1
25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /spec/operawatir/fixtures/input_fields_value.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Simple page with two input fields, of which one has a value 4 | 5 |

6 |

7 | -------------------------------------------------------------------------------- /spec/operawatir/fixtures/keys.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Keys fixture 6 | 7 | 8 |

Keys test

9 |

10 | 
11 | 
38 | 
39 | 
40 | 
41 | 


--------------------------------------------------------------------------------
/spec/operawatir/fixtures/label_submit.html:
--------------------------------------------------------------------------------
1 | 
2 | 
3 | LABEL element tied to form submission
4 | 
5 | 
6 | -------------------------------------------------------------------------------- /spec/operawatir/fixtures/mouse.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Mouse fixture 6 | 7 | 8 | 9 |

Mouse test

10 |
11 | Test area 12 |
13 |

14 | 
15 | 
26 | 
27 | 
57 | 
58 | 
59 | 
60 | 


--------------------------------------------------------------------------------
/spec/operawatir/fixtures/onclick.html:
--------------------------------------------------------------------------------
 1 | 
 2 | 
 3 | onclick
 4 | 
 5 | 

6 | 7 |

8 | 9 |

10 | 11 | 21 | -------------------------------------------------------------------------------- /spec/operawatir/fixtures/paragraphs.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Paragraphs 4 | 5 |

6 | Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. 7 |

8 | 9 |

10 | Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. 11 |

12 | 13 |

14 | Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. 15 |

16 | -------------------------------------------------------------------------------- /spec/operawatir/fixtures/simple.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Simple Title 4 | 5 |

Simple Heading

6 | 7 |

8 | foo bar. baz. 9 |

10 | 11 | -------------------------------------------------------------------------------- /spec/operawatir/fixtures/two_input_fields.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Simple page with two input fields 4 | 5 |

6 |

7 | -------------------------------------------------------------------------------- /spec/operawatir/guards.rb: -------------------------------------------------------------------------------- 1 | module WatirSpec 2 | class Guard 3 | 4 | attr_accessor :type, :browsers, :data 5 | 6 | def initialize(type, browsers, data={}) 7 | self.type, self.browsers, self.data = type, browsers, data 8 | WatirSpec.guards << self 9 | end 10 | 11 | def guarded?(browser) 12 | WatirSpec.guarded? || browsers.include?(browser.name) 13 | end 14 | 15 | module Helpers 16 | def deviates_on(*browsers) 17 | guard = WatirSpec::Guard.new :deviation, browsers, :file => caller.first 18 | yield unless guard.guarded?(OperaWatir::Helper.browser) 19 | end 20 | 21 | def not_compliant_on(*browsers) 22 | guard = WatirSpec::Guard.new :non_compliance, browsers, :file => caller.first 23 | yield unless guard.guarded?(OperaWatir::Helper.browser) 24 | end 25 | 26 | def compliant_on(*browsers) 27 | guard = WatirSpec::Guard.new :compliance, browsers, :file => caller.first 28 | yield unless guard.guarded?(OperaWatir::Helper.browser) 29 | end 30 | 31 | def bug(url, *browsers) 32 | guard = WatirSpec::Guard.new :bug, browsers, :file => caller.first, :url => url 33 | yield unless guard.guarded?(OperaWatir::Helper.browser) 34 | end 35 | end 36 | 37 | end 38 | end 39 | 40 | -------------------------------------------------------------------------------- /spec/operawatir/matchers.rb: -------------------------------------------------------------------------------- 1 | RSpec::Matchers.define :close_window do 2 | match { |actual| actual > 0 } 3 | 4 | failure_message_for_should do |window_id| 5 | "expected close_window to close window, but window_id returned is not valid: #{window_id}" 6 | end 7 | end 8 | 9 | RSpec::Matchers.define :close_dialog do |expected| 10 | match { |window_id| window_id > 0 } 11 | 12 | failure_message_for_should do |window_id| 13 | "expected close_dialog to close dialog, but window_id returned is not valid: #{window_id}" 14 | end 15 | end 16 | 17 | RSpec::Matchers.define :close_menu do |expected| 18 | match { |name| name.length > 0 } 19 | end 20 | 21 | RSpec::Matchers.define :open_window do 22 | match { |actual| actual > 0 } 23 | 24 | failure_message_for_should do |window_id| 25 | "expected open_window to open window, but window_id returned is not valid: #{window_id}" 26 | end 27 | end 28 | 29 | RSpec::Matchers.define :open_dialog do 30 | match { |actual| actual > 0 } 31 | 32 | failure_message_for_should do |window_id| 33 | "expected open_dialog to close dialog, but window_id returned is not valid: #{window_id}" 34 | end 35 | end 36 | 37 | RSpec::Matchers.define :open_menu do |expected| 38 | # match { |actual| actual == expected } #menuname not accessible for mac, so leave this 39 | match { |name| name.length > 0 } 40 | 41 | #failure_message_for_should do |expected| 42 | # "expected open_menu to open menu, #{expected}" 43 | #end 44 | end 45 | 46 | 47 | RSpec::Matchers.define :load_window do 48 | match { |actual| actual > 0 } 49 | 50 | failure_message_for_should do |window_id| 51 | "expected load... to load in window, but window_id returned is not valid: #{window_id}" 52 | end 53 | end 54 | 55 | RSpec::Matchers.define :load_page do 56 | match { |actual| actual > 0 } 57 | 58 | failure_message_for_should do |window_id| 59 | "expected load_page to load page, but window_id returned is not valid: #{window_id}" 60 | end 61 | end 62 | 63 | =begin 64 | RSpec::Matchers.define :load do |expected| 65 | match do |actual| 66 | expected == actual 67 | end 68 | end 69 | =end -------------------------------------------------------------------------------- /spec/operawatir/server.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require 'sinatra/base' 3 | 4 | class WatirSpec::Server < ::Sinatra::Base 5 | 6 | set :app_file, __FILE__ 7 | set :root, File.dirname(__FILE__) 8 | set :public, lambda { File.join(root, 'fixtures')} 9 | set :static, true 10 | set :run, false 11 | set :environment, :production 12 | set :bind, 'localhost' 13 | set :port, 2000 14 | set :server, %w[thin mongrel webrick] 15 | 16 | get '/' do 17 | self.class.name 18 | end 19 | 20 | get '/big' do 21 | Class.new do 22 | def each(&blk) 23 | yield "Big Content" 24 | string = "hello "*205 25 | 300.times { yield string } 26 | yield "" 27 | end 28 | end.new 29 | end 30 | 31 | post '/post_to_me' do 32 | "You posted the following content:\n#{ env['rack.input'].read }" 33 | end 34 | 35 | get '/plain_text' do 36 | content_type 'text/plain' 37 | 'This is text/plain' 38 | end 39 | 40 | get '/ajax' do 41 | sleep 10 42 | "A slooow ajax response" 43 | end 44 | 45 | get '/charset_mismatch' do 46 | content_type 'text/html; charset=UTF-8' 47 | %{ 48 | 49 | 50 | 51 | 52 | 53 |

ø

54 | 55 | 56 | } 57 | end 58 | 59 | get '/octet_stream' do 60 | content_type 'application/octet-stream' 61 | 'This is application/octet-stream' 62 | end 63 | 64 | get '/set_cookie' do 65 | content_type 'text/plain' 66 | headers 'Set-Cookie' => "monster=/" 67 | 68 | "C is for cookie, it's good enough for me" 69 | end 70 | 71 | get '/header_echo' do 72 | content_type 'text/plain' 73 | env.inspect 74 | end 75 | 76 | get '/authentication' do 77 | auth = Rack::Auth::Basic::Request.new(env) 78 | 79 | unless auth.provided? && auth.credentials == %w[foo bar] 80 | headers 'WWW-Authenticate' => %(Basic realm="localhost") 81 | halt 401, 'Authorization Required' 82 | end 83 | 84 | "ok" 85 | end 86 | 87 | get '/encodable_' do 88 | 'page with characters in URI that need encoding' 89 | end 90 | 91 | end 92 | -------------------------------------------------------------------------------- /spec/operawatir/watirspec.rake: -------------------------------------------------------------------------------- 1 | begin 2 | require 'rspec' 3 | rescue LoadError 4 | begin 5 | require 'rubygems' 6 | require 'rspec' 7 | rescue LoadError 8 | puts <<-EOS 9 | To use rspec for testing you must install rspec gem: 10 | gem install rspec 11 | EOS 12 | exit(0) 13 | end 14 | end 15 | 16 | require 'rspec/core/rake_task' 17 | namespace :watirspec do 18 | desc "Run the specs under #{File.dirname(__FILE__)}" 19 | RSpec::Core::RakeTask.new(:run) do |t| 20 | t.pattern = "#{File.dirname(__FILE__)}/*_spec.rb" 21 | end 22 | end 23 | 24 | 25 | namespace :watirspec do 26 | def watirspec_config; "#{File.dirname(__FILE__)}/.git/config"; end 27 | 28 | # 29 | # stolen from rubinius 30 | # 31 | 32 | desc 'Switch to the committer url for watirspec' 33 | task :committer do 34 | system "git config --file #{watirspec_config} remote.origin.url git@github.com:jarib/watirspec.git" 35 | puts "\nYou're now accessing watirspec via the committer URL." 36 | end 37 | 38 | desc "Switch to the watirspec anonymous URL" 39 | task :anon do 40 | system "git config --file #{watirspec_config} remote.origin.url git://github.com/jarib/watirspec.git" 41 | puts "\nYou're now accessing watirspec via the anonymous URL." 42 | end 43 | end 44 | -------------------------------------------------------------------------------- /spec/operawatir/watirspec_desktophelper.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | $LOAD_PATH.unshift File.dirname(__FILE__) 3 | $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__) 4 | require 'rspec' 5 | 6 | require 'guards' 7 | require 'server' 8 | 9 | require 'operawatir/desktop_helper' 10 | 11 | OperaWatir.api = 2 12 | 13 | RSpec.configure do |config| 14 | config.mock_with :rr 15 | end 16 | 17 | module WatirSpec 18 | extend self 19 | 20 | attr_accessor :args, :guarded 21 | 22 | def host 23 | "http://#{Server.bind}:#{Server.port}" 24 | end 25 | alias_method :files, :host 26 | 27 | def guards 28 | @guards ||= [] 29 | end 30 | 31 | def guarded? 32 | !!@guarded 33 | end 34 | 35 | module Helpers 36 | def browser 37 | OperaWatir::DesktopHelper.browser 38 | end 39 | 40 | def window 41 | browser.active_window 42 | end 43 | 44 | def fixture(*paths) 45 | [WatirSpec.host, *paths].join('/') 46 | end 47 | end 48 | 49 | end 50 | 51 | include OperaWatir::DesktopExceptions 52 | 53 | include WatirSpec::Guard::Helpers 54 | 55 | RSpec.configure do |config| 56 | config.include WatirSpec::Helpers 57 | 58 | config.before(:suite) do 59 | Thread.new { WatirSpec::Server.run! } 60 | end 61 | end 62 | ##################################### 63 | -------------------------------------------------------------------------------- /spec/operawatir/watirspec_helper.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | $LOAD_PATH.unshift File.dirname(__FILE__) 3 | $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__) 4 | require 'rspec' 5 | 6 | require 'guards' 7 | require 'server' 8 | 9 | require 'operawatir/helper' 10 | 11 | OperaWatir.api = 2 12 | 13 | RSpec.configure do |config| 14 | config.mock_with :rr 15 | end 16 | 17 | module WatirSpec 18 | extend self 19 | 20 | attr_accessor :args, :guarded 21 | 22 | def host 23 | "http://#{Server.bind}:#{Server.port}" 24 | end 25 | alias_method :files, :host 26 | 27 | def guards 28 | @guards ||= [] 29 | end 30 | 31 | def guarded? 32 | !!@guarded 33 | end 34 | 35 | module Helpers 36 | def browser 37 | OperaWatir::Helper.browser 38 | end 39 | 40 | def window 41 | browser.active_window 42 | end 43 | 44 | def fixture(*paths) 45 | [WatirSpec.host, *paths].join('/') 46 | end 47 | end 48 | 49 | end 50 | 51 | include WatirSpec::Guard::Helpers 52 | 53 | RSpec.configure do |config| 54 | config.include WatirSpec::Helpers 55 | 56 | config.before(:suite) do 57 | Thread.new { WatirSpec::Server.run! } 58 | end 59 | end 60 | 61 | -------------------------------------------------------------------------------- /spec/watir2/areas_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require File.expand_path("../spec_helper", __FILE__) 3 | 4 | describe "Areas" do 5 | 6 | before :each do 7 | browser.goto(WatirSpec.files + "/images.html") 8 | end 9 | 10 | describe "#length" do 11 | it "returns the number of areas" do 12 | browser.areas.length.should == 3 13 | end 14 | end 15 | 16 | describe "#[]" do 17 | it "returns the area at the given index" do 18 | browser.areas[1].id.should == "NCE" 19 | end 20 | end 21 | 22 | describe "#each" do 23 | it "iterates through areas correctly" do 24 | count = 0 25 | 26 | browser.areas.each_with_index do |a, index| 27 | a.name.should == browser.area(:index, index+1).name 28 | a.id.should == browser.area(:index, index+1).id 29 | a.value.should == browser.area(:index, index+1).value 30 | 31 | count += 1 32 | end 33 | 34 | count.should > 0 35 | end 36 | end 37 | 38 | end 39 | -------------------------------------------------------------------------------- /spec/watir2/buttons_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require File.expand_path("../spec_helper", __FILE__) 3 | 4 | describe "Buttons" do 5 | 6 | before :each do 7 | browser.goto(WatirSpec.files + "/forms_with_input_elements.html") 8 | end 9 | 10 | describe "#length" do 11 | bug "WTR-349", :watir do 12 | it "returns the number of buttons" do 13 | browser.buttons.length.should == 8 14 | end 15 | end 16 | end 17 | 18 | describe "#[]" do 19 | it "returns the button at the given index" do 20 | browser.buttons[1].title.should == "Submit the form" 21 | end 22 | end 23 | 24 | describe "#first" do 25 | it "returns the first element in the collection" do 26 | browser.buttons.first.value.should == browser.buttons[1].value 27 | end 28 | end 29 | 30 | describe "#last" do 31 | bug "WTR-349", :watir do 32 | it "returns the last element in the collection" do 33 | browser.buttons.last.value.should == browser.buttons[0].value 34 | end 35 | end 36 | end 37 | 38 | describe "#each" do 39 | it "iterates through buttons correctly" do 40 | count = 0 41 | 42 | browser.buttons.each_with_index do |b, index| 43 | b.name.should == browser.button(:index, index+1).name 44 | b.id.should == browser.button(:index, index+1).id 45 | b.value.should == browser.button(:index, index+1).value 46 | 47 | count += 1 48 | end 49 | 50 | count.should > 0 51 | end 52 | end 53 | 54 | end 55 | -------------------------------------------------------------------------------- /spec/watir2/checkboxes_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require File.expand_path("../spec_helper", __FILE__) 3 | 4 | describe "CheckBoxes" do 5 | 6 | before :each do 7 | browser.goto(WatirSpec.files + "/forms_with_input_elements.html") 8 | end 9 | 10 | describe "#length" do 11 | it "returns the number of checkboxes" do 12 | browser.checkboxes.length.should == 7 13 | end 14 | end 15 | 16 | describe "#[]" do 17 | it "returns the checkbox at the given index" do 18 | browser.checkboxes[1].id.should == "new_user_interests_books" 19 | end 20 | end 21 | 22 | describe "#each" do 23 | it "iterates through checkboxes correctly" do 24 | count = 0 25 | 26 | browser.checkboxes.each_with_index do |c, index| 27 | c.name.should == browser.checkbox(:index, index+1).name 28 | c.id.should == browser.checkbox(:index, index+1).id 29 | c.value.should == browser.checkbox(:index, index+1).value 30 | 31 | count += 1 32 | end 33 | 34 | count.should > 0 35 | end 36 | end 37 | 38 | end 39 | -------------------------------------------------------------------------------- /spec/watir2/collections_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require File.expand_path("../spec_helper", __FILE__) 3 | 4 | describe "Collections" do 5 | 6 | before :each do 7 | browser.goto(WatirSpec.files + "/collections.html") 8 | end 9 | 10 | it "returns inner elements of parent element having different html tag" do 11 | browser.span(:id => "a_span").divs.size.should == 2 12 | end 13 | 14 | it "returns inner elements of parent element having same html tag" do 15 | browser.span(:id => "a_span").spans.size.should == 2 16 | end 17 | 18 | end 19 | -------------------------------------------------------------------------------- /spec/watir2/dds_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require File.expand_path("../spec_helper", __FILE__) 3 | 4 | describe "Dds" do 5 | 6 | before :each do 7 | browser.goto(WatirSpec.files + "/definition_lists.html") 8 | end 9 | 10 | describe "#length" do 11 | it "returns the number of dds" do 12 | browser.dds.length.should == 11 13 | end 14 | end 15 | 16 | describe "#[]" do 17 | it "returns the dd at the given index" do 18 | browser.dds[2].title.should == "education" 19 | end 20 | end 21 | 22 | describe "#each" do 23 | it "iterates through dds correctly" do 24 | count = 0 25 | 26 | browser.dds.each_with_index do |d, index| 27 | d.name.should == browser.dd(:index, index+1).name 28 | d.id.should == browser.dd(:index, index+1).id 29 | d.class_name.should == browser.dd(:index, index+1).class_name 30 | 31 | count += 1 32 | end 33 | 34 | count.should > 0 35 | end 36 | end 37 | 38 | end 39 | -------------------------------------------------------------------------------- /spec/watir2/dels_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require File.expand_path("../spec_helper", __FILE__) 3 | 4 | describe "Dels" do 5 | 6 | before :each do 7 | browser.goto(WatirSpec.files + "/non_control_elements.html") 8 | end 9 | 10 | describe "#length" do 11 | it "returns the number of dels" do 12 | browser.dels.length.should == 5 13 | end 14 | end 15 | 16 | describe "#[]" do 17 | it "returns the del at the given index" do 18 | browser.dels[1].id.should == "lead" 19 | end 20 | end 21 | 22 | describe "#each" do 23 | it "iterates through dels correctly" do 24 | count = 0 25 | 26 | browser.dels.each_with_index do |s, index| 27 | s.name.should == browser.del(:index, index+1).name 28 | s.id.should == browser.del(:index, index+1).id 29 | s.value.should == browser.del(:index, index+1).value 30 | 31 | count += 1 32 | end 33 | 34 | count.should > 0 35 | end 36 | end 37 | 38 | describe "#to_s" do 39 | bug "WTR-350", :watir do 40 | it "returns a human readable representation of the collection" do 41 | browser.dels.to_s.should == "tag: del\n" + 42 | " id: lead\n" + 43 | " class: lead\n" + 44 | " title: Lorem ipsum\n" + 45 | " text: This is a deleted text tag 1\n" + 46 | "tag: del\n" + 47 | " name: invalid_attribute\n" + 48 | " value: invalid_attribute\n" + 49 | " text: This is a deleted text tag 2\n" + 50 | "tag: del\n" + 51 | " text: This is a deleted text tag 3\n" + 52 | "tag: del\n" + 53 | "tag: del\n" + 54 | " class: footer\n" + 55 | " name: footer\n" + 56 | " onclick: this.innerHTML = 'This is a del with text set by Javascript.'\n" + 57 | " text: This is a del." 58 | end 59 | end 60 | end 61 | 62 | end 63 | -------------------------------------------------------------------------------- /spec/watir2/divs_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require File.expand_path("../spec_helper", __FILE__) 3 | 4 | describe "Divs" do 5 | 6 | before :each do 7 | browser.goto(WatirSpec.files + "/non_control_elements.html") 8 | end 9 | 10 | describe "#length" do 11 | it "returns the number of divs" do 12 | browser.divs.length.should == 12 13 | end 14 | end 15 | 16 | describe "#[]" do 17 | it "returns the div at the given index" do 18 | browser.divs[2].id.should == "outer_container" 19 | end 20 | end 21 | 22 | describe "#each" do 23 | it "iterates through divs correctly" do 24 | count = 0 25 | 26 | browser.divs.each_with_index do |d, index| 27 | d.name.should == browser.div(:index, index+1).name 28 | d.id.should == browser.div(:index, index+1).id 29 | d.class_name.should == browser.div(:index, index+1).class_name 30 | 31 | count += 1 32 | end 33 | 34 | count.should > 0 35 | end 36 | end 37 | 38 | end 39 | -------------------------------------------------------------------------------- /spec/watir2/dls_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require File.expand_path("../spec_helper", __FILE__) 3 | 4 | describe "Dls" do 5 | 6 | before :each do 7 | browser.goto(WatirSpec.files + "/definition_lists.html") 8 | end 9 | 10 | describe "#length" do 11 | it "returns the number of dls" do 12 | browser.dls.length.should == 3 13 | end 14 | end 15 | 16 | describe "#[]" do 17 | it "returns the dl at the given index" do 18 | browser.dls[1].id.should == "experience-list" 19 | end 20 | end 21 | 22 | describe "#each" do 23 | it "iterates through dls correctly" do 24 | count = 0 25 | 26 | browser.dls.each_with_index do |d, index| 27 | d.text.should == browser.dl(:index, index+1).text 28 | d.id.should == browser.dl(:index, index+1).id 29 | d.class_name.should == browser.dl(:index, index+1).class_name 30 | 31 | count += 1 32 | end 33 | 34 | count.should > 0 35 | end 36 | end 37 | 38 | end 39 | -------------------------------------------------------------------------------- /spec/watir2/dts_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require File.expand_path("../spec_helper", __FILE__) 3 | 4 | describe "Dts" do 5 | 6 | before :each do 7 | browser.goto(WatirSpec.files + "/definition_lists.html") 8 | end 9 | 10 | describe "#length" do 11 | it "returns the number of dts" do 12 | browser.dts.length.should == 11 13 | end 14 | end 15 | 16 | describe "#[]" do 17 | it "returns the dt at the given index" do 18 | browser.dts[1].id.should == "experience" 19 | end 20 | end 21 | 22 | describe "#each" do 23 | it "iterates through dts correctly" do 24 | count = 0 25 | 26 | browser.dts.each_with_index do |d, index| 27 | d.name.should == browser.dt(:index, index+1).name 28 | d.id.should == browser.dt(:index, index+1).id 29 | d.class_name.should == browser.dt(:index, index+1).class_name 30 | 31 | count += 1 32 | end 33 | 34 | count.should > 0 35 | end 36 | end 37 | 38 | end 39 | -------------------------------------------------------------------------------- /spec/watir2/ems_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require File.expand_path("../spec_helper", __FILE__) 3 | 4 | describe "Ems" do 5 | 6 | before :each do 7 | browser.goto(WatirSpec.files + "/non_control_elements.html") 8 | end 9 | 10 | describe "#length" do 11 | it "returns the number of ems" do 12 | browser.ems.length.should == 1 13 | end 14 | end 15 | 16 | describe "#[]" do 17 | it "returns the em at the given index" do 18 | browser.ems[1].id.should == "important-id" 19 | end 20 | end 21 | 22 | describe "#each" do 23 | it "iterates through ems correctly" do 24 | count = 0 25 | 26 | browser.ems.each_with_index do |e, index| 27 | e.text.should == browser.em(:index, index+1).text 28 | e.id.should == browser.em(:index, index+1).id 29 | e.class_name.should == browser.em(:index, index+1).class_name 30 | 31 | count += 1 32 | end 33 | 34 | count.should > 0 35 | end 36 | end 37 | 38 | end 39 | -------------------------------------------------------------------------------- /spec/watir2/filefields_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require File.expand_path("../spec_helper", __FILE__) 3 | 4 | describe "FileFields" do 5 | 6 | before :each do 7 | browser.goto(WatirSpec.files + "/forms_with_input_elements.html") 8 | end 9 | 10 | describe "#length" do 11 | it "returns the correct number of file fields" do 12 | browser.file_fields.length.should == 2 13 | end 14 | end 15 | 16 | describe "#[]" do 17 | it "returns the file field at the given index" do 18 | browser.file_fields[1].id.should == "new_user_portrait" 19 | end 20 | end 21 | 22 | describe "#each" do 23 | it "iterates through file fields correctly" do 24 | count = 0 25 | 26 | browser.file_fields.each_with_index do |f, index| 27 | f.name.should == browser.file_field(:index, index+1).name 28 | f.id.should == browser.file_field(:index, index+1).id 29 | f.value.should == browser.file_field(:index, index+1).value 30 | 31 | count += 1 32 | end 33 | 34 | count.should > 0 35 | end 36 | end 37 | 38 | end 39 | -------------------------------------------------------------------------------- /spec/watir2/fixtures/bug_duplicate_attributes.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Duplicate attributes 5 | 6 | 7 | 8 |
9 |
10 | 11 |
12 |
13 | 14 | -------------------------------------------------------------------------------- /spec/watir2/fixtures/bug_javascript_001.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | java.lang.StackOverflowError 5 | 6 | 7 | 10 | 11 | -------------------------------------------------------------------------------- /spec/watir2/fixtures/buttons_with_duplicate_ids.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Duplicate id buttons 5 | 6 | 7 | 8 |
9 |
10 | 11 |
12 | 13 |
14 |
15 | 16 |
17 | 18 | -------------------------------------------------------------------------------- /spec/watir2/fixtures/collections.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Collections 5 | 6 | 7 | 8 | 9 |
first_div
10 |
second_div
11 | first_span 12 | second_span 13 |
14 | 15 | -------------------------------------------------------------------------------- /spec/watir2/fixtures/definition_lists.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | definition_lists 5 | 6 | 7 | 8 |
9 |
Experience
10 |
11 years
11 | 12 |
Education
13 |
Master
14 | 15 |
Current industry
16 |
Architecture
17 | 18 |
Previous industry experience
19 |
Architecture
20 |
21 | 22 |
23 |
Name
24 |
John Doe
25 | 26 |
Address
27 |
John Doe
28 | 29 |
City
30 |
New York
31 | 32 |
Country
33 |
USA
34 | 35 |
Gender
36 |
Male
37 | 38 |
Age
39 |
35
40 |
41 | 42 |
43 |
44 |
45 |
46 | 47 | 48 | -------------------------------------------------------------------------------- /spec/watir2/fixtures/euc-jp_text.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/operasoftware/operawatir/0e9b9329512b1ca7863156a7bcff07bb9db05a27/spec/watir2/fixtures/euc-jp_text.html -------------------------------------------------------------------------------- /spec/watir2/fixtures/frame_1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Frame 1 5 | 6 | 7 | 8 |

Frame 1

9 |

Nam accumsan. Donec nisi pede, interdum eget, ultrices ac, vulputate vitae, nunc. Nulla lorem. Duis cursus pharetra dolor. Nulla accumsan hendrerit leo. Vivamus commodo. Nullam dignissim adipiscing est. Aliquam vitae orci in risus lobortis luctus. Ut luctus fermentum ligula. Nullam ipsum. Suspendisse sit amet nisi.

10 |
11 |
12 | 13 | 14 |
15 |
16 |
17 | 18 | -------------------------------------------------------------------------------- /spec/watir2/fixtures/frame_2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Frame 2 5 | 6 | 7 | 8 |

Frame 2

9 |

Vestibulum dignissim mauris id tellus. Nulla volutpat bibendum ante. Nam malesuada, lacus vel ultrices luctus, lorem purus tristique magna, quis pharetra leo ipsum nec neque. Cras ornare tincidunt sem. In hac habitasse platea dictumst. Suspendisse commodo turpis at est. Sed quis tortor. Aenean non massa. Phasellus scelerisque nulla vel lectus. Quisque lorem. Praesent volutpat dignissim risus. Fusce vulputate ligula eu ipsum.

10 |
11 |
12 | 13 |
14 |
15 | 16 | -------------------------------------------------------------------------------- /spec/watir2/fixtures/frames.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Frames 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /spec/watir2/fixtures/iframes.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Iframes 5 | 6 | 7 | 8 |

Iframes

9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /spec/watir2/fixtures/images.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Images 5 | 6 | 7 | 8 |
9 | 10 | 1 11 | 2 12 | 3 13 | circle 14 | square 15 | 16 | 17 | 1 18 | 19 | Non-control elements 20 | Tables 21 | 22 | 23 | 24 | 25 |
26 | 27 | -------------------------------------------------------------------------------- /spec/watir2/fixtures/images/1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/operasoftware/operawatir/0e9b9329512b1ca7863156a7bcff07bb9db05a27/spec/watir2/fixtures/images/1.gif -------------------------------------------------------------------------------- /spec/watir2/fixtures/images/2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/operasoftware/operawatir/0e9b9329512b1ca7863156a7bcff07bb9db05a27/spec/watir2/fixtures/images/2.gif -------------------------------------------------------------------------------- /spec/watir2/fixtures/images/3.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/operasoftware/operawatir/0e9b9329512b1ca7863156a7bcff07bb9db05a27/spec/watir2/fixtures/images/3.gif -------------------------------------------------------------------------------- /spec/watir2/fixtures/images/button.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/operasoftware/operawatir/0e9b9329512b1ca7863156a7bcff07bb9db05a27/spec/watir2/fixtures/images/button.jpg -------------------------------------------------------------------------------- /spec/watir2/fixtures/images/circle.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/operasoftware/operawatir/0e9b9329512b1ca7863156a7bcff07bb9db05a27/spec/watir2/fixtures/images/circle.jpg -------------------------------------------------------------------------------- /spec/watir2/fixtures/images/map.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/operasoftware/operawatir/0e9b9329512b1ca7863156a7bcff07bb9db05a27/spec/watir2/fixtures/images/map.gif -------------------------------------------------------------------------------- /spec/watir2/fixtures/images/map2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/operasoftware/operawatir/0e9b9329512b1ca7863156a7bcff07bb9db05a27/spec/watir2/fixtures/images/map2.gif -------------------------------------------------------------------------------- /spec/watir2/fixtures/images/minus.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/operasoftware/operawatir/0e9b9329512b1ca7863156a7bcff07bb9db05a27/spec/watir2/fixtures/images/minus.gif -------------------------------------------------------------------------------- /spec/watir2/fixtures/images/originaltriangle.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/operasoftware/operawatir/0e9b9329512b1ca7863156a7bcff07bb9db05a27/spec/watir2/fixtures/images/originaltriangle.jpg -------------------------------------------------------------------------------- /spec/watir2/fixtures/images/plus.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/operasoftware/operawatir/0e9b9329512b1ca7863156a7bcff07bb9db05a27/spec/watir2/fixtures/images/plus.gif -------------------------------------------------------------------------------- /spec/watir2/fixtures/images/square.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/operasoftware/operawatir/0e9b9329512b1ca7863156a7bcff07bb9db05a27/spec/watir2/fixtures/images/square.jpg -------------------------------------------------------------------------------- /spec/watir2/fixtures/images/triangle.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/operasoftware/operawatir/0e9b9329512b1ca7863156a7bcff07bb9db05a27/spec/watir2/fixtures/images/triangle.jpg -------------------------------------------------------------------------------- /spec/watir2/fixtures/iso-2022-jp_text.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | ISO-2022-JP 8 | 9 | 10 | 11 |

12 | $BK\F|$O@2E7$J$j!#(B 13 |

14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /spec/watir2/fixtures/javascript/helpers.js: -------------------------------------------------------------------------------- 1 | var WatirSpec = function() { 2 | 3 | return { 4 | addMessage: function(string) { 5 | var text = document.createTextNode(string) 6 | var message = document.createElement('div'); 7 | var messages = document.getElementById('messages'); 8 | 9 | message.appendChild(text) 10 | messages.appendChild(message); 11 | } 12 | }; 13 | 14 | 15 | }(); // WatirSpec 16 | 17 | -------------------------------------------------------------------------------- /spec/watir2/fixtures/jquery.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | jquery test 5 | 6 | 21 | 22 | 23 |
24 | 25 | add function 26 |
typeof update:
27 | 28 | -------------------------------------------------------------------------------- /spec/watir2/fixtures/latin1_text.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/operasoftware/operawatir/0e9b9329512b1ca7863156a7bcff07bb9db05a27/spec/watir2/fixtures/latin1_text.html -------------------------------------------------------------------------------- /spec/watir2/fixtures/multiple_ids.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | Multiple IDs 7 | 8 | 9 | 10 |
11 |
12 | 13 | 14 | -------------------------------------------------------------------------------- /spec/watir2/fixtures/parser_bug_001.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Title 5 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /spec/watir2/fixtures/prevent_form_submit.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | preventDefault() on form submission 5 | 6 | 14 | 15 | 16 |
17 |

18 |
19 | 20 | 21 | -------------------------------------------------------------------------------- /spec/watir2/fixtures/right_click.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Right Click Test 5 | 6 | 7 | 8 |
9 |
Right click!
10 | 11 | -------------------------------------------------------------------------------- /spec/watir2/fixtures/shift_jis_text.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/operasoftware/operawatir/0e9b9329512b1ca7863156a7bcff07bb9db05a27/spec/watir2/fixtures/shift_jis_text.html -------------------------------------------------------------------------------- /spec/watir2/fixtures/timeout.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Timeout Spec 5 | 11 | 12 | 13 |
Trigger alert
14 |
Trigger change
15 | 16 | -------------------------------------------------------------------------------- /spec/watir2/fixtures/timeout_window_location.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Timeout test 6 | 7 | 8 | 15 | 16 | 17 | Wait 3 seconds for the next page. 18 | 19 | 20 | -------------------------------------------------------------------------------- /spec/watir2/fixtures/tiny_mce.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 18 | 19 | 20 | 21 | 22 | Beskrivelse 23 | 24 | 25 |
26 | 27 | 28 | -------------------------------------------------------------------------------- /spec/watir2/fixtures/utf8_text.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | UTF-8 8 | 9 | 10 | 11 |

12 | æåø 13 |

14 | 15 | 16 | -------------------------------------------------------------------------------- /spec/watir2/fixtures/watirspec.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/operasoftware/operawatir/0e9b9329512b1ca7863156a7bcff07bb9db05a27/spec/watir2/fixtures/watirspec.css -------------------------------------------------------------------------------- /spec/watir2/form_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require File.expand_path("../spec_helper", __FILE__) 3 | 4 | describe "Form" do 5 | 6 | before :each do 7 | browser.goto(WatirSpec.files + "/forms_with_input_elements.html") 8 | end 9 | 10 | describe "#exists?" do 11 | it "returns true if the form exists" do 12 | browser.form(:id, 'new_user').should exist 13 | browser.form(:id, /new_user/).should exist 14 | 15 | bug "WTR-355", :watir do 16 | browser.form(:class, 'user').should exist 17 | browser.form(:class, /user/).should exist 18 | end 19 | 20 | browser.form(:method, 'post').should exist 21 | browser.form(:method, /post/).should exist 22 | browser.form(:action, 'post_to_me').should exist 23 | browser.form(:action, /to_me/).should exist 24 | browser.form(:index, 1).should exist 25 | browser.form(:xpath, "//form[@id='new_user']").should exist 26 | end 27 | 28 | it "returns the first form if given no args" do 29 | browser.form.should exist 30 | end 31 | 32 | it "returns true if the element exists (default how = :name)" do 33 | browser.form("user_new").should exist 34 | end 35 | 36 | it "returns false if the form doesn't exist" do 37 | browser.form(:id, 'no_such_id').should_not exist 38 | browser.form(:id, /no_such_id/).should_not exist 39 | 40 | bug "WTR-355", :watir do 41 | browser.form(:class, 'no_such_class').should_not exist 42 | browser.form(:class, /no_such_class/).should_not exist 43 | end 44 | 45 | browser.form(:method, 'no_such_method').should_not exist 46 | browser.form(:method, /no_such_method/).should_not exist 47 | browser.form(:action, 'no_such_action').should_not exist 48 | browser.form(:action, /no_such_action/).should_not exist 49 | browser.form(:index, 1337).should_not exist 50 | browser.form(:xpath, "//form[@id='no_such_id']").should_not exist 51 | end 52 | 53 | bug "WTR-356", :watir do 54 | it "raises TypeError when 'what' argument is invalid" do 55 | lambda { browser.form(:id, 3.14).exists? }.should raise_error(TypeError) 56 | end 57 | end 58 | 59 | it "raises MissingWayOfFindingObjectException when 'how' argument is invalid" do 60 | lambda { browser.form(:no_such_how, 'some_value').exists? }.should raise_error(MissingWayOfFindingObjectException) 61 | end 62 | end 63 | 64 | describe "#submit" do 65 | not_compliant_on :celerity do 66 | it "submits the form" do 67 | browser.form(:id, "delete_user").submit 68 | browser.text.should include("Semantic table") 69 | end 70 | end 71 | end 72 | 73 | end 74 | -------------------------------------------------------------------------------- /spec/watir2/forms_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require File.expand_path("../spec_helper", __FILE__) 3 | 4 | describe "Forms" do 5 | 6 | before :each do 7 | browser.goto(WatirSpec.files + "/forms_with_input_elements.html") 8 | end 9 | 10 | describe "#length" do 11 | it "returns the number of forms in the container" do 12 | browser.forms.length.should == 2 13 | end 14 | end 15 | 16 | describe "#[]n" do 17 | it "provides access to the nth form" do 18 | browser.forms[1].action.should == 'post_to_me' 19 | browser.forms[1].attribute_value('method').should == 'post' 20 | end 21 | end 22 | 23 | describe "#each" do 24 | it "iterates through forms correctly" do 25 | count = 0 26 | 27 | browser.forms.each_with_index do |f, index| 28 | f.name.should == browser.form(:index, index+1).name 29 | f.id.should == browser.form(:index, index+1).id 30 | f.class_name.should == browser.form(:index, index+1).class_name 31 | 32 | count += 1 33 | end 34 | 35 | count.should > 0 36 | end 37 | end 38 | 39 | end 40 | -------------------------------------------------------------------------------- /spec/watir2/frames_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require File.expand_path("../spec_helper", __FILE__) 3 | 4 | not_compliant_on :watir do 5 | describe " Frames" do 6 | 7 | before :each do 8 | browser.goto(WatirSpec.files + "/frames.html") 9 | end 10 | 11 | describe "#length" do 12 | it "returns the correct number of frames" do 13 | browser.frames.length.should == 2 14 | end 15 | end 16 | 17 | describe "#[]" do 18 | it "returns the frame at the given index" do 19 | browser.frames[1].id.should == "frame_1" 20 | end 21 | end 22 | 23 | describe "#each" do 24 | it "iterates through frames correctly" do 25 | count = 0 26 | 27 | browser.frames.each_with_index do |f, index| 28 | f.name.should == browser.frame(:index, index+1).name 29 | f.id.should == browser.frame(:index, index+1).id 30 | f.value.should == browser.frame(:index, index+1).value 31 | 32 | count += 1 33 | end 34 | 35 | count.should > 0 36 | end 37 | end 38 | end 39 | 40 | describe "