├── html ├── watirspec.css ├── nested_frame_1.html ├── images │ ├── 1.gif │ ├── 2.gif │ ├── 3.gif │ ├── map.gif │ ├── map2.gif │ ├── minus.gif │ ├── plus.gif │ ├── button.png │ ├── circle.png │ ├── square.png │ ├── triangle.png │ └── originaltriangle.png ├── inner_outer.html ├── class_locator.html ├── aria_attributes.html ├── data_attributes.html ├── font.html ├── hover.html ├── nested_frame_2.html ├── closeable.html ├── modal_dialog.html ├── nested_iframes.html ├── window_switching.html ├── nested_frames.html ├── nested_iframe_2.html ├── special_chars.html ├── multiple_ids.html ├── nested_frame_3.html ├── right_click.html ├── uneven_table.html ├── javascript │ └── helpers.js ├── keylogger.html ├── collections.html ├── alerts.html ├── frames.html ├── iframes.html ├── removed_element.html ├── clicks.html ├── timeout_window_location.html ├── frame_2.html ├── frame_1.html ├── iframe_1.html ├── definition_lists.html ├── images.html ├── wait.html ├── drag_and_drop.html └── tables.html ├── .gitignore ├── README.markdown ├── lib ├── silent_logger.rb ├── implementation.rb ├── guards.rb ├── runner.rb ├── watirspec.rb └── server.rb ├── elements_spec.rb ├── collections_spec.rb ├── spec_helper.rb ├── textarea_spec.rb ├── meta_spec.rb ├── font_spec.rb ├── textareas_spec.rb ├── ps_spec.rb ├── screenshot_spec.rb ├── dels_spec.rb ├── uls_spec.rb ├── inses_spec.rb ├── images_spec.rb ├── spans_spec.rb ├── ols_spec.rb ├── pres_spec.rb ├── labels_spec.rb ├── areas_spec.rb ├── maps_spec.rb ├── metas_spec.rb ├── LICENSE ├── lis_spec.rb ├── dds_spec.rb ├── frames_spec.rb ├── divs_spec.rb ├── dts_spec.rb ├── tables_spec.rb ├── strongs_spec.rb ├── dls_spec.rb ├── hns_spec.rb ├── ems_spec.rb ├── links_spec.rb ├── radios_spec.rb ├── hiddens_spec.rb ├── watirspec.rake ├── filefields_spec.rb ├── checkboxes_spec.rb ├── forms_spec.rb ├── iframes_spec.rb ├── text_fields_spec.rb ├── select_lists_spec.rb ├── buttons_spec.rb ├── tds_spec.rb ├── tbodys_spec.rb ├── drag_and_drop_spec.rb ├── trs_spec.rb ├── table_nesting_spec.rb ├── element_hidden_spec.rb ├── tfoots_spec.rb ├── theads_spec.rb ├── td_spec.rb ├── form_spec.rb ├── tr_spec.rb ├── area_spec.rb ├── label_spec.rb ├── ul_spec.rb ├── map_spec.rb ├── alert_spec.rb ├── ol_spec.rb ├── hn_spec.rb ├── strong_spec.rb ├── tfoot_spec.rb ├── thead_spec.rb ├── tbody_spec.rb ├── hidden_spec.rb ├── em_spec.rb ├── li_spec.rb ├── p_spec.rb ├── cookies_spec.rb ├── pre_spec.rb ├── del_spec.rb ├── ins_spec.rb ├── dd_spec.rb ├── frame_spec.rb ├── dt_spec.rb └── span_spec.rb /html/watirspec.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.rbc 2 | .idea -------------------------------------------------------------------------------- /html/nested_frame_1.html: -------------------------------------------------------------------------------- 1 | frame 1 -------------------------------------------------------------------------------- /html/images/1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/watir/watirspec/HEAD/html/images/1.gif -------------------------------------------------------------------------------- /html/images/2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/watir/watirspec/HEAD/html/images/2.gif -------------------------------------------------------------------------------- /html/images/3.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/watir/watirspec/HEAD/html/images/3.gif -------------------------------------------------------------------------------- /html/images/map.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/watir/watirspec/HEAD/html/images/map.gif -------------------------------------------------------------------------------- /html/images/map2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/watir/watirspec/HEAD/html/images/map2.gif -------------------------------------------------------------------------------- /html/images/minus.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/watir/watirspec/HEAD/html/images/minus.gif -------------------------------------------------------------------------------- /html/images/plus.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/watir/watirspec/HEAD/html/images/plus.gif -------------------------------------------------------------------------------- /html/images/button.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/watir/watirspec/HEAD/html/images/button.png -------------------------------------------------------------------------------- /html/images/circle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/watir/watirspec/HEAD/html/images/circle.png -------------------------------------------------------------------------------- /html/images/square.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/watir/watirspec/HEAD/html/images/square.png -------------------------------------------------------------------------------- /html/images/triangle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/watir/watirspec/HEAD/html/images/triangle.png -------------------------------------------------------------------------------- /html/images/originaltriangle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/watir/watirspec/HEAD/html/images/originaltriangle.png -------------------------------------------------------------------------------- /html/inner_outer.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
hello
4 | 5 | -------------------------------------------------------------------------------- /html/class_locator.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
a
5 |
a b
6 |
abc
7 | 8 | -------------------------------------------------------------------------------- /html/aria_attributes.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | aria-* attributes 5 | 6 | 7 |

watir

8 | 9 | 10 | -------------------------------------------------------------------------------- /html/data_attributes.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | data-* attributes 5 | 6 | 7 |

watir

8 | 9 | 10 | -------------------------------------------------------------------------------- /html/font.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | The font element 4 | 5 | 6 | 7 | Ouch 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /README.markdown: -------------------------------------------------------------------------------- 1 | ### WatirSpec is now part of [Watir](https://github.com/watir/watir). Please refer to its [README](https://github.com/watir/watir#watirspec) on how to use it. 2 | 3 | ### This repository is no longer maintained. 4 | -------------------------------------------------------------------------------- /html/hover.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | 10 | hello 11 | 12 | -------------------------------------------------------------------------------- /html/nested_frame_2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /html/closeable.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | closeable window 5 | 6 | 7 | 8 |

9 | Click here to close this window. 10 |

11 | 12 | 13 | -------------------------------------------------------------------------------- /html/modal_dialog.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Modal Dialog Launcher 4 | 5 | 6 |

Modal Dialog Launcher

7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /lib/silent_logger.rb: -------------------------------------------------------------------------------- 1 | require "logger" 2 | 3 | module WatirSpec 4 | class SilentLogger 5 | (::Logger.instance_methods - Object.instance_methods).each do |logger_instance_method| 6 | define_method(logger_instance_method) { |*args| } 7 | end 8 | end 9 | end 10 | 11 | -------------------------------------------------------------------------------- /html/nested_iframes.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 |

Top Layer

7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /html/window_switching.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | window switching 5 | 6 | 7 | 8 |

9 | Click here to open a new window. 10 |

11 | 12 | -------------------------------------------------------------------------------- /html/nested_frames.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /html/nested_iframe_2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |

Nested Frame

8 |

9 | 10 |

11 | 12 | 13 | -------------------------------------------------------------------------------- /html/special_chars.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Special Chars 6 | 7 | 8 | 9 |
single 'quotes'
10 |
double "quotes"
11 | 12 | -------------------------------------------------------------------------------- /html/multiple_ids.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | Multiple IDs 7 | 8 | 9 | 10 |
11 |
12 | 13 | 14 | -------------------------------------------------------------------------------- /html/nested_frame_3.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Title 7 | 8 | 9 | 10 |

11 | this link should consume the page 12 |

13 | 14 | 15 | -------------------------------------------------------------------------------- /html/right_click.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Right Click Test 5 | 6 | 7 | 8 |
9 |
Right click!
10 | 11 | -------------------------------------------------------------------------------- /html/uneven_table.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Uneven Table 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
Header 1Header 2Header 3
Data 1Data 2
19 | 20 | 21 | -------------------------------------------------------------------------------- /html/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 | -------------------------------------------------------------------------------- /elements_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require File.expand_path("../spec_helper", __FILE__) 3 | 4 | describe "Elements" do 5 | before :each do 6 | browser.goto(WatirSpec.url_for("forms_with_input_elements.html")) 7 | end 8 | 9 | describe "#[]" do 10 | context "when elements do not exist" do 11 | it "returns not existing element" do 12 | expect(browser.elements(id: "non-existing")[0]).not_to exist 13 | end 14 | end 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /html/keylogger.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Keylogger 5 | 10 | 11 | 12 | 13 |
14 | 15 | -------------------------------------------------------------------------------- /html/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 | -------------------------------------------------------------------------------- /html/alerts.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Alerts 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /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.url_for("collections.html")) 8 | end 9 | 10 | it "returns inner elements of parent element having different html tag" do 11 | expect(browser.span(id: "a_span").divs.size).to eq 2 12 | end 13 | 14 | it "returns inner elements of parent element having same html tag" do 15 | expect(browser.span(id: "a_span").spans.size).to eq 2 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /html/frames.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Frames 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /html/iframes.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Iframes 5 | 6 | 7 | 8 |

Iframes

9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /html/removed_element.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | obsolete element 5 | 11 | 12 | 13 | 14 | 15 |
Text
16 | 17 |
Top Element> 18 |
Middle Element> 19 |
Bottom Element
20 |
21 |
22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /html/clicks.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 12 | 13 |
click me
14 |
15 |
16 |
Can You Click This?
17 |
18 | 19 | 20 | -------------------------------------------------------------------------------- /spec_helper.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | begin 3 | require "rubygems" 4 | rescue LoadError 5 | end 6 | 7 | require "tmpdir" 8 | require "sinatra/base" 9 | require "#{File.dirname(__FILE__)}/lib/watirspec" 10 | require "#{File.dirname(__FILE__)}/lib/implementation" 11 | require "#{File.dirname(__FILE__)}/lib/server" 12 | require "#{File.dirname(__FILE__)}/lib/runner" 13 | require "#{File.dirname(__FILE__)}/lib/guards" 14 | require "#{File.dirname(__FILE__)}/lib/silent_logger" 15 | 16 | if __FILE__ == $0 17 | # this is needed in order to have a stable Server on Windows + MRI 18 | WatirSpec::Server.run! 19 | else 20 | WatirSpec::Runner.execute_if_necessary 21 | end 22 | 23 | -------------------------------------------------------------------------------- /html/timeout_window_location.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Timeout test 6 | 7 | 8 | 15 | 16 | 17 | Wait 500ms for the next page. 18 | 19 | 20 | -------------------------------------------------------------------------------- /textarea_spec.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path("../spec_helper", __FILE__) 2 | 3 | describe "TextArea" do 4 | before :each do 5 | browser.goto WatirSpec.url_for('forms_with_input_elements.html') 6 | end 7 | 8 | let(:textarea) { browser.textarea } 9 | 10 | it 'can set a value' do 11 | textarea.set 'foo' 12 | expect(textarea.value).to eq 'foo' 13 | end 14 | 15 | it 'can clear a value' do 16 | textarea.set 'foo' 17 | textarea.clear 18 | expect(textarea.value).to eq '' 19 | end 20 | 21 | it 'locates textarea by value' do 22 | browser.textarea.set 'foo' 23 | expect(browser.textarea(value: /foo/)).to exist 24 | expect(browser.textarea(value: 'foo')).to exist 25 | end 26 | end 27 | -------------------------------------------------------------------------------- /meta_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require File.expand_path("../spec_helper", __FILE__) 3 | 4 | describe "Meta" do 5 | before :each do 6 | browser.goto(WatirSpec.url_for("forms_with_input_elements.html")) 7 | end 8 | 9 | describe "#exist?" do 10 | it "returns true if the meta tag exists" do 11 | expect(browser.meta(http_equiv: "Content-Type")).to exist 12 | end 13 | 14 | it "returns the first meta if given no args" do 15 | expect(browser.meta).to exist 16 | end 17 | end 18 | 19 | describe "content" do 20 | it "returns the content attribute of the tag" do 21 | expect(browser.meta(http_equiv: "Content-Type").content).to eq "text/html; charset=utf-8" 22 | end 23 | end 24 | end 25 | -------------------------------------------------------------------------------- /font_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require File.expand_path("../spec_helper", __FILE__) 3 | 4 | describe "Font" do 5 | 6 | before :each do 7 | browser.goto(WatirSpec.url_for("font.html")) 8 | end 9 | 10 | it "finds the font element" do 11 | expect(browser.font(index: 0)).to exist 12 | end 13 | 14 | it "knows about the color attribute" do 15 | expect(browser.font(index: 0).color).to eq "#ff00ff" 16 | end 17 | 18 | it "knows about the face attribute" do 19 | expect(browser.font(index: 0).face).to eq "Helvetica" 20 | end 21 | 22 | it "knows about the size attribute" do 23 | expect(browser.font(index: 0).size).to eq "12" 24 | end 25 | 26 | it "finds all font elements" do 27 | expect(browser.fonts.size).to eq 1 28 | end 29 | 30 | end 31 | -------------------------------------------------------------------------------- /textareas_spec.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path("../spec_helper", __FILE__) 2 | 3 | describe 'TextArea' do 4 | before :each do 5 | browser.goto WatirSpec.url_for('forms_with_input_elements.html') 6 | end 7 | 8 | context 'when locating by :value' do 9 | before(:each) do 10 | browser.textarea(index: 0).set 'foo1' 11 | browser.textarea(index: 1).set 'foo2' 12 | end 13 | 14 | it 'finds textareas by string' do 15 | expect(browser.textareas(value: 'foo1').map(&:id)).to eq [browser.textarea(index: 0).id] 16 | expect(browser.textareas(value: 'foo2').map(&:id)).to eq [browser.textarea(index: 1).id] 17 | end 18 | 19 | it 'finds textareas by regexp' do 20 | expect(browser.textareas(value: /foo/)[0].id).to eq browser.textarea(index: 0).id 21 | expect(browser.textareas(value: /foo/)[1].id).to eq browser.textarea(index: 1).id 22 | end 23 | end 24 | end 25 | -------------------------------------------------------------------------------- /ps_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require File.expand_path("../spec_helper", __FILE__) 3 | 4 | describe "Ps" do 5 | 6 | before :each do 7 | browser.goto(WatirSpec.url_for("non_control_elements.html")) 8 | end 9 | 10 | describe "with selectors" do 11 | it "returns the matching elements" do 12 | expect(browser.ps(class: "lead").to_a).to eq [browser.p(class: "lead")] 13 | end 14 | end 15 | 16 | describe "#length" do 17 | it "returns the number of ps" do 18 | expect(browser.ps.length).to eq 5 19 | end 20 | end 21 | 22 | describe "#[]" do 23 | it "returns the p at the given index" do 24 | expect(browser.ps[0].id).to eq "lead" 25 | end 26 | end 27 | 28 | describe "#each" do 29 | it "iterates through ps correctly" do 30 | count = 0 31 | 32 | browser.ps.each_with_index do |p, index| 33 | expect(p.id).to eq browser.p(index: index).id 34 | count += 1 35 | end 36 | 37 | expect(count).to be > 0 38 | end 39 | end 40 | 41 | end 42 | -------------------------------------------------------------------------------- /screenshot_spec.rb: -------------------------------------------------------------------------------- 1 | require "base64" 2 | require File.expand_path("../spec_helper", __FILE__) 3 | 4 | describe "Watir::Screenshot" do 5 | let(:png_header) do 6 | str = "\211PNG" 7 | str.force_encoding('BINARY') if str.respond_to?(:force_encoding) 8 | 9 | str 10 | end 11 | 12 | describe '#png' do 13 | it 'gets png representation of screenshot' do 14 | expect(browser.screenshot.png[0..3]).to eq png_header 15 | end 16 | end 17 | 18 | describe '#base64' do 19 | it 'gets base64 representation of screenshot' do 20 | image = browser.screenshot.base64 21 | expect(Base64.decode64(image)[0..3]).to eq png_header 22 | end 23 | end 24 | 25 | describe '#save' do 26 | it 'saves screenshot to given file' do 27 | path = "#{Dir.tmpdir}/test#{Time.now.to_i}.png" 28 | expect(File).to_not exist(path) 29 | browser.screenshot.save(path) 30 | expect(File).to exist(path) 31 | expect(File.open(path, "rb") {|io| io.read}[0..3]).to eq png_header 32 | end 33 | end 34 | end 35 | -------------------------------------------------------------------------------- /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.url_for("non_control_elements.html")) 8 | end 9 | 10 | describe "with selectors" do 11 | it "returns the matching elements" do 12 | expect(browser.dels(class: "lead").to_a).to eq [browser.del(class: "lead")] 13 | end 14 | end 15 | 16 | describe "#length" do 17 | it "returns the number of dels" do 18 | expect(browser.dels.length).to eq 5 19 | end 20 | end 21 | 22 | describe "#[]" do 23 | it "returns the del at the given index" do 24 | expect(browser.dels[0].id).to eq "lead" 25 | end 26 | end 27 | 28 | describe "#each" do 29 | it "iterates through dels correctly" do 30 | count = 0 31 | 32 | browser.dels.each_with_index do |s, index| 33 | expect(s.id).to eq browser.del(index: index).id 34 | count += 1 35 | end 36 | 37 | expect(count).to be > 0 38 | end 39 | end 40 | 41 | end 42 | -------------------------------------------------------------------------------- /uls_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require File.expand_path("../spec_helper", __FILE__) 3 | 4 | describe "Uls" do 5 | 6 | before :each do 7 | browser.goto(WatirSpec.url_for("non_control_elements.html")) 8 | end 9 | 10 | describe "with selectors" do 11 | it "returns the matching elements" do 12 | expect(browser.uls(class: "navigation").to_a).to eq [browser.ul(class: "navigation")] 13 | end 14 | end 15 | 16 | describe "#length" do 17 | it "returns the number of uls" do 18 | expect(browser.uls.length).to eq 2 19 | end 20 | end 21 | 22 | describe "#[]" do 23 | it "returns the ul at the given index" do 24 | expect(browser.uls[0].id).to eq "navbar" 25 | end 26 | end 27 | 28 | describe "#each" do 29 | it "iterates through uls correctly" do 30 | count = 0 31 | 32 | browser.uls.each_with_index do |ul, index| 33 | expect(ul.id).to eq browser.ul(index: index).id 34 | count += 1 35 | end 36 | 37 | expect(count).to be > 0 38 | end 39 | end 40 | end 41 | -------------------------------------------------------------------------------- /inses_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require File.expand_path("../spec_helper", __FILE__) 3 | 4 | describe "Inses" do 5 | 6 | before :each do 7 | browser.goto(WatirSpec.url_for("non_control_elements.html")) 8 | end 9 | 10 | describe "with selectors" do 11 | it "returns the matching elements" do 12 | expect(browser.inses(class: "lead").to_a).to eq [browser.ins(class: "lead")] 13 | end 14 | end 15 | 16 | describe "#length" do 17 | it "returns the number of inses" do 18 | expect(browser.inses.length).to eq 5 19 | end 20 | end 21 | 22 | describe "#[]" do 23 | it "returns the ins at the given index" do 24 | expect(browser.inses[0].id).to eq "lead" 25 | end 26 | end 27 | 28 | describe "#each" do 29 | it "iterates through inses correctly" do 30 | count = 0 31 | 32 | browser.inses.each_with_index do |s, index| 33 | expect(s.id).to eq browser.ins(index: index).id 34 | count += 1 35 | end 36 | 37 | expect(count).to be > 0 38 | end 39 | end 40 | 41 | end 42 | -------------------------------------------------------------------------------- /images_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require File.expand_path("../spec_helper", __FILE__) 3 | 4 | describe "Images" do 5 | 6 | before :each do 7 | browser.goto(WatirSpec.url_for("images.html")) 8 | end 9 | 10 | describe "with selectors" do 11 | it "returns the matching elements" do 12 | expect(browser.images(alt: "circle").to_a).to eq [browser.image(alt: "circle")] 13 | end 14 | end 15 | 16 | describe "#length" do 17 | it "returns the number of images" do 18 | expect(browser.images.length).to eq 10 19 | end 20 | end 21 | 22 | describe "#[]" do 23 | it "returns the image at the given index" do 24 | expect(browser.images[5].id).to eq "square" 25 | end 26 | end 27 | 28 | describe "#each" do 29 | it "iterates through images correctly" do 30 | count = 0 31 | 32 | browser.images.each_with_index do |c, index| 33 | expect(c.id).to eq browser.image(index: index).id 34 | count += 1 35 | end 36 | 37 | expect(count).to be > 0 38 | end 39 | end 40 | 41 | end 42 | -------------------------------------------------------------------------------- /spans_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require File.expand_path("../spec_helper", __FILE__) 3 | 4 | describe "Spans" do 5 | 6 | before :each do 7 | browser.goto(WatirSpec.url_for("non_control_elements.html")) 8 | end 9 | 10 | describe "with selectors" do 11 | it "returns the matching elements" do 12 | expect(browser.spans(class: "footer").to_a).to eq [browser.span(class: "footer")] 13 | end 14 | end 15 | 16 | describe "#length" do 17 | it "returns the number of spans" do 18 | expect(browser.spans.length).to eq 6 19 | end 20 | end 21 | 22 | describe "#[]" do 23 | it "returns the p at the given index" do 24 | expect(browser.spans[0].id).to eq "lead" 25 | end 26 | end 27 | 28 | describe "#each" do 29 | it "iterates through spans correctly" do 30 | count = 0 31 | 32 | browser.spans.each_with_index do |s, index| 33 | expect(s.id).to eq browser.span(index: index).id 34 | count += 1 35 | end 36 | 37 | expect(count).to be > 0 38 | end 39 | end 40 | 41 | end 42 | -------------------------------------------------------------------------------- /html/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 | -------------------------------------------------------------------------------- /ols_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require File.expand_path("../spec_helper", __FILE__) 3 | 4 | describe "Ols" do 5 | 6 | before :each do 7 | browser.goto(WatirSpec.url_for("non_control_elements.html")) 8 | end 9 | 10 | describe "with selectors" do 11 | it "returns the matching elements" do 12 | expect(browser.ols(class: "chemistry").to_a).to eq [browser.ol(class: "chemistry")] 13 | end 14 | end 15 | 16 | describe "#length" do 17 | it "returns the number of ols" do 18 | expect(browser.ols.length).to eq 2 19 | end 20 | end 21 | 22 | describe "#[]" do 23 | it "returns the ol at the given index" do 24 | expect(browser.ols[0].id).to eq "favorite_compounds" 25 | end 26 | end 27 | 28 | describe "#each" do 29 | it "iterates through ols correctly" do 30 | count = 0 31 | 32 | browser.ols.each_with_index do |ol, index| 33 | expect(ol.id).to eq browser.ol(index: index).id 34 | count += 1 35 | end 36 | 37 | expect(count).to be > 0 38 | end 39 | end 40 | 41 | end 42 | -------------------------------------------------------------------------------- /pres_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require File.expand_path("../spec_helper", __FILE__) 3 | 4 | describe "Pres" do 5 | 6 | before :each do 7 | browser.goto(WatirSpec.url_for("non_control_elements.html")) 8 | end 9 | 10 | describe "with selectors" do 11 | it "returns the matching elements" do 12 | expect(browser.pres(class: "c-plus-plus").to_a).to eq [browser.pre(class: "c-plus-plus")] 13 | end 14 | end 15 | 16 | describe "#length" do 17 | it "returns the number of pres" do 18 | expect(browser.pres.length).to eq 7 19 | end 20 | end 21 | 22 | describe "#[]" do 23 | it "returns the pre at the given index" do 24 | expect(browser.pres[1].id).to eq "rspec" 25 | end 26 | end 27 | 28 | describe "#each" do 29 | it "iterates through pres correctly" do 30 | count = 0 31 | 32 | browser.pres.each_with_index do |p, index| 33 | expect(p.id).to eq browser.pre(index: index).id 34 | count += 1 35 | end 36 | 37 | expect(count).to be > 0 38 | end 39 | end 40 | 41 | end 42 | -------------------------------------------------------------------------------- /labels_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require File.expand_path("../spec_helper", __FILE__) 3 | 4 | describe "Labels" do 5 | 6 | before :each do 7 | browser.goto(WatirSpec.url_for("forms_with_input_elements.html")) 8 | end 9 | 10 | describe "with selectors" do 11 | it "returns the matching elements" do 12 | expect(browser.labels(for: "new_user_first_name").to_a).to eq [browser.label(for: "new_user_first_name")] 13 | end 14 | end 15 | 16 | describe "#length" do 17 | it "returns the number of labels" do 18 | expect(browser.labels.length).to eq 38 19 | end 20 | end 21 | 22 | describe "#[]" do 23 | it "returns the label at the given index" do 24 | expect(browser.labels[0].id).to eq "first_label" 25 | end 26 | end 27 | 28 | describe "#each" do 29 | it "iterates through labels correctly" do 30 | count = 0 31 | 32 | browser.labels.each_with_index do |l, index| 33 | expect(l.id).to eq browser.label(index: index).id 34 | count += 1 35 | end 36 | 37 | expect(count).to be > 0 38 | end 39 | end 40 | 41 | end 42 | -------------------------------------------------------------------------------- /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.url_for("images.html")) 8 | end 9 | 10 | describe "with selectors" do 11 | it "returns the matching elements" do 12 | expect(browser.areas(alt: "Tables").to_a).to eq [browser.area(alt: "Tables")] 13 | end 14 | end 15 | 16 | describe "#length" do 17 | it "returns the number of areas" do 18 | expect(browser.areas.length).to eq 3 19 | end 20 | end 21 | 22 | describe "#[]" do 23 | it "returns the area at the given index" do 24 | expect(browser.areas[0].id).to eq("NCE") 25 | end 26 | end 27 | 28 | describe "#each" do 29 | it "iterates through areas correctly" do 30 | count = 0 31 | 32 | browser.areas.each_with_index do |a, index| 33 | expect(a.id).to eq browser.area(index: index).id 34 | expect(a.title).to eq browser.area(index: index).title 35 | 36 | count += 1 37 | end 38 | 39 | expect(count).to be > 0 40 | end 41 | end 42 | 43 | end 44 | -------------------------------------------------------------------------------- /maps_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require File.expand_path("../spec_helper", __FILE__) 3 | 4 | describe "Maps" do 5 | 6 | before :each do 7 | browser.goto(WatirSpec.url_for("images.html")) 8 | end 9 | 10 | describe "with selectors" do 11 | it "returns the matching elements" do 12 | expect(browser.maps(name: "triangle_map").to_a).to eq [browser.map(name: "triangle_map")] 13 | end 14 | end 15 | 16 | describe "#length" do 17 | it "returns the number of maps" do 18 | expect(browser.maps.length).to eq 2 19 | end 20 | end 21 | 22 | describe "#[]" do 23 | it "returns the p at the given index" do 24 | expect(browser.maps[0].id).to eq "triangle_map" 25 | end 26 | end 27 | 28 | describe "#each" do 29 | it "iterates through maps correctly" do 30 | count = 0 31 | 32 | browser.maps.each_with_index do |m, index| 33 | expect(m.name).to eq browser.map(index: index).name 34 | expect(m.id).to eq browser.map(index: index).id 35 | count += 1 36 | end 37 | 38 | expect(count).to be > 0 39 | end 40 | end 41 | 42 | end 43 | -------------------------------------------------------------------------------- /metas_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require File.expand_path("../spec_helper", __FILE__) 3 | 4 | describe "Metas" do 5 | 6 | before :each do 7 | browser.goto(WatirSpec.url_for("forms_with_input_elements.html")) 8 | end 9 | 10 | describe "with selectors" do 11 | it "returns the matching elements" do 12 | expect(browser.metas(name: "description").to_a).to eq [browser.meta(name: "description")] 13 | end 14 | end 15 | 16 | describe "#length" do 17 | it "returns the number of meta elements" do 18 | expect(browser.metas.length).to eq 2 19 | end 20 | end 21 | 22 | describe "#[]" do 23 | it "returns the meta element at the given index" do 24 | expect(browser.metas[1].name).to eq "description" 25 | end 26 | end 27 | 28 | describe "#each" do 29 | it "iterates through meta elements correctly" do 30 | count = 0 31 | 32 | browser.metas.each_with_index do |m, index| 33 | expect(m.content).to eq browser.meta(index: index).content 34 | count += 1 35 | end 36 | 37 | expect(count).to be > 0 38 | end 39 | end 40 | 41 | end 42 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009-2014 FINN.no AS 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /lis_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require File.expand_path("../spec_helper", __FILE__) 3 | 4 | describe "Lis" do 5 | 6 | before :each do 7 | browser.goto(WatirSpec.url_for("non_control_elements.html")) 8 | end 9 | 10 | describe "with selectors" do 11 | it "returns the matching elements" do 12 | expect(browser.lis(class: "nonlink").to_a).to eq [browser.li(class: "nonlink")] 13 | end 14 | end 15 | 16 | describe "#length" do 17 | it "returns the number of lis" do 18 | expect(browser.lis.length).to eq 18 19 | end 20 | end 21 | 22 | describe "#[]" do 23 | it "returns the li at the given index" do 24 | expect(browser.lis[4].id).to eq "non_link_1" 25 | end 26 | end 27 | 28 | describe "#each" do 29 | it "iterates through lis correctly" do 30 | count = 0 31 | 32 | browser.lis.each_with_index do |l, index| 33 | expect(l.id).to eq browser.li(index: index).id 34 | expect(l.value).to eq browser.li(index: index).value 35 | 36 | count += 1 37 | end 38 | 39 | expect(count).to be > 0 40 | end 41 | end 42 | 43 | end 44 | -------------------------------------------------------------------------------- /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.url_for("definition_lists.html")) 8 | end 9 | 10 | describe "with selectors" do 11 | it "returns the matching elements" do 12 | expect(browser.dds(text: "11 years").to_a).to eq [browser.dd(text: "11 years")] 13 | end 14 | end 15 | 16 | describe "#length" do 17 | it "returns the number of dds" do 18 | expect(browser.dds.length).to eq 11 19 | end 20 | end 21 | 22 | describe "#[]" do 23 | it "returns the dd at the given index" do 24 | expect(browser.dds[1].title).to eq "education" 25 | end 26 | end 27 | 28 | describe "#each" do 29 | it "iterates through dds correctly" do 30 | count = 0 31 | 32 | browser.dds.each_with_index do |d, index| 33 | expect(d.id).to eq browser.dd(index: index).id 34 | expect(d.class_name).to eq browser.dd(index: index).class_name 35 | 36 | count += 1 37 | end 38 | 39 | expect(count).to be > 0 40 | end 41 | end 42 | 43 | end 44 | -------------------------------------------------------------------------------- /frames_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require File.expand_path("../spec_helper", __FILE__) 3 | 4 | describe "Frames" do 5 | 6 | before :each do 7 | browser.goto(WatirSpec.url_for("frames.html")) 8 | end 9 | 10 | describe "with selectors" do 11 | it "returns the matching elements" do 12 | expect(browser.frames(name: "frame2").to_a).to eq [browser.frame(name: "frame2")] 13 | end 14 | end 15 | 16 | describe "#length" do 17 | it "returns the correct number of frames" do 18 | expect(browser.frames.length).to eq 2 19 | end 20 | end 21 | 22 | describe "#[]" do 23 | it "returns the frame at the given index" do 24 | expect(browser.frames[0].id).to eq "frame_1" 25 | end 26 | end 27 | 28 | describe "#each" do 29 | it "iterates through frames correctly" do 30 | count = 0 31 | 32 | browser.frames.each_with_index do |f, index| 33 | expect(f.name).to eq browser.frame(index: index).name 34 | expect(f.id).to eq browser.frame(index: index).id 35 | count += 1 36 | end 37 | 38 | expect(count).to be > 0 39 | end 40 | end 41 | end 42 | 43 | -------------------------------------------------------------------------------- /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.url_for("non_control_elements.html")) 8 | end 9 | 10 | describe "with selectors" do 11 | it "returns the matching elements" do 12 | expect(browser.divs(id: "header").to_a).to eq [browser.div(id: "header")] 13 | end 14 | end 15 | 16 | describe "#length" do 17 | it "returns the number of divs" do 18 | expect(browser.divs.length).to eq 12 19 | end 20 | end 21 | 22 | describe "#[]" do 23 | it "returns the div at the given index" do 24 | expect(browser.divs[1].id).to eq "outer_container" 25 | end 26 | end 27 | 28 | describe "#each" do 29 | it "iterates through divs correctly" do 30 | count = 0 31 | 32 | browser.divs.each_with_index do |d, index| 33 | expect(d.id).to eq browser.div(index: index).id 34 | expect(d.class_name).to eq browser.div(index: index).class_name 35 | 36 | count += 1 37 | end 38 | 39 | expect(count).to be > 0 40 | end 41 | end 42 | 43 | end 44 | -------------------------------------------------------------------------------- /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.url_for("definition_lists.html")) 8 | end 9 | 10 | describe "with selectors" do 11 | it "returns the matching elements" do 12 | expect(browser.dts(class: "current-industry").to_a).to eq [browser.dt(class: "current-industry")] 13 | end 14 | end 15 | 16 | describe "#length" do 17 | it "returns the number of dts" do 18 | expect(browser.dts.length).to eq 11 19 | end 20 | end 21 | 22 | describe "#[]" do 23 | it "returns the dt at the given index" do 24 | expect(browser.dts[0].id).to eq "experience" 25 | end 26 | end 27 | 28 | describe "#each" do 29 | it "iterates through dts correctly" do 30 | count = 0 31 | 32 | browser.dts.each_with_index do |d, index| 33 | expect(d.id).to eq browser.dt(index: index).id 34 | expect(d.class_name).to eq browser.dt(index: index).class_name 35 | 36 | count += 1 37 | end 38 | 39 | expect(count).to be > 0 40 | end 41 | end 42 | 43 | end 44 | -------------------------------------------------------------------------------- /tables_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require File.expand_path("../spec_helper", __FILE__) 3 | 4 | describe "Tables" do 5 | 6 | before :each do 7 | browser.goto(WatirSpec.url_for("tables.html")) 8 | end 9 | 10 | describe "with selectors" do 11 | it "returns the matching elements" do 12 | expect(browser.tables(rules: "groups").to_a).to eq [browser.table(rules: "groups")] 13 | end 14 | end 15 | 16 | describe "#length" do 17 | it "returns the number of tables" do 18 | expect(browser.tables.length).to eq 4 19 | end 20 | end 21 | 22 | describe "#[]" do 23 | it "returns the p at the given index" do 24 | expect(browser.tables[0].id).to eq "axis_example" 25 | expect(browser.tables[1].id).to eq "outer" 26 | expect(browser.tables[2].id).to eq "inner" 27 | end 28 | end 29 | 30 | describe "#each" do 31 | it "iterates through tables correctly" do 32 | count = 0 33 | 34 | browser.tables.each_with_index do |t, index| 35 | expect(t.id).to eq browser.table(index: index).id 36 | count += 1 37 | end 38 | 39 | expect(count).to be > 0 40 | end 41 | end 42 | 43 | end 44 | -------------------------------------------------------------------------------- /strongs_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require File.expand_path("../spec_helper", __FILE__) 3 | 4 | describe "Strongs" do 5 | 6 | before :each do 7 | browser.goto(WatirSpec.url_for("non_control_elements.html")) 8 | end 9 | 10 | describe "with selectors" do 11 | it "returns the matching elements" do 12 | expect(browser.strongs(class: "descartes").to_a).to eq [browser.strong(class: "descartes")] 13 | end 14 | end 15 | 16 | describe "#length" do 17 | it "returns the number of divs" do 18 | expect(browser.strongs.length).to eq 2 19 | end 20 | end 21 | 22 | describe "#[]" do 23 | it "returns the div at the given index" do 24 | expect(browser.strongs[0].id).to eq "descartes" 25 | end 26 | end 27 | 28 | describe "#each" do 29 | it "iterates through divs correctly" do 30 | count = 0 31 | 32 | browser.strongs.each_with_index do |s, index| 33 | strong = browser.strong(index: index) 34 | expect(s.id).to eq strong.id 35 | expect(s.class_name).to eq strong.class_name 36 | 37 | count += 1 38 | end 39 | 40 | expect(count).to be > 0 41 | end 42 | end 43 | 44 | end 45 | -------------------------------------------------------------------------------- /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.url_for("definition_lists.html")) 8 | end 9 | 10 | describe "with selectors" do 11 | it "returns the matching elements" do 12 | expect(browser.dls(title: "experience").to_a).to eq [browser.dl(title: "experience")] 13 | end 14 | end 15 | 16 | describe "#length" do 17 | it "returns the number of dls" do 18 | expect(browser.dls.length).to eq 3 19 | end 20 | end 21 | 22 | describe "#[]" do 23 | it "returns the dl at the given index" do 24 | expect(browser.dls[0].id).to eq "experience-list" 25 | end 26 | end 27 | 28 | describe "#each" do 29 | it "iterates through dls correctly" do 30 | count = 0 31 | 32 | browser.dls.each_with_index do |d, index| 33 | expect(d.text).to eq browser.dl(index: index).text 34 | expect(d.id).to eq browser.dl(index: index).id 35 | expect(d.class_name).to eq browser.dl(index: index).class_name 36 | 37 | count += 1 38 | end 39 | 40 | expect(count).to be > 0 41 | end 42 | end 43 | 44 | end 45 | -------------------------------------------------------------------------------- /hns_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require File.expand_path("../spec_helper", __FILE__) 3 | 4 | describe ["H1s", "H2s", "H3s", "H4s", "H5s", "H6s"] do 5 | before :each do 6 | browser.goto(WatirSpec.url_for("non_control_elements.html")) 7 | end 8 | 9 | describe "with selectors" do 10 | it "returns the matching elements" do 11 | expect(browser.h1s(class: "primary").to_a).to eq [browser.h1(class: "primary")] 12 | end 13 | end 14 | 15 | describe "#length" do 16 | it "returns the number of h1s" do 17 | expect(browser.h2s.length).to eq 9 18 | end 19 | end 20 | 21 | describe "#[]" do 22 | it "returns the h1 at the given index" do 23 | expect(browser.h1s[0].id).to eq "first_header" 24 | end 25 | end 26 | 27 | describe "#each" do 28 | it "iterates through header collections correctly" do 29 | lengths = (1..6).collect do |i| 30 | collection = browser.send(:"h#{i}s") 31 | collection.each_with_index do |h, index| 32 | expect(h.id).to eq browser.send(:"h#{i}", :index, index).id 33 | end 34 | collection.length 35 | end 36 | expect(lengths).to eq [2, 9, 2, 1, 1, 2] 37 | end 38 | end 39 | end 40 | -------------------------------------------------------------------------------- /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.url_for("non_control_elements.html")) 8 | end 9 | 10 | describe "with selectors" do 11 | it "returns the matching elements" do 12 | expect(browser.ems(class: "important-class").to_a).to eq [browser.em(class: "important-class")] 13 | end 14 | end 15 | 16 | describe "#length" do 17 | it "returns the number of ems" do 18 | expect(browser.ems.length).to eq 1 19 | end 20 | end 21 | 22 | describe "#[]" do 23 | it "returns the em at the given index" do 24 | expect(browser.ems[0].id).to eq "important-id" 25 | end 26 | end 27 | 28 | describe "#each" do 29 | it "iterates through ems correctly" do 30 | count = 0 31 | 32 | browser.ems.each_with_index do |e, index| 33 | expect(e.text).to eq browser.em(index: index).text 34 | expect(e.id).to eq browser.em(index: index).id 35 | expect(e.class_name).to eq browser.em(index: index).class_name 36 | 37 | count += 1 38 | end 39 | 40 | expect(count).to be > 0 41 | end 42 | end 43 | 44 | end 45 | -------------------------------------------------------------------------------- /links_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require File.expand_path("../spec_helper", __FILE__) 3 | 4 | describe "Links" do 5 | 6 | before :each do 7 | browser.goto(WatirSpec.url_for("non_control_elements.html")) 8 | end 9 | 10 | describe "with selectors" do 11 | it "returns the matching elements" do 12 | expect(browser.links(title: "link_title_2").to_a).to eq [browser.link(title: "link_title_2")] 13 | end 14 | end 15 | 16 | describe "#length" do 17 | it "returns the number of links" do 18 | expect(browser.links.length).to eq 4 19 | end 20 | end 21 | 22 | describe "#[]" do 23 | it "returns the link at the given index" do 24 | expect(browser.links[2].id).to eq "link_3" 25 | end 26 | 27 | it "returns a Link object also when the index is out of bounds" do 28 | expect(browser.links[2000]).to_not be_nil 29 | end 30 | end 31 | 32 | describe "#each" do 33 | it "iterates through links correctly" do 34 | count = 0 35 | 36 | browser.links.each_with_index do |c, index| 37 | expect(c.id).to eq browser.link(index: index).id 38 | count += 1 39 | end 40 | 41 | expect(count).to be > 0 42 | end 43 | end 44 | 45 | end 46 | -------------------------------------------------------------------------------- /radios_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require File.expand_path("../spec_helper", __FILE__) 3 | 4 | describe "Radios" do 5 | 6 | before :each do 7 | browser.goto(WatirSpec.url_for("forms_with_input_elements.html")) 8 | end 9 | 10 | describe "with selectors" do 11 | it "returns the matching elements" do 12 | expect(browser.radios(value: "yes").to_a).to eq [browser.radio(value: "yes")] 13 | end 14 | end 15 | 16 | describe "#length" do 17 | it "returns the number of radios" do 18 | expect(browser.radios.length).to eq 6 19 | end 20 | end 21 | 22 | describe "#[]" do 23 | it "returns the radio button at the given index" do 24 | expect(browser.radios[0].id).to eq "new_user_newsletter_yes" 25 | end 26 | end 27 | 28 | describe "#each" do 29 | it "iterates through radio buttons correctly" do 30 | count = 0 31 | 32 | browser.radios.each_with_index do |r, index| 33 | expect(r.name).to eq browser.radio(index: index).name 34 | expect(r.id).to eq browser.radio(index: index).id 35 | expect(r.value).to eq browser.radio(index: index).value 36 | 37 | count += 1 38 | end 39 | 40 | expect(count).to be > 0 41 | end 42 | end 43 | 44 | end 45 | -------------------------------------------------------------------------------- /hiddens_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require File.expand_path("../spec_helper", __FILE__) 3 | 4 | describe "Hiddens" do 5 | 6 | before :each do 7 | browser.goto(WatirSpec.url_for("forms_with_input_elements.html")) 8 | end 9 | 10 | describe "with selectors" do 11 | it "returns the matching elements" do 12 | expect(browser.hiddens(value: "dolls").to_a).to eq [browser.hidden(value: "dolls")] 13 | end 14 | end 15 | 16 | describe "#length" do 17 | it "returns the number of hiddens" do 18 | expect(browser.hiddens.length).to eq 2 19 | end 20 | end 21 | 22 | describe "#[]" do 23 | it "returns the Hidden at the given index" do 24 | expect(browser.hiddens[1].id).to eq "new_user_interests_dolls" 25 | end 26 | end 27 | 28 | describe "#each" do 29 | it "iterates through hiddens correctly" do 30 | count = 0 31 | 32 | browser.hiddens.each_with_index do |h, index| 33 | expect(h.name).to eq browser.hidden(index: index).name 34 | expect(h.id).to eq browser.hidden(index: index).id 35 | expect(h.value).to eq browser.hidden(index: index).value 36 | 37 | count += 1 38 | end 39 | 40 | expect(count).to be > 0 41 | end 42 | end 43 | 44 | end 45 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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.url_for("forms_with_input_elements.html")) 8 | end 9 | 10 | describe "with selectors" do 11 | it "returns the matching elements" do 12 | expect(browser.file_fields(class: "portrait").to_a).to eq [browser.file_field(class: "portrait")] 13 | end 14 | end 15 | 16 | describe "#length" do 17 | it "returns the correct number of file fields" do 18 | expect(browser.file_fields.length).to eq 3 19 | end 20 | end 21 | 22 | describe "#[]" do 23 | it "returns the file field at the given index" do 24 | expect(browser.file_fields[0].id).to eq "new_user_portrait" 25 | end 26 | end 27 | 28 | describe "#each" do 29 | it "iterates through file fields correctly" do 30 | count = 0 31 | 32 | browser.file_fields.each_with_index do |f, index| 33 | expect(f.name).to eq browser.file_field(index: index).name 34 | expect(f.id).to eq browser.file_field(index: index).id 35 | expect(f.value).to eq browser.file_field(index: index).value 36 | 37 | count += 1 38 | end 39 | 40 | expect(count).to be > 0 41 | end 42 | end 43 | 44 | end 45 | -------------------------------------------------------------------------------- /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.url_for("forms_with_input_elements.html")) 8 | end 9 | 10 | describe "with selectors" do 11 | it "returns the matching elements" do 12 | expect(browser.checkboxes(value: "books").to_a).to eq [browser.checkbox(value: "books")] 13 | end 14 | end 15 | 16 | describe "#length" do 17 | it "returns the number of checkboxes" do 18 | expect(browser.checkboxes.length).to eq 8 19 | end 20 | end 21 | 22 | describe "#[]" do 23 | it "returns the checkbox at the given index" do 24 | expect(browser.checkboxes[0].id).to eq "new_user_interests_books" 25 | end 26 | end 27 | 28 | describe "#each" do 29 | it "iterates through checkboxes correctly" do 30 | count = 0 31 | 32 | browser.checkboxes.each_with_index do |c, index| 33 | expect(c).to be_instance_of(CheckBox) 34 | expect(c.name).to eq browser.checkbox(index: index).name 35 | expect(c.id).to eq browser.checkbox(index: index).id 36 | expect(c.value).to eq browser.checkbox(index: index).value 37 | 38 | count += 1 39 | end 40 | 41 | expect(count).to be > 0 42 | end 43 | end 44 | 45 | end 46 | -------------------------------------------------------------------------------- /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.url_for("forms_with_input_elements.html")) 8 | end 9 | 10 | describe "with selectors" do 11 | it "returns the matching elements" do 12 | expect(browser.forms(method: "post").to_a).to eq [browser.form(method: "post")] 13 | end 14 | end 15 | 16 | describe "#length" do 17 | it "returns the number of forms in the container" do 18 | expect(browser.forms.length).to eq 2 19 | end 20 | end 21 | 22 | describe "#[]n" do 23 | it "provides access to the nth form" do 24 | expect(browser.forms[0].action).to match(/post_to_me$/) # varies between browsers 25 | expect(browser.forms[0].attribute_value('method')).to eq 'post' 26 | end 27 | end 28 | 29 | describe "#each" do 30 | it "iterates through forms correctly" do 31 | count = 0 32 | 33 | browser.forms.each_with_index do |f, index| 34 | expect(f.name).to eq browser.form(index: index).name 35 | expect(f.id).to eq browser.form(index: index).id 36 | expect(f.class_name).to eq browser.form(index: index).class_name 37 | 38 | count += 1 39 | end 40 | 41 | expect(count).to be > 0 42 | end 43 | end 44 | 45 | end 46 | -------------------------------------------------------------------------------- /iframes_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require File.expand_path("../spec_helper", __FILE__) 3 | 4 | describe "IFrames" do 5 | 6 | before :each do 7 | browser.goto(WatirSpec.url_for("iframes.html")) 8 | end 9 | 10 | describe "with selectors" do 11 | it "returns the matching elements" do 12 | expect(browser.iframes(id: "iframe_2").to_a).to eq [browser.iframe(id: "iframe_2")] 13 | end 14 | end 15 | 16 | describe "eql?" do 17 | it "matches equality of iframe with that from a collection" do 18 | expect(browser.iframes.last).to eq browser.iframe(id: "iframe_2") 19 | end 20 | 21 | end 22 | 23 | describe "#length" do 24 | it "returns the correct number of iframes" do 25 | expect(browser.iframes.length).to eq 2 26 | end 27 | end 28 | 29 | describe "#[]" do 30 | it "returns the iframe at the given index" do 31 | expect(browser.iframes[0].id).to eq "iframe_1" 32 | end 33 | end 34 | 35 | describe "#each" do 36 | it "iterates through frames correctly" do 37 | count = 0 38 | 39 | browser.iframes.each_with_index do |f, index| 40 | expect(f.name).to eq browser.iframe(index: index).name 41 | expect(f.id).to eq browser.iframe(index: index).id 42 | count += 1 43 | end 44 | 45 | expect(count).to be > 0 46 | end 47 | end 48 | end 49 | -------------------------------------------------------------------------------- /html/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 | 16 | 17 | 18 |
19 |
20 |
21 | 22 | 23 | -------------------------------------------------------------------------------- /text_fields_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require File.expand_path("../spec_helper", __FILE__) 3 | 4 | describe "TextFields" do 5 | 6 | before :each do 7 | browser.goto(WatirSpec.url_for("forms_with_input_elements.html")) 8 | end 9 | 10 | describe "with selectors" do 11 | it "returns the matching elements" do 12 | expect(browser.text_fields(name: "new_user_email").to_a).to eq [browser.text_field(name: "new_user_email")] 13 | end 14 | end 15 | 16 | describe "#length" do 17 | it "returns the number of text fields" do 18 | expect(browser.text_fields.length).to eq 20 19 | end 20 | end 21 | 22 | describe "#[]" do 23 | it "returns the text field at the given index" do 24 | expect(browser.text_fields[0].id).to eq "new_user_first_name" 25 | expect(browser.text_fields[1].id).to eq "new_user_last_name" 26 | expect(browser.text_fields[2].id).to eq "new_user_email" 27 | end 28 | end 29 | 30 | describe "#each" do 31 | it "iterates through text fields correctly" do 32 | count = 0 33 | 34 | browser.text_fields.each_with_index do |r, index| 35 | expect(r.name).to eq browser.text_field(index: index).name 36 | expect(r.id).to eq browser.text_field(index: index).id 37 | expect(r.value).to eq browser.text_field(index: index).value 38 | 39 | count += 1 40 | end 41 | 42 | expect(count).to be > 0 43 | end 44 | end 45 | end 46 | -------------------------------------------------------------------------------- /html/iframe_1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | IFrame 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 | 16 | 17 | 18 |
19 |
20 |
21 | 22 | 23 | -------------------------------------------------------------------------------- /select_lists_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require File.expand_path("../spec_helper", __FILE__) 3 | 4 | describe "SelectLists" do 5 | 6 | before :each do 7 | browser.goto(WatirSpec.url_for("forms_with_input_elements.html")) 8 | end 9 | 10 | describe "with selectors" do 11 | it "returns the matching elements" do 12 | expect(browser.select_lists(name: "delete_user_username").to_a).to eq [browser.select_list(name: "delete_user_username")] 13 | end 14 | end 15 | 16 | describe "#length" do 17 | it "returns the correct number of select lists on the page" do 18 | expect(browser.select_lists.length).to eq 6 19 | end 20 | end 21 | 22 | describe "#[]" do 23 | it "returns the correct item" do 24 | expect(browser.select_lists[0].value).to eq "2" 25 | expect(browser.select_lists[0].name).to eq "new_user_country" 26 | expect(browser.select_lists[0]).to_not be_multiple 27 | expect(browser.select_lists[1]).to be_multiple 28 | end 29 | end 30 | 31 | describe "#each" do 32 | it "iterates through the select lists correctly" do 33 | count = 0 34 | 35 | browser.select_lists.each_with_index do |l, index| 36 | expect(browser.select_list(index: index).name).to eq l.name 37 | expect(browser.select_list(index: index).id).to eq l.id 38 | expect(browser.select_list(index: index).value).to eq l.value 39 | 40 | count += 1 41 | end 42 | 43 | expect(count).to be > 0 44 | end 45 | end 46 | 47 | end 48 | -------------------------------------------------------------------------------- /html/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 | -------------------------------------------------------------------------------- /html/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 | Foo 24 | 25 | 26 |
27 | 28 | -------------------------------------------------------------------------------- /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.url_for("forms_with_input_elements.html")) 8 | end 9 | 10 | describe "with selectors" do 11 | it "returns the matching elements" do 12 | expect(browser.buttons(name: "new_user_button").to_a).to eq [browser.button(name: "new_user_button")] 13 | end 14 | end 15 | 16 | describe "#length" do 17 | it "returns the number of buttons" do 18 | expect(browser.buttons.length).to eq 9 19 | end 20 | end 21 | 22 | describe "#[]" do 23 | it "returns the button at the given index" do 24 | expect(browser.buttons[0].title).to eq "Submit the form" 25 | end 26 | end 27 | 28 | describe "#first" do 29 | it "returns the first element in the collection" do 30 | expect(browser.buttons.first.value).to eq browser.buttons[0].value 31 | end 32 | end 33 | 34 | describe "#last" do 35 | it "returns the last element in the collection" do 36 | expect(browser.buttons.last.value).to eq browser.buttons[-1].value 37 | end 38 | end 39 | 40 | describe "#each" do 41 | it "iterates through buttons correctly" do 42 | count = 0 43 | 44 | browser.buttons.each_with_index do |b, index| 45 | expect(b.name).to eq browser.button(index: index).name 46 | expect(b.id).to eq browser.button(index: index).id 47 | expect(b.value).to eq browser.button(index: index).value 48 | 49 | count += 1 50 | end 51 | 52 | expect(count).to be > 0 53 | end 54 | end 55 | 56 | end 57 | -------------------------------------------------------------------------------- /tds_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require File.expand_path("../spec_helper", __FILE__) 3 | 4 | describe "TableCells" do 5 | 6 | before :each do 7 | browser.goto(WatirSpec.url_for("tables.html")) 8 | end 9 | 10 | describe "with selectors" do 11 | it "returns the matching elements" do 12 | expect(browser.tds(headers: "before_tax").to_a).to eq [browser.td(headers: "before_tax")] 13 | end 14 | end 15 | 16 | # describe "#length" do 17 | # it "returns the number of cells" do 18 | # browser.table(id: 'outer').cells.length.to eq 6 19 | # browser.table(id: 'inner').cells.length.to eq 2 20 | # end 21 | # end 22 | # 23 | # describe "#[]" do 24 | # it "returns the row at the given index" do 25 | # browser.table(id: 'outer').cells[0].text.to eq "Table 1, Row 1, Cell 1" 26 | # browser.table(id: 'inner').cells[0].text.to eq "Table 2, Row 1, Cell 1" 27 | # browser.table(id: 'outer').cells[6].text.to eq "Table 1, Row 3, Cell 2" 28 | # end 29 | # end 30 | 31 | describe "#each" do 32 | it "iterates through all cells on the page correctly" do 33 | count = 0 34 | 35 | browser.tds.each_with_index do |c, index| 36 | expect(c.id).to eq browser.td(index: index).id 37 | count += 1 38 | end 39 | 40 | expect(count).to be > 0 41 | end 42 | 43 | it "iterates through cells inside a table" do 44 | count = 0 45 | 46 | inner_table = browser.table(id: 'inner') 47 | inner_table.tds.each_with_index do |c, index| 48 | expect(c.id).to eq inner_table.td(index: index).id 49 | count += 1 50 | end 51 | end 52 | 53 | end 54 | end 55 | -------------------------------------------------------------------------------- /lib/implementation.rb: -------------------------------------------------------------------------------- 1 | module WatirSpec 2 | class Implementation 3 | 4 | attr_writer :name, :guard_proc, :browser_class 5 | attr_accessor :browser_args 6 | 7 | def initialize 8 | @guard_proc = nil 9 | end 10 | 11 | def browser_class 12 | @browser_class || raise("browser_class not set") 13 | end 14 | 15 | def name 16 | @name || raise("implementation name not set") 17 | end 18 | 19 | def matches_guard?(args) 20 | return @guard_proc.call(args) if @guard_proc 21 | 22 | args.include? name 23 | end 24 | 25 | def matching_guards_in(guards) 26 | result = [] 27 | guards.each { |args, data| data.each {|d| result << d } if matches_guard?(args) } 28 | 29 | result 30 | end 31 | 32 | end # Implementation 33 | end # WatirSpec 34 | 35 | if __FILE__ == $0 36 | require "rubygems" 37 | require 'rspec/autorun' 38 | 39 | describe WatirSpec::Implementation do 40 | before { @impl = WatirSpec::Implementation.new } 41 | 42 | it "finds matching guards" do 43 | guards = { 44 | [:watir_classic] => [ 45 | {name: :not_compliant, data: {file: "./spec/watirspec/div_spec.rb:108"}}, 46 | {name: :deviates, data: {file: "./spec/watirspec/div_spec.rb:114"}}, 47 | {name: :not_compliant, data: {file: "./spec/watirspec/div_spec.rb:200"}}, 48 | {name: :bug, data: {file: "./spec/watirspec/div_spec.rb:228", key: "WTR-350"}} 49 | ] 50 | } 51 | @impl.name = :watir_classic 52 | @impl.matching_guards_in(guards).should == [{name: :deviates, data: {file: "./spec/watirspec/div_spec.rb:114"}}] 53 | end 54 | end 55 | end 56 | -------------------------------------------------------------------------------- /lib/guards.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | module WatirSpec 3 | module Guards 4 | 5 | class << self 6 | def guards 7 | @guards ||= Hash.new { |hash, key| hash[key] = [] } 8 | end 9 | 10 | def record(guard_name, impls, data) 11 | guards[impls] << {name: guard_name, data: data} 12 | end 13 | 14 | def report 15 | gs = WatirSpec.implementation.matching_guards_in(guards) 16 | print "\n\nWatirSpec guards for this implementation: " 17 | 18 | if gs.empty? 19 | puts "none." 20 | else 21 | puts 22 | gs.each do |guard| 23 | puts "\t#{guard[:name].to_s.ljust(20)}: #{guard[:data].inspect}" 24 | end 25 | end 26 | end 27 | end # class << self 28 | 29 | private 30 | 31 | def deviates_on(*impls) 32 | Guards.record :deviates, impls, file: caller.first 33 | return yield if WatirSpec.unguarded? 34 | yield if WatirSpec.implementation.matches_guard?(impls) 35 | end 36 | 37 | def not_compliant_on(*impls) 38 | Guards.record :not_compliant, impls, file: caller.first 39 | return yield if WatirSpec.unguarded? 40 | yield unless WatirSpec.implementation.matches_guard?(impls) 41 | end 42 | 43 | def compliant_on(*impls) 44 | Guards.record :compliant, impls, file: caller.first 45 | return yield if WatirSpec.unguarded? 46 | yield if WatirSpec.implementation.matches_guard?(impls) 47 | end 48 | 49 | def bug(key, *impls) 50 | Guards.record :bug, impls, file: caller.first, key: key 51 | return yield if WatirSpec.unguarded? 52 | yield unless WatirSpec.implementation.matches_guard?(impls) 53 | end 54 | end 55 | end 56 | 57 | class Object 58 | include WatirSpec::Guards 59 | end 60 | -------------------------------------------------------------------------------- /tbodys_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require File.expand_path("../spec_helper", __FILE__) 3 | 4 | describe "TableBodies" do 5 | 6 | before :each do 7 | browser.goto(WatirSpec.url_for("tables.html")) 8 | end 9 | 10 | describe "with selectors" do 11 | it "returns the matching elements" do 12 | expect(browser.tbodys(id: "first").to_a).to eq [browser.tbody(id: "first")] 13 | end 14 | end 15 | 16 | describe "#length" do 17 | it "returns the correct number of table bodies (page context)" do 18 | expect(browser.tbodys.length).to eq 5 19 | end 20 | 21 | it "returns the correct number of table bodies (table context)" do 22 | expect(browser.table(index: 0).tbodys.length).to eq 2 23 | end 24 | end 25 | 26 | describe "#[]" do 27 | it "returns the row at the given index (page context)" do 28 | expect(browser.tbodys[0].id).to eq "first" 29 | end 30 | 31 | it "returns the row at the given index (table context)" do 32 | expect(browser.table(index: 0).tbodys[0].id).to eq "first" 33 | end 34 | end 35 | 36 | describe "#each" do 37 | it "iterates through table bodies correctly (table context)" do 38 | count = 0 39 | 40 | browser.tbodys.each_with_index do |body, index| 41 | expect(body.id).to eq browser.tbody(index: index).id 42 | 43 | count += 1 44 | end 45 | 46 | expect(count).to be > 0 47 | end 48 | 49 | it "iterates through table bodies correctly (table context)" do 50 | table = browser.table(index: 0) 51 | count = 0 52 | 53 | table.tbodys.each_with_index do |body, index| 54 | expect(body.id).to eq table.tbody(index: index).id 55 | 56 | count += 1 57 | end 58 | 59 | expect(count).to be > 0 60 | end 61 | end 62 | 63 | end 64 | -------------------------------------------------------------------------------- /drag_and_drop_spec.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path("../spec_helper", __FILE__) 2 | 3 | describe "Element" do 4 | bug "Actions Endpoint Not Yet Implemented", :firefox do 5 | context "drag and drop" do 6 | before { browser.goto WatirSpec.url_for("drag_and_drop.html") } 7 | 8 | let(:draggable) { browser.div id: "draggable" } 9 | let(:droppable) { browser.div id: "droppable" } 10 | 11 | not_compliant_on :safari do 12 | it "can drag and drop an element onto another" do 13 | expect(droppable.text).to eq 'Drop here' 14 | draggable.drag_and_drop_on droppable 15 | expect(droppable.text).to eq 'Dropped!' 16 | end 17 | 18 | bug "http://code.google.com/p/selenium/issues/detail?id=3075", :ff_legacy do 19 | it "can drag and drop an element onto another when draggable is out of viewport" do 20 | reposition "draggable" 21 | perform_drag_and_drop_on_droppable 22 | end 23 | 24 | it "can drag and drop an element onto another when droppable is out of viewport" do 25 | reposition "droppable" 26 | perform_drag_and_drop_on_droppable 27 | end 28 | end 29 | 30 | it "can drag an element by the given offset" do 31 | expect(droppable.text).to eq 'Drop here' 32 | draggable.drag_and_drop_by 200, 50 33 | expect(droppable.text).to eq 'Dropped!' 34 | end 35 | 36 | def reposition(what) 37 | browser.button(id: "reposition#{what.capitalize}").click 38 | end 39 | 40 | def perform_drag_and_drop_on_droppable 41 | expect(droppable.text).to eq "Drop here" 42 | draggable.drag_and_drop_on droppable 43 | expect(droppable.text).to eq 'Dropped!' 44 | end 45 | end 46 | 47 | end 48 | end 49 | end 50 | -------------------------------------------------------------------------------- /trs_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require File.expand_path("../spec_helper", __FILE__) 3 | 4 | describe "TableRows" do 5 | 6 | before :each do 7 | browser.goto(WatirSpec.url_for("tables.html")) 8 | end 9 | 10 | describe "with selectors" do 11 | it "returns the matching elements" do 12 | expect(browser.trs(id: "outer_second").to_a).to eq [browser.tr(id: "outer_second")] 13 | end 14 | end 15 | 16 | describe "#length" do 17 | it "returns the correct number of cells (table context)" do 18 | expect(browser.table(id: 'inner').trs.length).to eq 1 19 | expect(browser.table(id: 'outer').trs.length).to eq 4 20 | end 21 | 22 | it "returns the correct number of cells (page context)" do 23 | expect(browser.trs.length).to eq 14 24 | end 25 | end 26 | 27 | describe "#[]" do 28 | it "returns the row at the given index (table context)" do 29 | expect(browser.table(id: 'outer').trs[0].id).to eq "outer_first" 30 | end 31 | 32 | it "returns the row at the given index (page context)" do 33 | expect(browser.trs[0].id).to eq "thead_row_1" 34 | end 35 | end 36 | 37 | describe "#each" do 38 | it "iterates through rows correctly" do 39 | inner_table = browser.table(id: 'inner') 40 | count = 0 41 | 42 | inner_table.trs.each_with_index do |r, index| 43 | expect(r.id).to eq inner_table.tr(index: index).id 44 | count += 1 45 | end 46 | expect(count).to be > 0 47 | end 48 | 49 | it "iterates through the outer table correctly" do 50 | outer_table = browser.table(id: 'outer') 51 | count = 0 52 | 53 | outer_table.trs.each_with_index do |r, index| 54 | expect(r.id).to eq outer_table.tr(index: index).id 55 | count += 1 56 | end 57 | 58 | expect(count).to be > 0 59 | end 60 | end 61 | 62 | end 63 | -------------------------------------------------------------------------------- /html/wait.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | wait test 5 | 25 | 26 | 27 | 28 |
foo
29 | 30 | show bar 31 | hide foo 32 | remove foo 33 |
34 | 35 | enable btn 36 | 37 | 38 | show and enable btn 39 | 40 |
41 |
42 | 43 | 44 | -------------------------------------------------------------------------------- /table_nesting_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require File.expand_path("../spec_helper", __FILE__) 3 | 4 | describe "Table" do 5 | 6 | before :each do 7 | browser.goto(WatirSpec.url_for("nested_tables.html")) 8 | end 9 | 10 | # not a selenium bug - IE seems unable to deal with the invalid nesting 11 | not_compliant_on :internet_explorer do 12 | it "returns the correct number of rows under a table" do 13 | tables = browser.div(id: "table-rows-test").tables(id: /^tbl/) 14 | expect(tables.length).to be > 0 15 | 16 | tables.each do |table| 17 | expected = Integer(table.data_row_count) 18 | actual = table.rows.length 19 | browser_count = Integer(table.data_browser_count) 20 | 21 | expect(actual).to eql(expected), "expected #{expected} rows, got #{actual} for table id=#{table.id}, browser reported: #{browser_count}" 22 | end 23 | end 24 | 25 | it "returns the correct number of cells under a row" do 26 | rows = browser.div(id: "row-cells-test").trs(id: /^row/) 27 | expect(rows.length).to be > 0 28 | 29 | rows.each do |row| 30 | expected = Integer(row.data_cell_count) 31 | actual = row.cells.length 32 | browser_count = Integer(row.data_browser_count) 33 | 34 | expect(actual).to eql(expected), "expected #{expected} cells, got #{actual} for row id=#{row.id}, browser reported: #{browser_count}" 35 | end 36 | end 37 | 38 | it "returns the correct number of rows under a table section" do 39 | tbodies = browser.table(id: "tbody-rows-test").tbodys(id: /^body/) 40 | expect(tbodies.length).to be > 0 41 | 42 | tbodies.each do |tbody| 43 | expected = Integer(tbody.data_rows_count) 44 | actual = tbody.rows.count 45 | browser_count = Integer(tbody.data_browser_count) 46 | 47 | expect(actual).to eql(expected), "expected #{expected} rows, got #{actual} for tbody id=#{tbody.id}, browser reported: #{browser_count}" 48 | end 49 | end 50 | end 51 | 52 | end 53 | -------------------------------------------------------------------------------- /element_hidden_spec.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path("../spec_helper", __FILE__) 2 | 3 | describe Watir::Locators::Element::Locator do 4 | 5 | describe "Visible Elements" do 6 | before do 7 | browser.goto(WatirSpec.url_for("wait.html")) 8 | end 9 | 10 | context "when true" do 11 | it "finds single element" do 12 | element = browser.body.element(visible: true) 13 | expect(element.id).to eq 'foo' 14 | end 15 | 16 | it "handles tag_name and index" do 17 | element = browser.div(visible: true, index: 1) 18 | expect(element.id).to eq 'buttons' 19 | end 20 | 21 | it "handles :tag_name and a single regexp attribute" do 22 | element = browser.div(visible: true, id: /ons/) 23 | expect(element.id).to eq 'buttons' 24 | end 25 | 26 | it "handles :xpath" do 27 | element = browser.element(visible: true, xpath: './/div[@id="foo"]') 28 | expect(element.id).to eq 'foo' 29 | end 30 | 31 | it "handles :css" do 32 | element = browser.element(visible: true, css: 'div#foo') 33 | expect(element.id).to eq 'foo' 34 | end 35 | end 36 | 37 | context "when false" do 38 | it "finds single element" do 39 | element = browser.body.element(visible: false) 40 | expect(element.id).to eq 'bar' 41 | end 42 | 43 | it "handles tag_name and index" do 44 | element = browser.div(visible: false, index: 1) 45 | expect(element.id).to eq 'also_hidden' 46 | end 47 | 48 | it "handles :tag_name and a single regexp attribute" do 49 | element = browser.div(visible: false, id: /_/) 50 | expect(element.id).to eq 'also_hidden' 51 | end 52 | 53 | it "handles :xpath" do 54 | element = browser.element(visible: false, xpath: './/div[@id="bar"]') 55 | expect(element.id).to eq 'bar' 56 | end 57 | 58 | it "handles :css" do 59 | element = browser.element(visible: false, css: 'div#bar') 60 | expect(element.id).to eq 'bar' 61 | end 62 | end 63 | end 64 | end 65 | 66 | -------------------------------------------------------------------------------- /tfoots_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require File.expand_path("../spec_helper", __FILE__) 3 | 4 | describe "TableFooters" do 5 | before :each do 6 | browser.goto(WatirSpec.url_for("tables.html")) 7 | end 8 | 9 | describe "with selectors" do 10 | it "returns the matching elements" do 11 | expect(browser.tfoots(id: "tax_totals").to_a).to eq [browser.tfoot(id: "tax_totals")] 12 | end 13 | end 14 | 15 | describe "#length" do 16 | it "returns the correct number of table tfoots (page context)" do 17 | expect(browser.tfoots.length).to eq 1 18 | end 19 | 20 | it "returns the correct number of table tfoots (table context)" do 21 | expect(browser.table(index: 0).tfoots.length).to eq 1 22 | end 23 | end 24 | 25 | describe "#[]" do 26 | it "returns the row at the given index (page context)" do 27 | expect(browser.tfoots[0].id).to eq "tax_totals" 28 | end 29 | 30 | it "returns the row at the given index (table context)" do 31 | expect(browser.table(index: 0).tfoots[0].id).to eq "tax_totals" 32 | end 33 | end 34 | 35 | describe "#each" do 36 | it "iterates through table tfoots correctly (page context)" do 37 | browser.tfoots.each_with_index do |tfoot, index| 38 | expect(tfoot.id).to eq browser.tfoot(index: index).id 39 | end 40 | end 41 | 42 | describe "#each" do 43 | it "iterates through table tfoots correctly (page context)" do 44 | count = 0 45 | 46 | browser.tfoots.each_with_index do |tfoot, index| 47 | expect(tfoot.id).to eq browser.tfoot(index: index).id 48 | 49 | count += 1 50 | end 51 | 52 | expect(count).to be > 0 53 | end 54 | 55 | it "iterates through table tfoots correctly (table context)" do 56 | table = browser.table(index: 0) 57 | count = 0 58 | 59 | table.tfoots.each_with_index do |tfoot, index| 60 | expect(tfoot.id).to eq table.tfoot(index: index).id 61 | 62 | count += 1 63 | end 64 | 65 | expect(count).to be > 0 66 | end 67 | end 68 | end 69 | end 70 | -------------------------------------------------------------------------------- /lib/runner.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | module WatirSpec 3 | module Runner 4 | 5 | module BrowserHelper 6 | def browser; @browser; end 7 | end 8 | 9 | module PersistentBrowserHelper 10 | def browser; $browser; end 11 | end 12 | 13 | module MessagesHelper 14 | def messages 15 | browser.div(id: 'messages').divs.map(&:text) 16 | end 17 | end 18 | 19 | module_function 20 | 21 | def execute 22 | load_requires 23 | start_server 24 | configure 25 | add_guard_hook 26 | 27 | @executed = true 28 | end 29 | 30 | def execute_if_necessary 31 | execute unless @executed 32 | end 33 | 34 | def configure 35 | Thread.abort_on_exception = true 36 | 37 | RSpec.configure do |config| 38 | config.include(MessagesHelper) 39 | 40 | if WatirSpec.persistent_browser == false 41 | config.include(BrowserHelper) 42 | 43 | config.before(:all) { @browser = WatirSpec.new_browser } 44 | config.after(:all) { @browser.close if @browser } 45 | else 46 | config.include(PersistentBrowserHelper) 47 | $browser = WatirSpec.new_browser 48 | at_exit { $browser.close } 49 | end 50 | end 51 | end 52 | 53 | def load_requires 54 | require "rspec" 55 | require "fileutils" 56 | 57 | implementation = File.expand_path("../../../implementation.rb", __FILE__) 58 | load implementation 59 | 60 | begin 61 | require "ruby-debug" 62 | Debugger.start 63 | Debugger.settings[:autoeval] = true 64 | Debugger.settings[:autolist] = 1 65 | rescue LoadError 66 | end 67 | end 68 | 69 | def start_server 70 | if WatirSpec::Server.should_run? 71 | WatirSpec::Server.run_async 72 | else 73 | $stderr.puts "not running WatirSpec::Server" 74 | end 75 | end 76 | 77 | def add_guard_hook 78 | return if WatirSpec.unguarded? 79 | at_exit { WatirSpec::Guards.report } 80 | end 81 | 82 | end # SpecHelper 83 | end # WatirSpec 84 | -------------------------------------------------------------------------------- /theads_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require File.expand_path("../spec_helper", __FILE__) 3 | 4 | describe "TableHeaders" do 5 | before :each do 6 | browser.goto(WatirSpec.url_for("tables.html")) 7 | end 8 | 9 | describe "with selectors" do 10 | it "returns the matching elements" do 11 | expect(browser.theads(id: "tax_headers").to_a).to eq [browser.thead(id: "tax_headers")] 12 | end 13 | end 14 | 15 | describe "#length" do 16 | it "returns the correct number of table theads (page context)" do 17 | expect(browser.theads.length).to eq 1 18 | end 19 | 20 | it "returns the correct number of table theads (table context)" do 21 | expect(browser.table(index: 0).theads.length).to eq 1 22 | end 23 | end 24 | 25 | describe "#[]" do 26 | it "returns the row at the given index (page context)" do 27 | expect(browser.theads[0].id).to eq "tax_headers" 28 | end 29 | 30 | it "returns the row at the given index (table context)" do 31 | expect(browser.table(index: 0).theads[0].id).to eq "tax_headers" 32 | end 33 | end 34 | 35 | describe "#each" do 36 | it "iterates through table theads correctly (page context)" do 37 | browser.theads.each_with_index do |thead, index| 38 | expect(thead.id).to eq browser.thead(index: index).id 39 | end 40 | end 41 | 42 | describe "#each" do 43 | it "iterates through table theads correctly (page context)" do 44 | count = 0 45 | 46 | browser.theads.each_with_index do |thead, index| 47 | expect(thead.id).to eq browser.thead(index: index).id 48 | 49 | count += 1 50 | end 51 | 52 | expect(count).to be > 0 53 | end 54 | 55 | it "iterates through table theads correctly (table context)" do 56 | table = browser.table(index: 0) 57 | count = 0 58 | 59 | table.theads.each_with_index do |thead, index| 60 | expect(thead.id).to eq table.thead(index: index).id 61 | 62 | count += 1 63 | end 64 | 65 | expect(count).to be > 0 66 | end 67 | end 68 | end 69 | end 70 | -------------------------------------------------------------------------------- /td_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require File.expand_path("../spec_helper", __FILE__) 3 | 4 | describe "TableCell" do 5 | 6 | before :each do 7 | browser.goto(WatirSpec.url_for("tables.html")) 8 | end 9 | 10 | # Exists 11 | describe "#exists?" do 12 | it "returns true when the table cell exists" do 13 | expect(browser.td(id: 't1_r2_c1')).to exist 14 | expect(browser.td(id: /t1_r2_c1/)).to exist 15 | expect(browser.td(text: 'Table 1, Row 3, Cell 1')).to exist 16 | expect(browser.td(text: /Table 1/)).to exist 17 | expect(browser.td(index: 0)).to exist 18 | expect(browser.td(xpath: "//td[@id='t1_r2_c1']")).to exist 19 | end 20 | 21 | it "returns the first cell if given no args" do 22 | expect(browser.td).to exist 23 | end 24 | 25 | it "returns false when the table cell does not exist" do 26 | expect(browser.td(id: 'no_such_id')).to_not exist 27 | expect(browser.td(id: /no_such_id/)).to_not exist 28 | expect(browser.td(text: 'no_such_text')).to_not exist 29 | expect(browser.td(text: /no_such_text/)).to_not exist 30 | expect(browser.td(index: 1337)).to_not exist 31 | expect(browser.td(xpath: "//td[@id='no_such_id']")).to_not exist 32 | end 33 | 34 | it "raises TypeError when 'what' argument is invalid" do 35 | expect { browser.td(id: 3.14).exists? }.to raise_error(TypeError) 36 | end 37 | 38 | it "raises MissingWayOfFindingObjectException when 'how' argument is invalid" do 39 | expect { browser.td(no_such_how: 'some_value').exists? }.to raise_error(Watir::Exception::MissingWayOfFindingObjectException) 40 | end 41 | end 42 | 43 | describe "#click" do 44 | it "fires the table's onclick event" do 45 | browser.td(id: 't2_r1_c1').click 46 | expect(messages).to include('td') 47 | end 48 | end 49 | 50 | # Attribute methods 51 | describe "#text" do 52 | it "returns the text inside the table cell" do 53 | expect(browser.td(id: 't1_r2_c1').text).to eq 'Table 1, Row 2, Cell 1' 54 | expect(browser.td(id: 't2_r1_c1').text).to eq 'Table 2, Row 1, Cell 1' 55 | end 56 | end 57 | 58 | describe "#colspan" do 59 | it "gets the colspan attribute" do 60 | expect(browser.td(id: 'colspan_2').colspan).to eq 2 61 | expect(browser.td(id: 'no_colspan').colspan).to eq 1 62 | end 63 | end 64 | 65 | describe "#respond_to?" do 66 | it "returns true for all attribute methods" do 67 | expect(browser.td(index: 0)).to respond_to(:text) 68 | expect(browser.td(index: 0)).to respond_to(:colspan) 69 | end 70 | end 71 | 72 | end 73 | -------------------------------------------------------------------------------- /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.url_for("forms_with_input_elements.html")) 8 | end 9 | 10 | describe "#exists?" do 11 | it "returns true if the form exists" do 12 | expect(browser.form(id: 'new_user')).to exist 13 | expect(browser.form(id: /new_user/)).to exist 14 | 15 | expect(browser.form(class: 'user')).to exist 16 | expect(browser.form(class: /user/)).to exist 17 | 18 | expect(browser.form(method: 'post')).to exist 19 | expect(browser.form(method: /post/)).to exist 20 | expect(browser.form(action: /to_me/)).to exist 21 | expect(browser.form(index: 0)).to exist 22 | expect(browser.form(xpath: "//form[@id='new_user']")).to exist 23 | end 24 | 25 | it "returns the first form if given no args" do 26 | expect(browser.form).to exist 27 | end 28 | 29 | it "returns false if the form doesn't exist" do 30 | expect(browser.form(id: 'no_such_id')).to_not exist 31 | expect(browser.form(id: /no_such_id/)).to_not exist 32 | 33 | expect(browser.form(class: 'no_such_class')).to_not exist 34 | expect(browser.form(class: /no_such_class/)).to_not exist 35 | 36 | expect(browser.form(method: 'no_such_method')).to_not exist 37 | expect(browser.form(method: /no_such_method/)).to_not exist 38 | expect(browser.form(action: 'no_such_action')).to_not exist 39 | expect(browser.form(action: /no_such_action/)).to_not exist 40 | expect(browser.form(index: 1337)).to_not exist 41 | expect(browser.form(xpath: "//form[@id='no_such_id']")).to_not exist 42 | end 43 | 44 | it "raises TypeError when 'what' argument is invalid" do 45 | expect { browser.form(id: 3.14).exists? }.to raise_error(TypeError) 46 | end 47 | 48 | it "raises MissingWayOfFindingObjectException when 'how' argument is invalid" do 49 | expect { browser.form(no_such_how: 'some_value').exists? }.to raise_error(Watir::Exception::MissingWayOfFindingObjectException) 50 | end 51 | end 52 | 53 | bug "https://bugzilla.mozilla.org/show_bug.cgi?id=1290985", :firefox do 54 | describe "#submit" do 55 | it "submits the form" do 56 | browser.form(id: "delete_user").submit 57 | Watir::Wait.until { !browser.url.include? 'forms_with_input_elements.html' } 58 | expect(browser.text).to include("Semantic table") 59 | end 60 | 61 | it "triggers onsubmit event and takes its result into account" do 62 | form = browser.form(name: "user_new") 63 | form.submit 64 | expect(form).to exist 65 | expect(messages.size).to eq 1 66 | expect(messages[0]).to eq "submit" 67 | end 68 | end 69 | end 70 | 71 | end 72 | -------------------------------------------------------------------------------- /tr_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require File.expand_path("../spec_helper", __FILE__) 3 | 4 | describe "TableRow" do 5 | 6 | before :each do 7 | browser.goto(WatirSpec.url_for("tables.html")) 8 | end 9 | 10 | describe "#exists?" do 11 | it "returns true if the table row exists" do 12 | expect(browser.tr(id: "outer_first")).to exist 13 | expect(browser.tr(id: /outer_first/)).to exist 14 | expect(browser.tr(index: 0)).to exist 15 | browser.tr(xpath: "//tr[@id='outer_first']") 16 | end 17 | 18 | it "returns the first row if given no args" do 19 | expect(browser.tr).to exist 20 | end 21 | 22 | it "returns false if the table row doesn't exist" do 23 | expect(browser.tr(id: "no_such_id")).to_not exist 24 | expect(browser.tr(id: /no_such_id/)).to_not exist 25 | expect(browser.tr(index: 1337)).to_not exist 26 | browser.tr(xpath: "//tr[@id='no_such_id']") 27 | end 28 | 29 | it "raises TypeError when 'what' argument is invalid" do 30 | expect { browser.tr(id: 3.14).exists? }.to raise_error(TypeError) 31 | end 32 | 33 | it "raises MissingWayOfFindingObjectException when 'how' argument is invalid" do 34 | expect { browser.tr(no_such_how: 'some_value').exists? }.to raise_error(Watir::Exception::MissingWayOfFindingObjectException) 35 | end 36 | end 37 | 38 | describe "#click" do 39 | bug "http://github.com/watir/watir/issues/issue/32", :internet_explorer, :chrome do 40 | it "fires the row's onclick event" do 41 | browser.tr(id: 'inner_first').click 42 | expect(messages).to include('tr') 43 | end 44 | end 45 | end 46 | 47 | describe "#[]" do 48 | let(:table) { browser.table(id: 'outer') } 49 | 50 | it "returns the nth cell of the row" do 51 | expect(table[0][0].text).to eq "Table 1, Row 1, Cell 1" 52 | expect(table[2][0].text).to eq "Table 1, Row 3, Cell 1" 53 | end 54 | end 55 | 56 | describe "#cells" do 57 | let(:table) { browser.table(id: 'outer') } 58 | 59 | it "returns the correct number of cells" do 60 | expect(table[0].cells.length).to eq 2 61 | expect(table[1].cells.length).to eq 2 62 | expect(table[2].cells.length).to eq 2 63 | end 64 | 65 | it "finds cells in the table" do 66 | expect(table[0].cells(text: /Table 1/).size).to eq 2 67 | end 68 | 69 | it "does not find cells from nested tables" do 70 | expect(table[1].cell(id: "t2_r1_c1")).to_not exist 71 | expect(table[1].cell(id: /t2_r1_c1/)).to_not exist 72 | end 73 | 74 | it "iterates correctly through the cells of the row" do 75 | browser.table(id: 'outer').row(index: 1).cells.each_with_index do |cell, idx| 76 | expect(cell.id).to eq "t1_r2_c#{idx + 1}" 77 | end 78 | end 79 | end 80 | 81 | end 82 | -------------------------------------------------------------------------------- /area_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require File.expand_path("../spec_helper", __FILE__) 3 | 4 | describe "Area" do 5 | 6 | before :each do 7 | browser.goto(WatirSpec.url_for("images.html")) 8 | end 9 | 10 | # Exists method 11 | describe "#exist?" do 12 | it "returns true if the area exists" do 13 | expect(browser.area(id: "NCE")).to exist 14 | expect(browser.area(id: /NCE/)).to exist 15 | expect(browser.area(title: "Tables")).to exist 16 | expect(browser.area(title: /Tables/)).to exist 17 | 18 | not_compliant_on :internet_explorer do 19 | expect(browser.area(href: "tables.html")).to exist 20 | end 21 | 22 | expect(browser.area(href: /tables/)).to exist 23 | 24 | expect(browser.area(index: 0)).to exist 25 | expect(browser.area(xpath: "//area[@id='NCE']")).to exist 26 | end 27 | 28 | it "returns the first area if given no args" do 29 | expect(browser.area).to exist 30 | end 31 | 32 | it "returns false if the area doesn't exist" do 33 | expect(browser.area(id: "no_such_id")).to_not exist 34 | expect(browser.area(id: /no_such_id/)).to_not exist 35 | expect(browser.area(title: "no_such_title")).to_not exist 36 | expect(browser.area(title: /no_such_title/)).to_not exist 37 | 38 | expect(browser.area(href: "no-tables.html")).to_not exist 39 | expect(browser.area(href: /no-tables/)).to_not exist 40 | 41 | expect(browser.area(index: 1337)).to_not exist 42 | expect(browser.area(xpath: "//area[@id='no_such_id']")).to_not exist 43 | end 44 | 45 | it "raises TypeError when 'what' argument is invalid" do 46 | expect { browser.area(id: 3.14).exists? }.to raise_error(TypeError) 47 | end 48 | 49 | it "raises MissingWayOfFindingObjectException when 'how' argument is invalid" do 50 | expect { browser.area(no_such_how: 'some_value').exists? }.to raise_error(Watir::Exception::MissingWayOfFindingObjectException) 51 | end 52 | end 53 | 54 | # Attribute methods 55 | describe "#id" do 56 | it "returns the id attribute" do 57 | expect(browser.area(index: 0).id).to eq "NCE" 58 | end 59 | 60 | it "returns an empty string if the element exists and the attribute doesn't" do 61 | expect(browser.area(index: 2).id).to eq '' 62 | end 63 | 64 | it "raises UnknownObjectException if the area doesn't exist" do 65 | expect { browser.area(id: "no_such_id").id }.to raise_error(Watir::Exception::UnknownObjectException) 66 | expect { browser.area(index: 1337).id }.to raise_error(Watir::Exception::UnknownObjectException) 67 | end 68 | 69 | end 70 | 71 | describe "#respond_to?" do 72 | it "returns true for all attribute methods" do 73 | expect(browser.area(index: 0)).to respond_to(:id) 74 | end 75 | end 76 | 77 | end 78 | -------------------------------------------------------------------------------- /label_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require File.expand_path("../spec_helper", __FILE__) 3 | 4 | describe "Label" do 5 | 6 | before :each do 7 | browser.goto(WatirSpec.url_for("forms_with_input_elements.html")) 8 | end 9 | 10 | # Exists method 11 | describe "#exists?" do 12 | it "returns true if the element exists" do 13 | expect(browser.label(id: 'first_label')).to exist 14 | expect(browser.label(id: /first_label/)).to exist 15 | expect(browser.label(for: "new_user_first_name")).to exist 16 | expect(browser.label(for: /new_user_first_name/)).to exist 17 | expect(browser.label(text: 'First name')).to exist 18 | expect(browser.label(text: /First name/)).to exist 19 | expect(browser.label(index: 0)).to exist 20 | expect(browser.label(xpath: "//label[@id='first_label']")).to exist 21 | end 22 | 23 | it "returns the first label if given no args" do 24 | expect(browser.label).to exist 25 | end 26 | 27 | it "returns false if the element does not exist" do 28 | expect(browser.label(id: 'no_such_id')).to_not exist 29 | expect(browser.label(id: /no_such_id/)).to_not exist 30 | expect(browser.label(text: 'no_such_text')).to_not exist 31 | expect(browser.label(text: /no_such_text/)).to_not exist 32 | expect(browser.label(index: 1337)).to_not exist 33 | expect(browser.label(xpath: "//input[@id='no_such_id']")).to_not exist 34 | end 35 | 36 | it "raises TypeError when 'what' argument is invalid" do 37 | expect { browser.label(id: 3.14).exists? }.to raise_error(TypeError) 38 | end 39 | 40 | it "raises MissingWayOfFindingObjectException when 'how' argument is invalid" do 41 | expect { browser.label(no_such_how: 'some_value').exists? }.to raise_error(Watir::Exception::MissingWayOfFindingObjectException) 42 | end 43 | end 44 | 45 | describe "click" do 46 | it "fires the onclick event" do 47 | browser.label(id: 'first_label').click 48 | expect(messages.first).to eq 'label' 49 | end 50 | end 51 | 52 | # Attribute methods 53 | describe "#id" do 54 | it "returns the id attribute if the label exists" do 55 | expect(browser.label(index: 0).id).to eq "first_label" 56 | end 57 | 58 | it "raises UnknownObjectException if the label doesn't exist" do 59 | expect { browser.label(index: 1337).id }.to raise_error(Watir::Exception::UnknownObjectException) 60 | end 61 | end 62 | 63 | describe "#for" do 64 | it "returns the 'for' attribute if the label exists" do 65 | expect(browser.label(index: 0).for).to eq "new_user_first_name" 66 | end 67 | 68 | it "raises UnknownObjectException if the label doesn't exist" do 69 | expect { browser.label(index: 1337).for }.to raise_error(Watir::Exception::UnknownObjectException) 70 | end 71 | end 72 | 73 | describe "#respond_to?" do 74 | it "returns true for all attribute methods" do 75 | expect(browser.label(index: 0)).to respond_to(:id) 76 | expect(browser.label(index: 0)).to respond_to(:for) 77 | end 78 | end 79 | 80 | end 81 | -------------------------------------------------------------------------------- /ul_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require File.expand_path("../spec_helper", __FILE__) 3 | 4 | describe "Ul" do 5 | 6 | before :each do 7 | browser.goto(WatirSpec.url_for("non_control_elements.html")) 8 | end 9 | 10 | # Exists method 11 | describe "#exist?" do 12 | it "returns true if the 'ul' exists" do 13 | expect(browser.ul(id: "navbar")).to exist 14 | expect(browser.ul(id: /navbar/)).to exist 15 | expect(browser.ul(index: 0)).to exist 16 | expect(browser.ul(xpath: "//ul[@id='navbar']")).to exist 17 | end 18 | 19 | it "returns the first ul if given no args" do 20 | expect(browser.ul).to exist 21 | end 22 | 23 | it "returns false if the 'ul' doesn't exist" do 24 | expect(browser.ul(id: "no_such_id")).to_not exist 25 | expect(browser.ul(id: /no_such_id/)).to_not exist 26 | expect(browser.ul(text: "no_such_text")).to_not exist 27 | expect(browser.ul(text: /no_such_text/)).to_not exist 28 | expect(browser.ul(class: "no_such_class")).to_not exist 29 | expect(browser.ul(class: /no_such_class/)).to_not exist 30 | expect(browser.ul(index: 1337)).to_not exist 31 | expect(browser.ul(xpath: "//ul[@id='no_such_id']")).to_not exist 32 | end 33 | 34 | it "raises TypeError when 'what' argument is invalid" do 35 | expect { browser.ul(id: 3.14).exists? }.to raise_error(TypeError) 36 | end 37 | 38 | it "raises MissingWayOfFindingObjectException when 'how' argument is invalid" do 39 | expect { browser.ul(no_such_how: 'some_value').exists? }.to raise_error(Watir::Exception::MissingWayOfFindingObjectException) 40 | end 41 | end 42 | 43 | # Attribute methods 44 | describe "#class_name" do 45 | it "returns the class attribute" do 46 | expect(browser.ul(id: 'navbar').class_name).to eq 'navigation' 47 | end 48 | 49 | it "returns an empty string if the element exists and the attribute doesn't" do 50 | expect(browser.ul(index: 1).class_name).to eq '' 51 | end 52 | 53 | it "raises UnknownObjectException if the ul doesn't exist" do 54 | expect { browser.ul(id: 'no_such_id').class_name }.to raise_error(Watir::Exception::UnknownObjectException) 55 | end 56 | end 57 | 58 | describe "#id" do 59 | it "returns the id attribute" do 60 | expect(browser.ul(class: 'navigation').id).to eq "navbar" 61 | end 62 | 63 | it "returns an empty string if the element exists and the attribute doesn't" do 64 | expect(browser.ul(index: 1).id).to eq '' 65 | end 66 | 67 | it "raises UnknownObjectException if the ul doesn't exist" do 68 | expect { browser.ul(id: "no_such_id").id }.to raise_error(Watir::Exception::UnknownObjectException) 69 | expect { browser.ul(index: 1337).id }.to raise_error(Watir::Exception::UnknownObjectException) 70 | end 71 | end 72 | 73 | describe "#respond_to?" do 74 | it "returns true for all attribute methods" do 75 | expect(browser.ul(index: 0)).to respond_to(:class_name) 76 | expect(browser.ul(index: 0)).to respond_to(:id) 77 | end 78 | end 79 | 80 | end 81 | -------------------------------------------------------------------------------- /map_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require File.expand_path("../spec_helper", __FILE__) 3 | 4 | describe "Map" do 5 | 6 | before :each do 7 | browser.goto(WatirSpec.url_for("images.html")) 8 | end 9 | 10 | # Exists method 11 | describe "#exist?" do 12 | it "returns true if the 'map' exists" do 13 | expect(browser.map(id: "triangle_map")).to exist 14 | expect(browser.map(id: /triangle_map/)).to exist 15 | expect(browser.map(name: "triangle_map")).to exist 16 | expect(browser.map(name: /triangle_map/)).to exist 17 | expect(browser.map(index: 0)).to exist 18 | expect(browser.map(xpath: "//map[@id='triangle_map']")).to exist 19 | end 20 | 21 | it "returns the first map if given no args" do 22 | expect(browser.map).to exist 23 | end 24 | 25 | it "returns false if the 'map' doesn't exist" do 26 | expect(browser.map(id: "no_such_id")).to_not exist 27 | expect(browser.map(id: /no_such_id/)).to_not exist 28 | expect(browser.map(name: "no_such_id")).to_not exist 29 | expect(browser.map(name: /no_such_id/)).to_not exist 30 | expect(browser.map(index: 1337)).to_not exist 31 | expect(browser.map(xpath: "//map[@id='no_such_id']")).to_not exist 32 | end 33 | 34 | it "raises TypeError when 'what' argument is invalid" do 35 | expect { browser.map(id: 3.14).exists? }.to raise_error(TypeError) 36 | end 37 | 38 | it "raises MissingWayOfFindingObjectException when 'how' argument is invalid" do 39 | expect { browser.map(no_such_how: 'some_value').exists? }.to raise_error(Watir::Exception::MissingWayOfFindingObjectException) 40 | end 41 | end 42 | 43 | # Attribute methods 44 | describe "#id" do 45 | it "returns the id attribute" do 46 | expect(browser.map(index: 0).id).to eq "triangle_map" 47 | end 48 | 49 | it "returns an empty string if the element exists and the attribute doesn't" do 50 | expect(browser.map(index: 1).id).to eq '' 51 | end 52 | 53 | it "raises UnknownObjectException if the p doesn't exist" do 54 | expect { browser.map(id: "no_such_id").id }.to raise_error(Watir::Exception::UnknownObjectException) 55 | expect { browser.map(index: 1337).id }.to raise_error(Watir::Exception::UnknownObjectException) 56 | end 57 | end 58 | 59 | describe "#name" do 60 | it "returns the name attribute" do 61 | expect(browser.map(index: 0).name).to eq "triangle_map" 62 | end 63 | 64 | it "returns an empty string if the element exists and the attribute doesn't" do 65 | expect(browser.map(index: 1).name).to eq '' 66 | end 67 | 68 | it "raises UnknownObjectException if the map doesn't exist" do 69 | expect { browser.map(id: "no_such_id").name }.to raise_error(Watir::Exception::UnknownObjectException) 70 | expect { browser.map(index: 1337).name }.to raise_error(Watir::Exception::UnknownObjectException) 71 | end 72 | end 73 | 74 | describe "#respond_to?" do 75 | it "returns true for all attribute methods" do 76 | expect(browser.map(index: 0)).to respond_to(:id) 77 | expect(browser.map(index: 0)).to respond_to(:name) 78 | end 79 | end 80 | end 81 | -------------------------------------------------------------------------------- /html/drag_and_drop.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | jQuery UI Droppable - Default Demo 6 | 7 | 8 | 9 | 13 | 14 | 79 | 80 | 81 | 82 | 83 | 84 |
85 | 86 |
87 |

Drag me to my target

88 |
89 | 90 |
91 |

Drop here

92 |
93 | 94 |
95 |

start

96 |
97 | 98 |
99 | 100 |
101 | 102 |

Taken from the JQuery demo.

103 | 104 |
105 | 106 | 107 | -------------------------------------------------------------------------------- /alert_spec.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path("../spec_helper", __FILE__) 2 | 3 | describe 'Alert API' do 4 | bug "https://github.com/detro/ghostdriver/issues/20", :phantomjs do 5 | not_compliant_on :safari do 6 | before do 7 | browser.goto WatirSpec.url_for("alerts.html") 8 | end 9 | 10 | after do 11 | browser.alert.ok if browser.alert.exists? 12 | end 13 | 14 | context 'alert' do 15 | describe '#text' do 16 | it 'returns text of alert' do 17 | browser.button(id: 'alert').click 18 | expect(browser.alert.text).to include('ok') 19 | end 20 | end 21 | 22 | describe '#exists?' do 23 | it 'returns false if alert is not present' do 24 | expect(browser.alert).to_not exist 25 | end 26 | 27 | it 'returns true if alert is present' do 28 | browser.button(id: 'alert').click 29 | browser.wait_until(10) { browser.alert.exists? } 30 | end 31 | end 32 | 33 | describe '#ok' do 34 | it 'closes alert' do 35 | browser.button(id: 'alert').click 36 | browser.alert.ok 37 | expect(browser.alert).to_not exist 38 | end 39 | end 40 | 41 | bug "https://code.google.com/p/chromedriver/issues/detail?id=26", [:chrome, :macosx] do 42 | describe '#close' do 43 | it 'closes alert' do 44 | browser.button(id: 'alert').click 45 | browser.alert.when_present.close 46 | expect(browser.alert).to_not exist 47 | end 48 | end 49 | end 50 | 51 | describe 'when_present' do 52 | it 'waits until alert is present and goes on' do 53 | browser.button(id: 'timeout-alert').click 54 | browser.alert.when_present.ok 55 | 56 | expect(browser.alert).to_not exist 57 | end 58 | 59 | it 'raises error if alert is not present after timeout' do 60 | expect { 61 | browser.alert.when_present(0.1).ok 62 | }.to raise_error(Watir::Wait::TimeoutError) 63 | end 64 | end 65 | end 66 | 67 | context 'confirm' do 68 | describe '#ok' do 69 | it 'accepts confirm' do 70 | browser.button(id: 'confirm').click 71 | browser.alert.ok 72 | expect(browser.button(id: 'confirm').value).to eq "true" 73 | end 74 | end 75 | 76 | describe '#close' do 77 | it 'cancels confirm' do 78 | browser.button(id: 'confirm').click 79 | browser.alert.when_present.close 80 | expect(browser.button(id: 'confirm').value).to eq "false" 81 | end 82 | end 83 | end 84 | 85 | context 'prompt' do 86 | describe '#set' do 87 | bug "https://bugzilla.mozilla.org/show_bug.cgi?id=1255906", :firefox do 88 | it 'enters text to prompt' do 89 | browser.button(id: 'prompt').click 90 | browser.alert.set 'My Name' 91 | browser.alert.ok 92 | expect(browser.button(id: 'prompt').value).to eq 'My Name' 93 | end 94 | end 95 | end 96 | end 97 | end 98 | end 99 | end 100 | -------------------------------------------------------------------------------- /lib/watirspec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | 3 | # see http://redmine.ruby-lang.org/issues/5218 4 | if defined?(RUBY_ENGINE) && RUBY_ENGINE == "ruby" && RUBY_VERSION >= "1.9" 5 | module Kernel 6 | alias :__at_exit :at_exit 7 | def at_exit(&block) 8 | __at_exit do 9 | exit_status = $!.status if $!.is_a?(SystemExit) 10 | block.call 11 | exit exit_status if exit_status 12 | end 13 | end 14 | end 15 | end 16 | 17 | module WatirSpec 18 | class << self 19 | attr_accessor :browser_args, :persistent_browser, :unguarded, :implementation, :always_use_server 20 | 21 | def html 22 | @html ||= File.expand_path("../../html", __FILE__) 23 | end 24 | 25 | def url_for(str, opts = {}) 26 | if opts[:needs_server] || always_use_server 27 | File.join(host, str) 28 | else 29 | File.join(files, str) 30 | end 31 | end 32 | 33 | def files 34 | @files ||= "file://#{html}" 35 | end 36 | 37 | def host 38 | @host ||= "http://#{Server.bind}:#{Server.port}" 39 | end 40 | 41 | def unguarded? 42 | @unguarded ||= false 43 | end 44 | 45 | def platform 46 | @platform ||= case RUBY_PLATFORM 47 | when /java/ 48 | :java 49 | when /mswin|msys|mingw32/ 50 | :windows 51 | when /darwin/ 52 | :macosx 53 | when /linux/ 54 | :linux 55 | else 56 | RUBY_PLATFORM 57 | end 58 | end 59 | 60 | def implementation 61 | @implementation ||= ( 62 | imp = WatirSpec::Implementation.new 63 | yield imp if block_given? 64 | 65 | imp 66 | ) 67 | end 68 | 69 | def implementation=(imp) 70 | unless imp.kind_of? WatirSpec::Implementation 71 | raise TypeError, "expected WatirSpec::Implementation, got #{imp.class}" 72 | end 73 | 74 | @implementation = imp 75 | end 76 | 77 | def new_browser 78 | klass = WatirSpec.implementation.browser_class 79 | args = Array(WatirSpec.implementation.browser_args).map { |e| Hash === e ? e.dup : e } 80 | 81 | instance = klass.new(*args) 82 | print_browser_info_once(instance) 83 | 84 | instance 85 | end 86 | 87 | def ruby 88 | @ruby ||= ( 89 | if defined?(Gem) 90 | Gem.ruby 91 | else 92 | require "rbconfig" 93 | rb = File.join(RbConfig::CONFIG.values_at('BINDIR', 'RUBY_INSTALL_NAME').compact) 94 | ext = RbConfig::CONFIG['EXEEXT'] 95 | 96 | "#{rb}#{ext}" 97 | end 98 | ) 99 | end 100 | 101 | private 102 | 103 | def print_browser_info_once(instance) 104 | return if defined?(@did_print_browser_info) && @did_print_browser_info 105 | @did_print_browser_info = true 106 | 107 | info = [] 108 | info << instance.class.name 109 | 110 | if instance.respond_to?(:driver) && instance.driver.class.name == "Selenium::WebDriver::Driver" 111 | info << "(webdriver)" 112 | caps = instance.driver.capabilities 113 | 114 | info << "#{caps.browser_name}" 115 | info << "#{caps.version}" 116 | end 117 | 118 | $stderr.puts "running watirspec against #{info.join ' '} using args #{WatirSpec.implementation.browser_args.inspect}" 119 | rescue 120 | # ignored 121 | end 122 | 123 | end # class << WatirSpec 124 | end # WatirSpec 125 | -------------------------------------------------------------------------------- /ol_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require File.expand_path("../spec_helper", __FILE__) 3 | 4 | describe "Ol" do 5 | 6 | before :each do 7 | browser.goto(WatirSpec.url_for("non_control_elements.html")) 8 | end 9 | 10 | # Exists method 11 | describe "#exist?" do 12 | it "returns true if the 'ol' exists" do 13 | expect(browser.ol(id: "favorite_compounds")).to exist 14 | expect(browser.ol(id: /favorite_compounds/)).to exist 15 | expect(browser.ol(index: 0)).to exist 16 | expect(browser.ol(xpath: "//ol[@id='favorite_compounds']")).to exist 17 | end 18 | 19 | it "returns the first ol if given no args" do 20 | expect(browser.ol).to exist 21 | end 22 | 23 | it "returns false if the 'ol' doesn't exist" do 24 | expect(browser.ol(id: "no_such_id")).to_not exist 25 | expect(browser.ol(id: /no_such_id/)).to_not exist 26 | expect(browser.ol(text: "no_such_text")).to_not exist 27 | expect(browser.ol(text: /no_such_text/)).to_not exist 28 | expect(browser.ol(class: "no_such_class")).to_not exist 29 | expect(browser.ol(class: /no_such_class/)).to_not exist 30 | expect(browser.ol(index: 1337)).to_not exist 31 | expect(browser.ol(xpath: "//ol[@id='no_such_id']")).to_not exist 32 | end 33 | 34 | it "returns false if the 'ol' doesn't exist" do 35 | expect(browser.ol(id: "no_such_id")).to_not exist 36 | expect(browser.ol(id: /no_such_id/)).to_not exist 37 | expect(browser.ol(text: "no_such_text")).to_not exist 38 | expect(browser.ol(text: /no_such_text/)).to_not exist 39 | expect(browser.ol(class: "no_such_class")).to_not exist 40 | expect(browser.ol(class: /no_such_class/)).to_not exist 41 | expect(browser.ol(index: 1337)).to_not exist 42 | expect(browser.ol(xpath: "//ol[@id='no_such_id']")).to_not exist 43 | end 44 | 45 | it "raises TypeError when 'what' argument is invalid" do 46 | expect { browser.ol(id: 3.14).exists? }.to raise_error(TypeError) 47 | end 48 | 49 | it "raises MissingWayOfFindingObjectException when 'how' argument is invalid" do 50 | expect { browser.ol(no_such_how: 'some_value').exists? }.to raise_error(Watir::Exception::MissingWayOfFindingObjectException) 51 | end 52 | end 53 | 54 | # Attribute methods 55 | describe "#class_name" do 56 | it "returns the class attribute" do 57 | expect(browser.ol(id: 'favorite_compounds').class_name).to eq 'chemistry' 58 | end 59 | 60 | it "returns an empty string if the element exists and the attribute doesn't" do 61 | expect(browser.ol(index: 1).class_name).to eq '' 62 | end 63 | 64 | it "raises UnknownObjectException if the ol doesn't exist" do 65 | expect { browser.ol(id: 'no_such_id').class_name }.to raise_error(Watir::Exception::UnknownObjectException) 66 | end 67 | end 68 | 69 | describe "#id" do 70 | it "returns the id attribute" do 71 | expect(browser.ol(class: 'chemistry').id).to eq "favorite_compounds" 72 | end 73 | 74 | it "returns an empty string if the element exists and the attribute doesn't" do 75 | expect(browser.ol(index: 1).id).to eq '' 76 | end 77 | 78 | it "raises UnknownObjectException if the ol doesn't exist" do 79 | expect { browser.ol(id: "no_such_id").id }.to raise_error(Watir::Exception::UnknownObjectException) 80 | expect { browser.ol(index: 1337).id }.to raise_error(Watir::Exception::UnknownObjectException) 81 | end 82 | end 83 | 84 | describe "#respond_to?" do 85 | it "returns true for all attribute methods" do 86 | expect(browser.ol(index: 0)).to respond_to(:class_name) 87 | expect(browser.ol(index: 0)).to respond_to(:id) 88 | end 89 | end 90 | end 91 | -------------------------------------------------------------------------------- /hn_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require File.expand_path("../spec_helper", __FILE__) 3 | 4 | describe ["H1", "H2", "H3", "H4", "H5", "H6"] do 5 | 6 | before :each do 7 | browser.goto(WatirSpec.url_for("non_control_elements.html")) 8 | end 9 | 10 | # Exists method 11 | describe "#exist?" do 12 | it "returns true if the element exists" do 13 | expect(browser.h1(id: "header1")).to exist 14 | expect(browser.h2(id: /header2/)).to exist 15 | expect(browser.h3(text: "Header 3")).to exist 16 | expect(browser.h4(text: /Header 4/)).to exist 17 | expect(browser.h5(index: 0)).to exist 18 | expect(browser.h6(index: 0)).to exist 19 | expect(browser.h1(xpath: "//h1[@id='first_header']")).to exist 20 | end 21 | 22 | it "returns the first h1 if given no args" do 23 | expect(browser.h1).to exist 24 | end 25 | 26 | it "returns true if the element exists" do 27 | expect(browser.h1(id: "no_such_id")).to_not exist 28 | expect(browser.h1(id: /no_such_id/)).to_not exist 29 | expect(browser.h1(text: "no_such_text")).to_not exist 30 | expect(browser.h1(text: /no_such_text 1/)).to_not exist 31 | expect(browser.h1(index: 1337)).to_not exist 32 | expect(browser.h1(xpath: "//p[@id='no_such_id']")).to_not exist 33 | end 34 | 35 | it "raises TypeError when 'what' argument is invalid" do 36 | expect { browser.h1(id: 3.14).exists? }.to raise_error(TypeError) 37 | end 38 | 39 | it "raises MissingWayOfFindingObjectException when 'how' argument is invalid" do 40 | expect { browser.h1(no_such_how: 'some_value').exists? }.to raise_error(Watir::Exception::MissingWayOfFindingObjectException) 41 | end 42 | end 43 | 44 | # Attribute methods 45 | describe "#class_name" do 46 | it "returns the class attribute" do 47 | expect(browser.h1(index: 0).class_name).to eq 'primary' 48 | end 49 | 50 | it "returns an empty string if the element exists and the attribute doesn't" do 51 | expect(browser.h2(index: 0).class_name).to eq '' 52 | end 53 | 54 | it "raises UnknownObjectException if the p doesn't exist" do 55 | expect { browser.h2(id: 'no_such_id').class_name }.to raise_error(Watir::Exception::UnknownObjectException) 56 | end 57 | end 58 | 59 | describe "#id" do 60 | it "returns the id attribute" do 61 | expect(browser.h1(index: 0).id).to eq "first_header" 62 | end 63 | 64 | it "returns an empty string if the element exists and the attribute doesn't" do 65 | expect(browser.h3(index: 0).id).to eq '' 66 | end 67 | 68 | it "raises UnknownObjectException if the p doesn't exist" do 69 | expect { browser.h1(id: "no_such_id").id }.to raise_error(Watir::Exception::UnknownObjectException) 70 | expect { browser.h1(index: 1337).id }.to raise_error(Watir::Exception::UnknownObjectException) 71 | end 72 | end 73 | 74 | describe "#text" do 75 | it "returns the text of the element" do 76 | expect(browser.h1(index: 0).text).to eq 'Header 1' 77 | end 78 | 79 | it "returns an empty string if the element doesn't contain any text" do 80 | expect(browser.h6(id: "empty_header").text).to eq '' 81 | end 82 | 83 | it "raises UnknownObjectException if the p doesn't exist" do 84 | expect { browser.h1(id: 'no_such_id').text }.to raise_error(Watir::Exception::UnknownObjectException) 85 | expect { browser.h1(:xpath , "//h1[@id='no_such_id']").text }.to raise_error(Watir::Exception::UnknownObjectException) 86 | end 87 | end 88 | 89 | describe "#respond_to?" do 90 | it "returns true for all attribute methods" do 91 | expect(browser.h1(index: 0)).to respond_to(:class_name) 92 | expect(browser.h1(index: 0)).to respond_to(:id) 93 | expect(browser.h1(index: 0)).to respond_to(:text) 94 | end 95 | end 96 | 97 | end 98 | -------------------------------------------------------------------------------- /strong_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require File.expand_path("../spec_helper", __FILE__) 3 | 4 | describe "Strong" do 5 | 6 | before :each do 7 | browser.goto(WatirSpec.url_for("non_control_elements.html")) 8 | end 9 | 10 | # Exists method 11 | describe "#exist?" do 12 | it "returns true if the element exists" do 13 | expect(browser.strong(id: "descartes")).to exist 14 | expect(browser.strong(id: /descartes/)).to exist 15 | expect(browser.strong(text: "Dubito, ergo cogito, ergo sum.")).to exist 16 | expect(browser.strong(text: /Dubito, ergo cogito, ergo sum/)).to exist 17 | expect(browser.strong(class: "descartes")).to exist 18 | expect(browser.strong(class: /descartes/)).to exist 19 | expect(browser.strong(index: 0)).to exist 20 | expect(browser.strong(xpath: "//strong[@id='descartes']")).to exist 21 | end 22 | 23 | it "returns the first strong if given no args" do 24 | expect(browser.strong).to exist 25 | end 26 | 27 | it "returns false if the element doesn't exist" do 28 | expect(browser.strong(id: "no_such_id")).to_not exist 29 | expect(browser.strong(id: /no_such_id/)).to_not exist 30 | expect(browser.strong(text: "no_such_text")).to_not exist 31 | expect(browser.strong(text: /no_such_text/)).to_not exist 32 | expect(browser.strong(class: "no_such_class")).to_not exist 33 | expect(browser.strong(class: /no_such_class/)).to_not exist 34 | expect(browser.strong(index: 1337)).to_not exist 35 | expect(browser.strong(xpath: "//strong[@id='no_such_id']")).to_not exist 36 | end 37 | 38 | it "raises TypeError when 'what' argument is invalid" do 39 | expect { browser.strong(id: 3.14).exists? }.to raise_error(TypeError) 40 | end 41 | 42 | it "raises MissingWayOfFindingObjectException when 'how' argument is invalid" do 43 | expect { browser.strong(no_such_how: 'some_value').exists? }.to raise_error(Watir::Exception::MissingWayOfFindingObjectException) 44 | end 45 | end 46 | 47 | # Attribute methods 48 | describe "#class_name" do 49 | it "returns the class attribute" do 50 | expect(browser.strong(index: 0).class_name).to eq 'descartes' 51 | end 52 | 53 | it "returns an empty string if the element exists and the attribute doesn't" do 54 | expect(browser.strong(index: 1).class_name).to eq '' 55 | end 56 | 57 | it "raises UnknownObjectException if the element doesn't exist" do 58 | expect { browser.strong(id: 'no_such_id').class_name }.to raise_error(Watir::Exception::UnknownObjectException) 59 | end 60 | end 61 | 62 | describe "#id" do 63 | it "returns the id attribute" do 64 | expect(browser.strong(index: 0).id).to eq "descartes" 65 | end 66 | 67 | it "raises UnknownObjectException if the element doesn't exist" do 68 | expect { browser.strong(id: "no_such_id").id }.to raise_error(Watir::Exception::UnknownObjectException) 69 | expect { browser.strong(index: 1337).id }.to raise_error(Watir::Exception::UnknownObjectException) 70 | end 71 | end 72 | 73 | describe "#text" do 74 | it "returns the text of the element" do 75 | expect(browser.strong(index: 0).text).to eq "Dubito, ergo cogito, ergo sum." 76 | end 77 | 78 | it "raises UnknownObjectException if the element doesn't exist" do 79 | expect { browser.strong(id: 'no_such_id').text }.to raise_error(Watir::Exception::UnknownObjectException) 80 | expect { browser.strong(:xpath , "//strong[@id='no_such_id']").text }.to raise_error(Watir::Exception::UnknownObjectException) 81 | end 82 | end 83 | 84 | describe "#respond_to?" do 85 | it "returns true for all attribute methods" do 86 | expect(browser.strong(index: 0)).to respond_to(:class_name) 87 | expect(browser.strong(index: 0)).to respond_to(:id) 88 | expect(browser.strong(index: 0)).to respond_to(:text) 89 | end 90 | end 91 | 92 | # Other 93 | end 94 | -------------------------------------------------------------------------------- /tfoot_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require File.expand_path("../spec_helper", __FILE__) 3 | 4 | describe "TableFooter" do 5 | before :each do 6 | browser.goto(WatirSpec.url_for("tables.html")) 7 | end 8 | 9 | describe "#exists?" do 10 | it "returns true if the table tfoot exists (page context)" do 11 | expect(browser.tfoot(id: 'tax_totals')).to exist 12 | expect(browser.tfoot(id: /tax_totals/)).to exist 13 | expect(browser.tfoot(index: 0)).to exist 14 | expect(browser.tfoot(xpath: "//tfoot[@id='tax_totals']")).to exist 15 | end 16 | 17 | it "returns true if the table tfoot exists (table context)" do 18 | expect(browser.table(index: 0).tfoot(id: 'tax_totals')).to exist 19 | expect(browser.table(index: 0).tfoot(id: /tax_totals/)).to exist 20 | expect(browser.table(index: 0).tfoot(index: 0)).to exist 21 | expect(browser.table(index: 0).tfoot(xpath: "//tfoot[@id='tax_totals']")).to exist 22 | end 23 | 24 | it "returns the first tfoot if given no args" do 25 | expect(browser.tfoot).to exist 26 | end 27 | 28 | it "returns false if the table tfoot doesn't exist (page context)" do 29 | expect(browser.tfoot(id: 'no_such_id')).to_not exist 30 | expect(browser.tfoot(id: /no_such_id/)).to_not exist 31 | expect(browser.tfoot(index: 1337)).to_not exist 32 | expect(browser.tfoot(xpath: "//tfoot[@id='no_such_id']")).to_not exist 33 | end 34 | 35 | it "returns false if the table tfoot doesn't exist (table context)" do 36 | expect(browser.table(index: 0).tfoot(id: 'no_such_id')).to_not exist 37 | expect(browser.table(index: 0).tfoot(id: /no_such_id/)).to_not exist 38 | expect(browser.table(index: 0).tfoot(index: 1337)).to_not exist 39 | expect(browser.table(index: 0).tfoot(xpath: "//tfoot[@id='no_such_id']")).to_not exist 40 | end 41 | 42 | it "raises TypeError when 'what' argument is invalid" do 43 | expect { browser.tfoot(id: 3.14).exists? }.to raise_error(TypeError) 44 | expect { browser.table(index: 0).tfoot(id: 3.14).exists? }.to raise_error(TypeError) 45 | end 46 | 47 | it "raises MissingWayOfFindingObjectException when 'how' argument is invalid" do 48 | expect { browser.tfoot(no_such_how: 'some_value').exists? }.to raise_error(Watir::Exception::MissingWayOfFindingObjectException) 49 | expect { browser.table(index: 0).tfoot(no_such_how: 'some_value').exists? }.to raise_error(Watir::Exception::MissingWayOfFindingObjectException) 50 | end 51 | end 52 | 53 | describe "#[]" do 54 | it "returns the row at the given index (page context)" do 55 | expect(browser.tfoot(id: 'tax_totals')[0].id).to eq 'tfoot_row_1' 56 | expect(browser.tfoot(id: 'tax_totals')[0][1].text).to eq '24 349' 57 | expect(browser.tfoot(id: 'tax_totals')[0][2].text).to eq '5 577' 58 | end 59 | 60 | it "returns the row at the given index (table context)" do 61 | expect(browser.table(index: 0).tfoot(id: 'tax_totals')[0].id).to eq "tfoot_row_1" 62 | expect(browser.table(index: 0).tfoot(id: 'tax_totals')[0][1].text).to eq '24 349' 63 | expect(browser.table(index: 0).tfoot(id: 'tax_totals')[0][2].text).to eq '5 577' 64 | end 65 | end 66 | 67 | describe "#row" do 68 | it "finds the first row matching the selector" do 69 | row = browser.tfoot(id: 'tax_totals').row(id: "tfoot_row_1") 70 | 71 | expect(row.id).to eq "tfoot_row_1" 72 | end 73 | end 74 | 75 | describe "#rows" do 76 | it "finds rows matching the selector" do 77 | rows = browser.tfoot(id: 'tax_totals').rows(id: "tfoot_row_1") 78 | 79 | expect(rows.size).to eq 1 80 | expect(rows.first.id).to eq "tfoot_row_1" 81 | end 82 | end 83 | 84 | describe "#strings" do 85 | it "returns the text of child cells" do 86 | expect(browser.tfoot(id: 'tax_totals').strings).to eq [ 87 | ["Sum", "24 349", "5 577", "18 722"] 88 | ] 89 | end 90 | end 91 | 92 | end 93 | -------------------------------------------------------------------------------- /thead_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require File.expand_path("../spec_helper", __FILE__) 3 | 4 | describe "TableHeader" do 5 | 6 | before :each do 7 | browser.goto(WatirSpec.url_for("tables.html")) 8 | end 9 | 10 | describe "#exists?" do 11 | it "returns true if the table theader exists (page context)" do 12 | expect(browser.thead(id: 'tax_headers')).to exist 13 | expect(browser.thead(id: /tax_headers/)).to exist 14 | expect(browser.thead(index: 0)).to exist 15 | expect(browser.thead(xpath: "//thead[@id='tax_headers']")).to exist 16 | end 17 | 18 | it "returns the first thead if given no args" do 19 | expect(browser.thead).to exist 20 | end 21 | 22 | it "returns true if the table theader exists (table context)" do 23 | expect(browser.table(index: 0).thead(id: 'tax_headers')).to exist 24 | expect(browser.table(index: 0).thead(id: /tax_headers/)).to exist 25 | expect(browser.table(index: 0).thead(index: 0)).to exist 26 | expect(browser.table(index: 0).thead(xpath: "//thead[@id='tax_headers']")).to exist 27 | end 28 | 29 | it "returns false if the table theader doesn't exist (page context)" do 30 | expect(browser.thead(id: 'no_such_id')).to_not exist 31 | expect(browser.thead(id: /no_such_id/)).to_not exist 32 | expect(browser.thead(index: 1337)).to_not exist 33 | expect(browser.thead(xpath: "//thead[@id='no_such_id']")).to_not exist 34 | end 35 | 36 | it "returns false if the table theader doesn't exist (table context)" do 37 | expect(browser.table(index: 0).thead(id: 'no_such_id')).to_not exist 38 | expect(browser.table(index: 0).thead(id: /no_such_id/)).to_not exist 39 | expect(browser.table(index: 0).thead(index: 1337)).to_not exist 40 | expect(browser.table(index: 0).thead(xpath: "//thead[@id='no_such_id']")).to_not exist 41 | end 42 | 43 | it "raises TypeError when 'what' argument is invalid" do 44 | expect { browser.thead(id: 3.14).exists? }.to raise_error(TypeError) 45 | expect { browser.table(index: 0).thead(id: 3.14).exists? }.to raise_error(TypeError) 46 | end 47 | 48 | it "raises MissingWayOfFindingObjectException when 'how' argument is invalid" do 49 | expect { browser.thead(no_such_how: 'some_value').exists? }.to raise_error(Watir::Exception::MissingWayOfFindingObjectException) 50 | expect { browser.table(index: 0).thead(no_such_how: 'some_value').exists? }.to raise_error(Watir::Exception::MissingWayOfFindingObjectException) 51 | end 52 | end 53 | 54 | describe "#[]" do 55 | it "returns the row at the given index (page context)" do 56 | expect(browser.thead(id: 'tax_headers')[0].id).to eq 'thead_row_1' 57 | expect(browser.thead(id: 'tax_headers')[0][1].text).to eq 'Before income tax' 58 | expect(browser.thead(id: 'tax_headers')[0][2].text).to eq 'Income tax' 59 | end 60 | 61 | it "returns the row at the given index (table context)" do 62 | expect(browser.table(index: 0).thead(id: 'tax_headers')[0].id).to eq 'thead_row_1' 63 | expect(browser.table(index: 0).thead(id: 'tax_headers')[0][1].text).to eq 'Before income tax' 64 | expect(browser.table(index: 0).thead(id: 'tax_headers')[0][2].text).to eq 'Income tax' 65 | end 66 | end 67 | 68 | describe "#row" do 69 | it "finds the first row matching the selector" do 70 | row = browser.thead(id: 'tax_headers').row(class: "dark") 71 | expect(row.id).to eq "thead_row_1" 72 | end 73 | end 74 | 75 | describe "#rows" do 76 | it "finds rows matching the selector" do 77 | rows = browser.thead(id: 'tax_headers').rows(class: "dark") 78 | 79 | expect(rows.size).to eq 1 80 | expect(rows.first.id).to eq "thead_row_1" 81 | end 82 | end 83 | 84 | describe "#strings" do 85 | it "returns the text of child cells" do 86 | expect(browser.thead(id: 'tax_headers').strings).to eq [ 87 | ["", "Before income tax", "Income tax", "After income tax"] 88 | ] 89 | end 90 | end 91 | 92 | end 93 | -------------------------------------------------------------------------------- /tbody_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require File.expand_path("../spec_helper", __FILE__) 3 | 4 | describe "TableBody" do 5 | 6 | before :each do 7 | browser.goto(WatirSpec.url_for("tables.html")) 8 | end 9 | 10 | describe "#exists?" do 11 | it "returns true if the table body exists (page context)" do 12 | expect(browser.tbody(id: 'first')).to exist 13 | expect(browser.tbody(id: /first/)).to exist 14 | expect(browser.tbody(index: 0)).to exist 15 | expect(browser.tbody(xpath: "//tbody[@id='first']")).to exist 16 | end 17 | 18 | it "returns true if the table body exists (table context)" do 19 | expect(browser.table(index: 0).tbody(id: 'first')).to exist 20 | expect(browser.table(index: 0).tbody(id: /first/)).to exist 21 | expect(browser.table(index: 0).tbody(index: 1)).to exist 22 | expect(browser.table(index: 0).tbody(xpath: "//tbody[@id='first']")).to exist 23 | end 24 | 25 | it "returns the first table body if given no args" do 26 | expect(browser.table.tbody).to exist 27 | end 28 | 29 | it "returns false if the table body doesn't exist (page context)" do 30 | expect(browser.tbody(id: 'no_such_id')).to_not exist 31 | expect(browser.tbody(id: /no_such_id/)).to_not exist 32 | expect(browser.tbody(index: 1337)).to_not exist 33 | expect(browser.tbody(xpath: "//tbody[@id='no_such_id']")).to_not exist 34 | end 35 | 36 | it "returns false if the table body doesn't exist (table context)" do 37 | expect(browser.table(index: 0).tbody(id: 'no_such_id')).to_not exist 38 | expect(browser.table(index: 0).tbody(id: /no_such_id/)).to_not exist 39 | expect(browser.table(index: 0).tbody(index: 1337)).to_not exist 40 | expect(browser.table(index: 0).tbody(xpath: "//tbody[@id='no_such_id']")).to_not exist 41 | end 42 | 43 | it "raises TypeError when 'what' argument is invalid" do 44 | expect { browser.tbody(id: 3.14).exists? }.to raise_error(TypeError) 45 | expect { browser.table(index: 0).tbody(id: 3.14).exists? }.to raise_error(TypeError) 46 | end 47 | 48 | it "raises MissingWayOfFindingObjectException when 'how' argument is invalid" do 49 | expect { browser.tbody(no_such_how: 'some_value').exists? }.to raise_error(Watir::Exception::MissingWayOfFindingObjectException) 50 | expect { browser.table(index: 0).tbody(no_such_how: 'some_value').exists? }.to raise_error(Watir::Exception::MissingWayOfFindingObjectException) 51 | end 52 | end 53 | 54 | describe "#[]" do 55 | it "returns the row at the given index (page context)" do 56 | expect(browser.tbody(id: 'first')[0].text).to eq 'March 2008' 57 | expect(browser.tbody(id: 'first')[1][0].text).to eq 'Gregory House' 58 | expect(browser.tbody(id: 'first')[2][0].text).to eq 'Hugh Laurie' 59 | end 60 | 61 | it "returns the row at the given index (table context)" do 62 | expect(browser.table(index: 0).tbody(id: 'first')[0].text).to eq 'March 2008' 63 | expect(browser.table(index: 0).tbody(id: 'first')[1][0].text).to eq 'Gregory House' 64 | expect(browser.table(index: 0).tbody(id: 'first')[2][0].text).to eq 'Hugh Laurie' 65 | end 66 | end 67 | 68 | describe "#row" do 69 | it "finds the first row matching the selector" do 70 | row = browser.tbody(id: 'first').row(id: "gregory") 71 | 72 | expect(row.tag_name).to eq "tr" 73 | expect(row.id).to eq "gregory" 74 | end 75 | end 76 | 77 | describe "#rows" do 78 | it "finds rows matching the selector" do 79 | rows = browser.tbody(id: 'first').rows(id: /h$/) 80 | 81 | expect(rows.size).to eq 2 82 | 83 | expect(rows.first.id).to eq "march" 84 | expect(rows.last.id).to eq "hugh" 85 | end 86 | end 87 | 88 | describe "#strings" do 89 | it "returns the text of child cells" do 90 | expect(browser.tbody(id: 'first').strings).to eq [ 91 | ["March 2008", "", "", ""], 92 | ["Gregory House", "5 934", "1 347", "4 587"], 93 | ["Hugh Laurie", "6 300", "1 479", "4 821"] 94 | ] 95 | end 96 | end 97 | end 98 | -------------------------------------------------------------------------------- /hidden_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require File.expand_path("../spec_helper", __FILE__) 3 | 4 | describe "Hidden" do 5 | 6 | before :each do 7 | browser.goto(WatirSpec.url_for("forms_with_input_elements.html")) 8 | end 9 | 10 | # Exist method 11 | describe "#exists?" do 12 | it "returns true if the element exists" do 13 | expect(browser.hidden(id: 'new_user_interests_dolls')).to exist 14 | expect(browser.hidden(id: /new_user_interests_dolls/)).to exist 15 | expect(browser.hidden(name: 'new_user_interests')).to exist 16 | expect(browser.hidden(name: /new_user_interests/)).to exist 17 | expect(browser.hidden(value: 'dolls')).to exist 18 | expect(browser.hidden(value: /dolls/)).to exist 19 | expect(browser.hidden(class: 'fun')).to exist 20 | expect(browser.hidden(class: /fun/)).to exist 21 | expect(browser.hidden(index: 0)).to exist 22 | expect(browser.hidden(xpath: "//input[@id='new_user_interests_dolls']")).to exist 23 | end 24 | 25 | it "returns the first hidden if given no args" do 26 | expect(browser.hidden).to exist 27 | end 28 | 29 | it "returns false if the element does not exist" do 30 | expect(browser.hidden(id: 'no_such_id')).to_not exist 31 | expect(browser.hidden(id: /no_such_id/)).to_not exist 32 | expect(browser.hidden(name: 'no_such_name')).to_not exist 33 | expect(browser.hidden(name: /no_such_name/)).to_not exist 34 | expect(browser.hidden(value: 'no_such_value')).to_not exist 35 | expect(browser.hidden(value: /no_such_value/)).to_not exist 36 | expect(browser.hidden(text: 'no_such_text')).to_not exist 37 | expect(browser.hidden(text: /no_such_text/)).to_not exist 38 | expect(browser.hidden(class: 'no_such_class')).to_not exist 39 | expect(browser.hidden(class: /no_such_class/)).to_not exist 40 | expect(browser.hidden(index: 1337)).to_not exist 41 | expect(browser.hidden(xpath: "//input[@id='no_such_id']")).to_not exist 42 | end 43 | 44 | it "raises TypeError when 'what' argument is invalid" do 45 | expect { browser.hidden(id: 3.14).exists? }.to raise_error(TypeError) 46 | end 47 | 48 | it "raises MissingWayOfFindingObjectException when 'how' argument is invalid" do 49 | expect { browser.hidden(no_such_how: 'some_value').exists? }.to raise_error(Watir::Exception::MissingWayOfFindingObjectException) 50 | end 51 | end 52 | 53 | # Attribute methods 54 | describe "#id" do 55 | it "returns the id attribute if the text field exists" do 56 | expect(browser.hidden(index: 1).id).to eq "new_user_interests_dolls" 57 | end 58 | 59 | it "raises UnknownObjectException if the text field doesn't exist" do 60 | expect { browser.hidden(index: 1337).id }.to raise_error(Watir::Exception::UnknownObjectException) 61 | end 62 | end 63 | 64 | describe "#name" do 65 | it "returns the name attribute if the text field exists" do 66 | expect(browser.hidden(index: 1).name).to eq "new_user_interests" 67 | end 68 | 69 | it "raises UnknownObjectException if the text field doesn't exist" do 70 | expect { browser.hidden(index: 1337).name }.to raise_error(Watir::Exception::UnknownObjectException) 71 | end 72 | end 73 | 74 | describe "#type" do 75 | it "returns the type attribute if the text field exists" do 76 | expect(browser.hidden(index: 1).type).to eq "hidden" 77 | end 78 | 79 | it "raises UnknownObjectException if the text field doesn't exist" do 80 | expect { browser.hidden(index: 1337).type }.to raise_error(Watir::Exception::UnknownObjectException) 81 | end 82 | end 83 | 84 | describe "#value" do 85 | it "returns the value attribute if the text field exists" do 86 | expect(browser.hidden(index: 1).value).to eq "dolls" 87 | end 88 | 89 | it "raises UnknownObjectException if the text field doesn't exist" do 90 | expect { browser.hidden(index: 1337).value }.to raise_error(Watir::Exception::UnknownObjectException) 91 | end 92 | end 93 | 94 | describe "#respond_to?" do 95 | it "returns true for all attribute methods" do 96 | expect(browser.hidden(index: 1)).to respond_to(:id) 97 | expect(browser.hidden(index: 1)).to respond_to(:name) 98 | expect(browser.hidden(index: 1)).to respond_to(:type) 99 | expect(browser.hidden(index: 1)).to respond_to(:value) 100 | end 101 | end 102 | 103 | end 104 | -------------------------------------------------------------------------------- /em_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require File.expand_path("../spec_helper", __FILE__) 3 | 4 | describe "Em" do 5 | 6 | before :each do 7 | browser.goto(WatirSpec.url_for("non_control_elements.html")) 8 | end 9 | 10 | # Exists method 11 | describe "#exists?" do 12 | it "returns true if the element exists" do 13 | expect(browser.em(id: "important-id")).to exist 14 | expect(browser.em(class: "important-class")).to exist 15 | expect(browser.em(xpath: "//em[@id='important-id']")).to exist 16 | expect(browser.em(index: 0)).to exist 17 | end 18 | 19 | it "returns the first em if given no args" do 20 | expect(browser.em).to exist 21 | end 22 | 23 | it "returns false if the element does not exist" do 24 | expect(browser.em(id: "no_such_id")).to_not exist 25 | end 26 | 27 | it "raises TypeError when 'what' argument is invalid" do 28 | expect { browser.em(id: 3.14).exists? }.to raise_error(TypeError) 29 | end 30 | 31 | it "raises MissingWayOfFindingObjectException when 'how' argument is invalid" do 32 | expect { browser.em(no_such_how: 'some_value').exists? }.to raise_error(Watir::Exception::MissingWayOfFindingObjectException) 33 | end 34 | end 35 | 36 | # Attribute methods 37 | describe "#class_name" do 38 | it "returns the class attribute if the element exists" do 39 | expect(browser.em(id: "important-id").class_name).to eq "important-class" 40 | end 41 | 42 | it "raises UnknownObjectException if the element does not exist" do 43 | expect { browser.em(id: "no_such_id").class_name }.to raise_error(Watir::Exception::UnknownObjectException) 44 | expect { browser.em(title: "no_such_title").class_name }.to raise_error(Watir::Exception::UnknownObjectException) 45 | expect { browser.em(index: 1337).class_name }.to raise_error(Watir::Exception::UnknownObjectException) 46 | expect { browser.em(xpath: "//em[@id='no_such_id']").class_name }.to raise_error(Watir::Exception::UnknownObjectException) 47 | end 48 | end 49 | 50 | describe "#id" do 51 | it "returns the id attribute if the element exists" do 52 | expect(browser.em(class: 'important-class').id).to eq "important-id" 53 | end 54 | 55 | it "raises UnknownObjectException if the element does not exist" do 56 | expect {browser.em(id: "no_such_id").id }.to raise_error(Watir::Exception::UnknownObjectException) 57 | expect {browser.em(title: "no_such_id").id }.to raise_error(Watir::Exception::UnknownObjectException) 58 | expect {browser.em(index: 1337).id }.to raise_error(Watir::Exception::UnknownObjectException) 59 | end 60 | end 61 | 62 | describe "#title" do 63 | it "returns the title of the element" do 64 | expect(browser.em(class: "important-class").title).to eq "ergo cogito" 65 | end 66 | end 67 | 68 | describe "#text" do 69 | it "returns the text of the element" do 70 | expect(browser.em(id: "important-id").text).to eq "ergo cogito" 71 | end 72 | 73 | it "raises UnknownObjectException if the element does not exist" do 74 | expect { browser.em(id: "no_such_id").text }.to raise_error(Watir::Exception::UnknownObjectException) 75 | expect { browser.em(title: "no_such_title").text }.to raise_error(Watir::Exception::UnknownObjectException) 76 | expect { browser.em(index: 1337).text }.to raise_error(Watir::Exception::UnknownObjectException) 77 | expect { browser.em(xpath: "//em[@id='no_such_id']").text }.to raise_error(Watir::Exception::UnknownObjectException) 78 | end 79 | end 80 | 81 | describe "#respond_to?" do 82 | it "returns true for all attribute methods" do 83 | expect(browser.em(index: 0)).to respond_to(:id) 84 | expect(browser.em(index: 0)).to respond_to(:class_name) 85 | expect(browser.em(index: 0)).to respond_to(:style) 86 | expect(browser.em(index: 0)).to respond_to(:text) 87 | expect(browser.em(index: 0)).to respond_to(:title) 88 | end 89 | end 90 | 91 | # Manipulation methods 92 | describe "#click" do 93 | it "raises UnknownObjectException if the element does not exist" do 94 | expect { browser.em(id: "no_such_id").click }.to raise_error(Watir::Exception::UnknownObjectException) 95 | expect { browser.em(title: "no_such_title").click }.to raise_error(Watir::Exception::UnknownObjectException) 96 | expect { browser.em(index: 1337).click }.to raise_error(Watir::Exception::UnknownObjectException) 97 | expect { browser.em(xpath: "//em[@id='no_such_id']").click }.to raise_error(Watir::Exception::UnknownObjectException) 98 | end 99 | end 100 | 101 | end 102 | -------------------------------------------------------------------------------- /li_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require File.expand_path("../spec_helper", __FILE__) 3 | 4 | describe "Li" do 5 | 6 | before :each do 7 | browser.goto(WatirSpec.url_for("non_control_elements.html")) 8 | end 9 | 10 | # Exists method 11 | describe "#exist?" do 12 | it "returns true if the 'li' exists" do 13 | expect(browser.li(id: "non_link_1")).to exist 14 | expect(browser.li(id: /non_link_1/)).to exist 15 | expect(browser.li(text: "Non-link 3")).to exist 16 | expect(browser.li(text: /Non-link 3/)).to exist 17 | expect(browser.li(class: "nonlink")).to exist 18 | expect(browser.li(class: /nonlink/)).to exist 19 | expect(browser.li(index: 0)).to exist 20 | expect(browser.li(xpath: "//li[@id='non_link_1']")).to exist 21 | end 22 | 23 | it "returns the first element if given no args" do 24 | expect(browser.li).to exist 25 | end 26 | 27 | it "returns false if the 'li' doesn't exist" do 28 | expect(browser.li(id: "no_such_id")).to_not exist 29 | expect(browser.li(id: /no_such_id/)).to_not exist 30 | expect(browser.li(text: "no_such_text")).to_not exist 31 | expect(browser.li(text: /no_such_text/)).to_not exist 32 | expect(browser.li(class: "no_such_class")).to_not exist 33 | expect(browser.li(class: /no_such_class/)).to_not exist 34 | expect(browser.li(index: 1337)).to_not exist 35 | expect(browser.li(xpath: "//li[@id='no_such_id']")).to_not exist 36 | end 37 | 38 | it "raises TypeError when 'what' argument is invalid" do 39 | expect { browser.li(id: 3.14).exists? }.to raise_error(TypeError) 40 | end 41 | 42 | it "raises MissingWayOfFindingObjectException when 'how' argument is invalid" do 43 | expect { browser.li(no_such_how: 'some_value').exists? }.to raise_error(Watir::Exception::MissingWayOfFindingObjectException) 44 | end 45 | end 46 | 47 | # Attribute methods 48 | describe "#class_name" do 49 | it "returns the class attribute" do 50 | expect(browser.li(id: 'non_link_1').class_name).to eq 'nonlink' 51 | end 52 | 53 | it "returns an empty string if the element exists and the attribute doesn't" do 54 | expect(browser.li(index: 0).class_name).to eq '' 55 | end 56 | 57 | it "raises UnknownObjectException if the li doesn't exist" do 58 | expect { browser.li(id: 'no_such_id').class_name }.to raise_error(Watir::Exception::UnknownObjectException) 59 | end 60 | end 61 | 62 | describe "#id" do 63 | it "returns the id attribute" do 64 | expect(browser.li(class: 'nonlink').id).to eq "non_link_1" 65 | end 66 | 67 | it "returns an empty string if the element exists and the attribute doesn't" do 68 | expect(browser.li(index: 0).id).to eq '' 69 | end 70 | 71 | it "raises UnknownObjectException if the li doesn't exist" do 72 | expect { browser.li(id: "no_such_id").id }.to raise_error(Watir::Exception::UnknownObjectException) 73 | expect { browser.li(index: 1337).id }.to raise_error(Watir::Exception::UnknownObjectException) 74 | end 75 | end 76 | 77 | describe "#title" do 78 | it "returns the title attribute" do 79 | expect(browser.li(id: 'non_link_1').title).to eq 'This is not a link!' 80 | end 81 | 82 | it "returns an empty string if the element exists and the attribute doesn't" do 83 | expect(browser.li(index: 0).title).to eq '' 84 | end 85 | 86 | it "raises UnknownObjectException if the li doesn't exist" do 87 | expect { browser.li(id: 'no_such_id').title }.to raise_error(Watir::Exception::UnknownObjectException) 88 | expect { browser.li(xpath: "//li[@id='no_such_id']").title }.to raise_error(Watir::Exception::UnknownObjectException) 89 | end 90 | end 91 | 92 | describe "#text" do 93 | it "returns the text of the li" do 94 | expect(browser.li(id: 'non_link_1').text).to eq 'Non-link 1' 95 | end 96 | 97 | it "returns an empty string if the element doesn't contain any text" do 98 | expect(browser.li(index: 0).text).to eq '' 99 | end 100 | 101 | it "raises UnknownObjectException if the li doesn't exist" do 102 | expect { browser.li(id: 'no_such_id').text }.to raise_error(Watir::Exception::UnknownObjectException) 103 | expect { browser.li(:xpath , "//li[@id='no_such_id']").text }.to raise_error(Watir::Exception::UnknownObjectException) 104 | end 105 | end 106 | 107 | describe "#respond_to?" do 108 | it "returns true for all attribute methods" do 109 | expect(browser.li(index: 0)).to respond_to(:class_name) 110 | expect(browser.li(index: 0)).to respond_to(:id) 111 | expect(browser.li(index: 0)).to respond_to(:text) 112 | expect(browser.li(index: 0)).to respond_to(:title) 113 | end 114 | end 115 | 116 | end 117 | -------------------------------------------------------------------------------- /p_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require File.expand_path("../spec_helper", __FILE__) 3 | 4 | describe "P" do 5 | 6 | before :each do 7 | browser.goto(WatirSpec.url_for("non_control_elements.html")) 8 | end 9 | 10 | # Exists method 11 | describe "#exist?" do 12 | it "returns true if the 'p' exists" do 13 | expect(browser.p(id: "lead")).to exist 14 | expect(browser.p(id: /lead/)).to exist 15 | expect(browser.p(text: "Dubito, ergo cogito, ergo sum.")).to exist 16 | expect(browser.p(text: /Dubito, ergo cogito, ergo sum/)).to exist 17 | expect(browser.p(class: "lead")).to exist 18 | expect(browser.p(class: /lead/)).to exist 19 | expect(browser.p(index: 0)).to exist 20 | expect(browser.p(xpath: "//p[@id='lead']")).to exist 21 | end 22 | 23 | it "returns the first p if given no args" do 24 | expect(browser.p).to exist 25 | end 26 | 27 | it "returns false if the 'p' doesn't exist" do 28 | expect(browser.p(id: "no_such_id")).to_not exist 29 | expect(browser.p(id: /no_such_id/)).to_not exist 30 | expect(browser.p(text: "no_such_text")).to_not exist 31 | expect(browser.p(text: /no_such_text/)).to_not exist 32 | expect(browser.p(class: "no_such_class")).to_not exist 33 | expect(browser.p(class: /no_such_class/)).to_not exist 34 | expect(browser.p(index: 1337)).to_not exist 35 | expect(browser.p(xpath: "//p[@id='no_such_id']")).to_not exist 36 | end 37 | 38 | it "raises TypeError when 'what' argument is invalid" do 39 | expect { browser.p(id: 3.14).exists? }.to raise_error(TypeError) 40 | end 41 | 42 | it "raises MissingWayOfFindingObjectException when 'how' argument is invalid" do 43 | expect { browser.p(no_such_how: 'some_value').exists? }.to raise_error(Watir::Exception::MissingWayOfFindingObjectException) 44 | end 45 | end 46 | 47 | # Attribute methods 48 | describe "#class_name" do 49 | it "returns the class attribute" do 50 | expect(browser.p(index: 0).class_name).to eq 'lead' 51 | end 52 | 53 | it "returns an empty string if the element exists and the attribute doesn't" do 54 | expect(browser.p(index: 2).class_name).to eq '' 55 | end 56 | 57 | it "raises UnknownObjectException if the p doesn't exist" do 58 | expect { browser.p(id: 'no_such_id').class_name }.to raise_error(Watir::Exception::UnknownObjectException) 59 | end 60 | end 61 | 62 | describe "#id" do 63 | it "returns the id attribute" do 64 | expect(browser.p(index: 0).id).to eq "lead" 65 | end 66 | 67 | it "returns an empty string if the element exists and the attribute doesn't" do 68 | expect(browser.p(index: 2).id).to eq '' 69 | end 70 | 71 | it "raises UnknownObjectException if the p doesn't exist" do 72 | expect { browser.p(id: "no_such_id").id }.to raise_error(Watir::Exception::UnknownObjectException) 73 | expect { browser.p(index: 1337).id }.to raise_error(Watir::Exception::UnknownObjectException) 74 | end 75 | end 76 | 77 | describe "#title" do 78 | it "returns the title attribute" do 79 | expect(browser.p(index: 0).title).to eq 'Lorem ipsum' 80 | end 81 | 82 | it "returns an empty string if the element exists and the attribute doesn't" do 83 | expect(browser.p(index: 2).title).to eq '' 84 | end 85 | 86 | it "raises UnknownObjectException if the p doesn't exist" do 87 | expect { browser.p(id: 'no_such_id').title }.to raise_error(Watir::Exception::UnknownObjectException) 88 | expect { browser.p(xpath: "//p[@id='no_such_id']").title }.to raise_error(Watir::Exception::UnknownObjectException) 89 | end 90 | end 91 | 92 | describe "#text" do 93 | it "returns the text of the p" do 94 | expect(browser.p(index: 1).text).to eq 'Sed pretium metus et quam. Nullam odio dolor, vestibulum non, tempor ut, vehicula sed, sapien. Vestibulum placerat ligula at quam. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.' 95 | end 96 | 97 | it "returns an empty string if the element doesn't contain any text" do 98 | expect(browser.p(index: 4).text).to eq '' 99 | end 100 | 101 | it "raises UnknownObjectException if the p doesn't exist" do 102 | expect { browser.p(id: 'no_such_id').text }.to raise_error(Watir::Exception::UnknownObjectException) 103 | expect { browser.p(:xpath , "//p[@id='no_such_id']").text }.to raise_error(Watir::Exception::UnknownObjectException) 104 | end 105 | end 106 | 107 | describe "#respond_to?" do 108 | it "returns true for all attribute methods" do 109 | expect(browser.p(index: 0)).to respond_to(:class_name) 110 | expect(browser.p(index: 0)).to respond_to(:id) 111 | expect(browser.p(index: 0)).to respond_to(:title) 112 | expect(browser.p(index: 0)).to respond_to(:text) 113 | end 114 | end 115 | 116 | end 117 | -------------------------------------------------------------------------------- /cookies_spec.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path("../spec_helper", __FILE__) 2 | 3 | bug "https://github.com/ariya/phantomjs/issues/13115", :phantomjs do 4 | describe "Browser#cookies" do 5 | after { browser.cookies.clear } 6 | 7 | it 'gets an empty list of cookies' do 8 | browser.goto WatirSpec.url_for 'collections.html' # no cookie set. 9 | expect(browser.cookies.to_a).to eq [] 10 | end 11 | 12 | it "gets any cookies set" do 13 | browser.goto set_cookie_url 14 | 15 | verify_cookies_count 1 16 | 17 | cookie = browser.cookies.to_a.first 18 | expect(cookie[:name]).to eq 'monster' 19 | expect(cookie[:value]).to eq '1' 20 | end 21 | 22 | describe '#[]' do 23 | before do 24 | browser.goto set_cookie_url 25 | verify_cookies_count 1 26 | end 27 | 28 | it 'returns cookie by symbol name' do 29 | cookie = browser.cookies[:monster] 30 | expect(cookie[:name]).to eq('monster') 31 | expect(cookie[:value]).to eq('1') 32 | end 33 | 34 | it 'returns cookie by string name' do 35 | cookie = browser.cookies['monster'] 36 | expect(cookie[:name]).to eq('monster') 37 | expect(cookie[:value]).to eq('1') 38 | end 39 | 40 | it 'returns nil if there is no cookie with such name' do 41 | expect(browser.cookies[:non_monster]).to eq(nil) 42 | end 43 | end 44 | 45 | not_compliant_on :internet_explorer do 46 | it 'adds a cookie' do 47 | browser.goto set_cookie_url 48 | verify_cookies_count 1 49 | 50 | browser.cookies.add 'foo', 'bar' 51 | verify_cookies_count 2 52 | 53 | compliant_on :safari do 54 | $browser.close 55 | $browser = WatirSpec.new_browser 56 | end 57 | end 58 | end 59 | 60 | # TODO - Split this up into multiple tests or figure out which parts are not compliant 61 | not_compliant_on :chrome, :internet_explorer, :safari, :firefox do 62 | it 'adds a cookie with options' do 63 | browser.goto set_cookie_url 64 | 65 | expires = Time.now + 10000 66 | options = {path: "/set_cookie", 67 | secure: true, 68 | expires: expires} 69 | 70 | browser.cookies.add 'a', 'b', options 71 | cookie = browser.cookies.to_a.find { |e| e[:name] == 'a' } 72 | expect(cookie).to_not be_nil 73 | 74 | expect(cookie[:name]).to eq 'a' 75 | expect(cookie[:value]).to eq 'b' 76 | 77 | expect(cookie[:path]).to eq "/set_cookie" 78 | expect(cookie[:secure]).to be true 79 | 80 | expect(cookie[:expires]).to be_kind_of(Time) 81 | # a few ms slack 82 | expect((cookie[:expires]).to_i).to be_within(2).of(expires.to_i) 83 | end 84 | end 85 | 86 | not_compliant_on :internet_explorer do 87 | it 'removes a cookie' do 88 | browser.goto set_cookie_url 89 | verify_cookies_count 1 90 | 91 | browser.cookies.delete 'monster' 92 | verify_cookies_count 0 93 | end 94 | 95 | bug "https://code.google.com/p/selenium/issues/detail?id=5487", :safari do 96 | it 'clears all cookies' do 97 | browser.goto set_cookie_url 98 | browser.cookies.add 'foo', 'bar' 99 | verify_cookies_count 2 100 | 101 | browser.cookies.clear 102 | verify_cookies_count 0 103 | end 104 | end 105 | end 106 | 107 | not_compliant_on :internet_explorer do 108 | let(:file) { "#{Dir.tmpdir}/cookies" } 109 | 110 | before do 111 | browser.goto set_cookie_url 112 | browser.cookies.save file 113 | end 114 | 115 | describe '#save' do 116 | it 'saves cookies to file' do 117 | expect(IO.read(file)).to eq(browser.cookies.to_a.to_yaml) 118 | end 119 | end 120 | 121 | describe '#load' do 122 | it 'loads cookies from file' do 123 | browser.cookies.clear 124 | browser.cookies.load file 125 | expected = browser.cookies.to_a 126 | actual = YAML.load(IO.read(file)) 127 | 128 | # https://code.google.com/p/selenium/issues/detail?id=6834 129 | expected.each { |cookie| cookie.delete(:expires) } 130 | actual.each { |cookie| cookie.delete(:expires) } 131 | 132 | expect(actual).to eq(expected) 133 | end 134 | end 135 | end 136 | 137 | def set_cookie_url 138 | # add timestamp to url to avoid caching in IE8 139 | WatirSpec.url_for('set_cookie/index.html', needs_server: true) + "?t=#{Time.now.to_i + Time.now.usec}" 140 | end 141 | 142 | def verify_cookies_count expected_size 143 | cookies = browser.cookies.to_a 144 | expect(cookies.size).to eq(expected_size), "expected #{expected_size} cookies, got #{cookies.size}: #{cookies.inspect}" 145 | end 146 | end 147 | end 148 | -------------------------------------------------------------------------------- /pre_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require File.expand_path("../spec_helper", __FILE__) 3 | 4 | describe "Pre" do 5 | 6 | before :each do 7 | browser.goto(WatirSpec.url_for("non_control_elements.html")) 8 | end 9 | 10 | # Exists method 11 | describe "#exist?" do 12 | it "returns true if the 'p' exists" do 13 | expect(browser.pre(id: "rspec")).to exist 14 | expect(browser.pre(id: /rspec/)).to exist 15 | expect(browser.pre(text: 'browser.pre(id: "rspec").should exist')).to exist 16 | expect(browser.pre(text: /browser\.pre/)).to exist 17 | expect(browser.pre(class: "ruby")).to exist 18 | expect(browser.pre(class: /ruby/)).to exist 19 | expect(browser.pre(index: 0)).to exist 20 | expect(browser.pre(xpath: "//pre[@id='rspec']")).to exist 21 | end 22 | 23 | it "returns the first pre if given no args" do 24 | expect(browser.pre).to exist 25 | end 26 | 27 | it "returns false if the 'p' doesn't exist" do 28 | expect(browser.pre(id: "no_such_id")).to_not exist 29 | expect(browser.pre(id: /no_such_id/)).to_not exist 30 | expect(browser.pre(text: "no_such_text")).to_not exist 31 | expect(browser.pre(text: /no_such_text/)).to_not exist 32 | expect(browser.pre(class: "no_such_class")).to_not exist 33 | expect(browser.pre(class: /no_such_class/)).to_not exist 34 | expect(browser.pre(index: 1337)).to_not exist 35 | expect(browser.pre(xpath: "//pre[@id='no_such_id']")).to_not exist 36 | end 37 | 38 | it "raises TypeError when 'what' argument is invalid" do 39 | expect { browser.pre(id: 3.14).exists? }.to raise_error(TypeError) 40 | end 41 | 42 | it "raises MissingWayOfFindingObjectException when 'how' argument is invalid" do 43 | expect { browser.pre(no_such_how: 'some_value').exists? }.to raise_error(Watir::Exception::MissingWayOfFindingObjectException) 44 | end 45 | end 46 | 47 | # Attribute methods 48 | describe "#class_name" do 49 | it "returns the class attribute" do 50 | expect(browser.pre(id: 'rspec').class_name).to eq 'ruby' 51 | end 52 | 53 | it "returns an empty string if the element exists and the attribute doesn't" do 54 | expect(browser.pre(index: 0).class_name).to eq '' 55 | end 56 | 57 | it "raises UnknownObjectException if the p doesn't exist" do 58 | expect { browser.pre(id: 'no_such_id').class_name }.to raise_error(Watir::Exception::UnknownObjectException) 59 | end 60 | end 61 | 62 | describe "#id" do 63 | it "returns the id attribute" do 64 | expect(browser.pre(class: 'ruby').id).to eq "rspec" 65 | end 66 | 67 | it "returns an empty string if the element exists and the attribute doesn't" do 68 | expect(browser.pre(index: 0).id).to eq '' 69 | end 70 | 71 | it "raises UnknownObjectException if the pre doesn't exist" do 72 | expect { browser.pre(id: "no_such_id").id }.to raise_error(Watir::Exception::UnknownObjectException) 73 | expect { browser.pre(index: 1337).id }.to raise_error(Watir::Exception::UnknownObjectException) 74 | end 75 | end 76 | 77 | describe "#title" do 78 | it "returns the title attribute" do 79 | expect(browser.pre(class: 'brainfuck').title).to eq 'The brainfuck language is an esoteric programming language noted for its extreme minimalism' 80 | end 81 | 82 | it "returns an empty string if the element exists and the attribute doesn't" do 83 | expect(browser.pre(index: 0).title).to eq '' 84 | end 85 | 86 | it "raises UnknownObjectException if the pre doesn't exist" do 87 | expect { browser.pre(id: 'no_such_id').title }.to raise_error(Watir::Exception::UnknownObjectException) 88 | expect { browser.pre(xpath: "//pre[@id='no_such_id']").title }.to raise_error(Watir::Exception::UnknownObjectException) 89 | end 90 | end 91 | 92 | describe "#text" do 93 | it "returns the text of the pre" do 94 | expect(browser.pre(class: 'haskell').text).to eq 'main = putStrLn "Hello World"' 95 | end 96 | 97 | it "returns an empty string if the element doesn't contain any text" do 98 | expect(browser.pre(index: 0).text).to eq '' 99 | end 100 | 101 | it "raises UnknownObjectException if the pre doesn't exist" do 102 | expect { browser.pre(id: 'no_such_id').text }.to raise_error(Watir::Exception::UnknownObjectException) 103 | expect { browser.pre(:xpath , "//pre[@id='no_such_id']").text }.to raise_error(Watir::Exception::UnknownObjectException) 104 | end 105 | end 106 | 107 | describe "#respond_to?" do 108 | it "returns true for all attribute methods" do 109 | expect(browser.image(index: 0)).to respond_to(:class_name) 110 | expect(browser.image(index: 0)).to respond_to(:id) 111 | expect(browser.image(index: 0)).to respond_to(:title) 112 | expect(browser.image(index: 0)).to respond_to(:text) 113 | end 114 | end 115 | 116 | end 117 | -------------------------------------------------------------------------------- /lib/server.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | 3 | require "socket" 4 | 5 | module WatirSpec 6 | class Server < Sinatra::Base 7 | class << self 8 | attr_accessor :autorun 9 | 10 | def run_async 11 | if WatirSpec.platform == :java 12 | Thread.new { run! } 13 | sleep 0.1 until WatirSpec::Server.running? 14 | elsif WatirSpec.platform == :windows 15 | # FIXME: this makes use lose implementation-specific routes! 16 | run_in_child_process 17 | sleep 0.5 until listening? 18 | else 19 | pid = fork { run! } 20 | sleep 0.5 until listening? 21 | end 22 | 23 | if pid 24 | # is this really necessary? 25 | at_exit { 26 | begin 27 | Process.kill 0, pid 28 | alive = true 29 | rescue Errno::ESRCH 30 | alive = false 31 | end 32 | 33 | Process.kill(9, pid) if alive 34 | } 35 | end 36 | end 37 | 38 | def run! 39 | handler = detect_rack_handler 40 | handler.run(self, Host: bind, Port: port, AccessLog: [], Logger: SilentLogger.new) { @running = true } 41 | end 42 | 43 | def listening? 44 | $stderr.puts "trying #{bind}:#{port}..." 45 | 46 | TCPSocket.new(bind, port).close 47 | true 48 | rescue 49 | false 50 | end 51 | 52 | def autorun 53 | @autorun ||= true 54 | end 55 | 56 | def should_run? 57 | autorun && !running? 58 | end 59 | 60 | def running? 61 | defined?(@running) && @running 62 | end 63 | 64 | private 65 | 66 | def run_in_child_process 67 | begin 68 | require "childprocess" 69 | rescue LoadError => ex 70 | raise "please run `gem install childprocess` for WatirSpec on Windows + MRI\n\t(caught: #{ex.message})" 71 | end 72 | 73 | path = File.expand_path("../../spec_helper.rb", __FILE__) 74 | 75 | process = ChildProcess.build(WatirSpec.ruby, path) 76 | process.io.inherit! if $DEBUG 77 | process.start 78 | 79 | at_exit { process.stop } 80 | end 81 | 82 | def pick_port_above(port) 83 | port += 1 until port_free? port 84 | port 85 | end 86 | 87 | def port_free?(port) 88 | TCPServer.new(bind, port).close 89 | true 90 | rescue SocketError, Errno::EADDRINUSE 91 | false 92 | end 93 | 94 | end # class << Server 95 | 96 | set :public_folder, WatirSpec.html 97 | set :static, true 98 | set :run, false 99 | set :environment, :production 100 | set :bind, "127.0.0.1" if WatirSpec.platform == :windows 101 | set :port, pick_port_above(8180) 102 | set :server, "webrick" 103 | 104 | get '/' do 105 | self.class.name 106 | end 107 | 108 | class BigContent 109 | def each(&blk) 110 | yield "Big Content" 111 | 112 | string = "hello"*205 113 | 114 | 300.times do 115 | yield string 116 | end 117 | 118 | yield "" 119 | end 120 | end 121 | 122 | get '/big' do 123 | BigContent.new 124 | end 125 | 126 | post '/post_to_me' do 127 | "You posted the following content:\n#{ env['rack.input'].read }" 128 | end 129 | 130 | get '/plain_text' do 131 | content_type 'text/plain' 132 | 'This is text/plain' 133 | end 134 | 135 | get '/ajax' do 136 | sleep 10 137 | "A slooow ajax response" 138 | end 139 | 140 | get '/charset_mismatch' do 141 | content_type 'text/html; charset=UTF-8' 142 | %{ 143 | 144 | 145 | 146 | 147 | 148 |

ø

149 | 150 | 151 | } 152 | end 153 | 154 | get '/octet_stream' do 155 | content_type 'application/octet-stream' 156 | 'This is application/octet-stream' 157 | end 158 | 159 | get '/set_cookie' do 160 | content_type 'text/html' 161 | headers 'Set-Cookie' => "monster=1" 162 | 163 | "C is for cookie, it's good enough for me" 164 | end 165 | 166 | get '/set_cookie/index.html' do 167 | content_type 'text/html' 168 | headers 'Set-Cookie' => "monster=1" 169 | 170 | "C is for cookie, it's good enough for me" 171 | end 172 | 173 | get '/header_echo' do 174 | content_type 'text/plain' 175 | env.inspect 176 | end 177 | 178 | get '/authentication' do 179 | auth = Rack::Auth::Basic::Request.new(env) 180 | 181 | unless auth.provided? && auth.credentials == %w[foo bar] 182 | headers 'WWW-Authenticate' => %(Basic realm="localhost") 183 | halt 401, 'Authorization Required' 184 | end 185 | 186 | "ok" 187 | end 188 | 189 | get '/encodable_' do 190 | 'page with characters in URI that need encoding' 191 | end 192 | 193 | end # Server 194 | end # WatirSpec 195 | -------------------------------------------------------------------------------- /del_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require File.expand_path("../spec_helper", __FILE__) 3 | 4 | describe "Del" do 5 | 6 | before :each do 7 | browser.goto(WatirSpec.url_for("non_control_elements.html")) 8 | end 9 | 10 | # Exists method 11 | describe "#exist?" do 12 | it "returns true if the 'del' exists" do 13 | expect(browser.del(id: "lead")).to exist 14 | expect(browser.del(id: /lead/)).to exist 15 | expect(browser.del(text: "This is a deleted text tag 1")).to exist 16 | expect(browser.del(text: /This is a deleted text tag 1/)).to exist 17 | expect(browser.del(class: "lead")).to exist 18 | expect(browser.del(class: /lead/)).to exist 19 | expect(browser.del(index: 0)).to exist 20 | expect(browser.del(xpath: "//del[@id='lead']")).to exist 21 | end 22 | 23 | it "returns the first del if given no args" do 24 | expect(browser.del).to exist 25 | end 26 | 27 | it "returns false if the element doesn't exist" do 28 | expect(browser.del(id: "no_such_id")).to_not exist 29 | expect(browser.del(id: /no_such_id/)).to_not exist 30 | expect(browser.del(text: "no_such_text")).to_not exist 31 | expect(browser.del(text: /no_such_text/)).to_not exist 32 | expect(browser.del(class: "no_such_class")).to_not exist 33 | expect(browser.del(class: /no_such_class/)).to_not exist 34 | expect(browser.del(index: 1337)).to_not exist 35 | expect(browser.del(xpath: "//del[@id='no_such_id']")).to_not exist 36 | end 37 | 38 | it "raises TypeError when 'what' argument is invalid" do 39 | expect { browser.del(id: 3.14).exists? }.to raise_error(TypeError) 40 | end 41 | 42 | it "raises MissingWayOfFindingObjectException when 'how' argument is invalid" do 43 | expect { browser.del(no_such_how: 'some_value').exists? }.to raise_error(Watir::Exception::MissingWayOfFindingObjectException) 44 | end 45 | end 46 | 47 | # Attribute methods 48 | describe "#class_name" do 49 | it "returns the class attribute" do 50 | expect(browser.del(index: 0).class_name).to eq 'lead' 51 | end 52 | 53 | it "returns an empty string if the element exists and the attribute doesn't" do 54 | expect(browser.del(index: 2).class_name).to eq '' 55 | end 56 | 57 | it "raises UnknownObjectException if the del doesn't exist" do 58 | expect { browser.del(id: 'no_such_id').class_name }.to raise_error(Watir::Exception::UnknownObjectException) 59 | end 60 | end 61 | 62 | describe "#id" do 63 | it "returns the id attribute" do 64 | expect(browser.del(index: 0).id).to eq "lead" 65 | end 66 | 67 | it "returns an empty string if the element exists and the attribute doesn't" do 68 | expect(browser.del(index: 2).id).to eq '' 69 | end 70 | 71 | it "raises UnknownObjectException if the del doesn't exist" do 72 | expect { browser.del(id: "no_such_id").id }.to raise_error(Watir::Exception::UnknownObjectException) 73 | expect { browser.del(index: 1337).id }.to raise_error(Watir::Exception::UnknownObjectException) 74 | end 75 | end 76 | 77 | describe "#title" do 78 | it "returns the title attribute" do 79 | expect(browser.del(index: 0).title).to eq 'Lorem ipsum' 80 | end 81 | 82 | it "returns an empty string if the element exists and the attribute doesn't" do 83 | expect(browser.del(index: 2).title).to eq '' 84 | end 85 | 86 | it "raises UnknownObjectException if the del doesn't exist" do 87 | expect { browser.del(id: 'no_such_id').title }.to raise_error(Watir::Exception::UnknownObjectException) 88 | expect { browser.del(xpath: "//del[@id='no_such_id']").title }.to raise_error(Watir::Exception::UnknownObjectException) 89 | end 90 | end 91 | 92 | describe "#text" do 93 | it "returns the text of the del" do 94 | expect(browser.del(index: 1).text).to eq 'This is a deleted text tag 2' 95 | end 96 | 97 | it "returns an empty string if the element doesn't contain any text" do 98 | expect(browser.del(index: 3).text).to eq '' 99 | end 100 | 101 | it "raises UnknownObjectException if the del doesn't exist" do 102 | expect { browser.del(id: 'no_such_id').text }.to raise_error(Watir::Exception::UnknownObjectException) 103 | expect { browser.del(:xpath , "//del[@id='no_such_id']").text }.to raise_error(Watir::Exception::UnknownObjectException) 104 | end 105 | end 106 | 107 | describe "#respond_to?" do 108 | it "returns true for all attribute methods" do 109 | expect(browser.del(index: 0)).to respond_to(:class_name) 110 | expect(browser.del(index: 0)).to respond_to(:id) 111 | expect(browser.del(index: 0)).to respond_to(:title) 112 | expect(browser.del(index: 0)).to respond_to(:text) 113 | end 114 | end 115 | 116 | # Other 117 | describe "#click" do 118 | it "fires events" do 119 | expect(browser.del(class: 'footer').text).to_not include('Javascript') 120 | browser.del(class: 'footer').click 121 | expect(browser.del(class: 'footer').text).to include('Javascript') 122 | end 123 | 124 | it "raises UnknownObjectException if the del doesn't exist" do 125 | expect { browser.del(id: "no_such_id").click }.to raise_error(Watir::Exception::UnknownObjectException) 126 | expect { browser.del(title: "no_such_title").click }.to raise_error(Watir::Exception::UnknownObjectException) 127 | end 128 | end 129 | end 130 | -------------------------------------------------------------------------------- /ins_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require File.expand_path("../spec_helper", __FILE__) 3 | 4 | describe "Ins" do 5 | 6 | before :each do 7 | browser.goto(WatirSpec.url_for("non_control_elements.html")) 8 | end 9 | 10 | # Exists method 11 | describe "#exist?" do 12 | it "returns true if the 'ins' exists" do 13 | expect(browser.ins(id: "lead")).to exist 14 | expect(browser.ins(id: /lead/)).to exist 15 | expect(browser.ins(text: "This is an inserted text tag 1")).to exist 16 | expect(browser.ins(text: /This is an inserted text tag 1/)).to exist 17 | expect(browser.ins(class: "lead")).to exist 18 | expect(browser.ins(class: /lead/)).to exist 19 | expect(browser.ins(index: 0)).to exist 20 | expect(browser.ins(xpath: "//ins[@id='lead']")).to exist 21 | end 22 | 23 | it "returns the first ins if given no args" do 24 | expect(browser.ins).to exist 25 | end 26 | 27 | it "returns false if the element doesn't exist" do 28 | expect(browser.ins(id: "no_such_id")).to_not exist 29 | expect(browser.ins(id: /no_such_id/)).to_not exist 30 | expect(browser.ins(text: "no_such_text")).to_not exist 31 | expect(browser.ins(text: /no_such_text/)).to_not exist 32 | expect(browser.ins(class: "no_such_class")).to_not exist 33 | expect(browser.ins(class: /no_such_class/)).to_not exist 34 | expect(browser.ins(index: 1337)).to_not exist 35 | expect(browser.ins(xpath: "//ins[@id='no_such_id']")).to_not exist 36 | end 37 | 38 | it "raises TypeError when 'what' argument is invalid" do 39 | expect { browser.ins(id: 3.14).exists? }.to raise_error(TypeError) 40 | end 41 | 42 | it "raises MissingWayOfFindingObjectException when 'how' argument is invalid" do 43 | expect { browser.ins(no_such_how: 'some_value').exists? }.to raise_error(Watir::Exception::MissingWayOfFindingObjectException) 44 | end 45 | end 46 | 47 | # Attribute methods 48 | describe "#class_name" do 49 | it "returns the class attribute" do 50 | expect(browser.ins(index: 0).class_name).to eq 'lead' 51 | end 52 | 53 | it "returns an empty string if the element exists and the attribute doesn't" do 54 | expect(browser.ins(index: 2).class_name).to eq '' 55 | end 56 | 57 | it "raises UnknownObjectException if the ins doesn't exist" do 58 | expect { browser.ins(id: 'no_such_id').class_name }.to raise_error(Watir::Exception::UnknownObjectException) 59 | end 60 | end 61 | 62 | describe "#id" do 63 | it "returns the id attribute" do 64 | expect(browser.ins(index: 0).id).to eq "lead" 65 | end 66 | 67 | it "returns an empty string if the element exists and the attribute doesn't" do 68 | expect(browser.ins(index: 2).id).to eq '' 69 | end 70 | 71 | it "raises UnknownObjectException if the ins doesn't exist" do 72 | expect { browser.ins(id: "no_such_id").id }.to raise_error(Watir::Exception::UnknownObjectException) 73 | expect { browser.ins(index: 1337).id }.to raise_error(Watir::Exception::UnknownObjectException) 74 | end 75 | end 76 | 77 | describe "#title" do 78 | it "returns the title attribute" do 79 | expect(browser.ins(index: 0).title).to eq 'Lorem ipsum' 80 | end 81 | 82 | it "returns an empty string if the element exists and the attribute doesn't" do 83 | expect(browser.ins(index: 2).title).to eq '' 84 | end 85 | 86 | it "raises UnknownObjectException if the ins doesn't exist" do 87 | expect { browser.ins(id: 'no_such_id').title }.to raise_error(Watir::Exception::UnknownObjectException) 88 | expect { browser.ins(xpath: "//ins[@id='no_such_id']").title }.to raise_error(Watir::Exception::UnknownObjectException) 89 | end 90 | end 91 | 92 | describe "#text" do 93 | it "returns the text of the ins" do 94 | expect(browser.ins(index: 1).text).to eq 'This is an inserted text tag 2' 95 | end 96 | 97 | it "returns an empty string if the element doesn't contain any text" do 98 | expect(browser.ins(index: 3).text).to eq '' 99 | end 100 | 101 | it "raises UnknownObjectException if the ins doesn't exist" do 102 | expect { browser.ins(id: 'no_such_id').text }.to raise_error(Watir::Exception::UnknownObjectException) 103 | expect { browser.ins(:xpath , "//ins[@id='no_such_id']").text }.to raise_error(Watir::Exception::UnknownObjectException) 104 | end 105 | end 106 | 107 | describe "#respond_to?" do 108 | it "returns true for all attribute methods" do 109 | expect(browser.ins(index: 0)).to respond_to(:class_name) 110 | expect(browser.ins(index: 0)).to respond_to(:id) 111 | expect(browser.ins(index: 0)).to respond_to(:title) 112 | expect(browser.ins(index: 0)).to respond_to(:text) 113 | end 114 | end 115 | 116 | # Other 117 | describe "#click" do 118 | it "fires events" do 119 | expect(browser.ins(class: 'footer').text).to_not include('Javascript') 120 | browser.ins(class: 'footer').click 121 | expect(browser.ins(class: 'footer').text).to include('Javascript') 122 | end 123 | 124 | it "raises UnknownObjectException if the ins doesn't exist" do 125 | expect { browser.ins(id: "no_such_id").click }.to raise_error(Watir::Exception::UnknownObjectException) 126 | expect { browser.ins(title: "no_such_title").click }.to raise_error(Watir::Exception::UnknownObjectException) 127 | end 128 | end 129 | 130 | end 131 | -------------------------------------------------------------------------------- /dd_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require File.expand_path("../spec_helper", __FILE__) 3 | 4 | describe "Dd" do 5 | 6 | before :each do 7 | browser.goto(WatirSpec.url_for("definition_lists.html")) 8 | end 9 | 10 | # Exists method 11 | describe "#exists?" do 12 | it "returns true if the element exists" do 13 | expect(browser.dd(id: "someone")).to exist 14 | expect(browser.dd(class: "name")).to exist 15 | expect(browser.dd(xpath: "//dd[@id='someone']")).to exist 16 | expect(browser.dd(index: 0)).to exist 17 | end 18 | 19 | it "returns the first dd if given no args" do 20 | expect(browser.dd).to exist 21 | end 22 | 23 | it "returns false if the element does not exist" do 24 | expect(browser.dd(id: "no_such_id")).to_not exist 25 | end 26 | 27 | it "raises TypeError when 'what' argument is invalid" do 28 | expect { browser.dd(id: 3.14).exists? }.to raise_error(TypeError) 29 | end 30 | 31 | it "raises MissingWayOfFindingObjectException when 'how' argument is invalid" do 32 | expect { browser.dd(no_such_how: 'some_value').exists? }.to raise_error(Watir::Exception::MissingWayOfFindingObjectException) 33 | end 34 | end 35 | 36 | # Attribute methods 37 | describe "#class_name" do 38 | it "returns the class attribute if the element exists" do 39 | expect(browser.dd(id: "someone").class_name).to eq "name" 40 | end 41 | 42 | it "returns an empty string if the element exists but the attribute doesn't" do 43 | expect(browser.dd(id: "city").class_name).to eq "" 44 | end 45 | 46 | it "raises UnknownObjectException if the element does not exist" do 47 | expect { browser.dd(id: "no_such_id").class_name }.to raise_error(Watir::Exception::UnknownObjectException) 48 | expect { browser.dd(title: "no_such_title").class_name }.to raise_error(Watir::Exception::UnknownObjectException) 49 | expect { browser.dd(index: 1337).class_name }.to raise_error(Watir::Exception::UnknownObjectException) 50 | expect { browser.dd(xpath: "//dd[@id='no_such_id']").class_name }.to raise_error(Watir::Exception::UnknownObjectException) 51 | end 52 | end 53 | 54 | describe "#id" do 55 | it "returns the id attribute if the element exists" do 56 | expect(browser.dd(class: 'name').id).to eq "someone" 57 | end 58 | 59 | it "returns an empty string if the element exists, but the attribute doesn't" do 60 | expect(browser.dd(class: 'address').id).to eq "" 61 | end 62 | 63 | it "raises UnknownObjectException if the element does not exist" do 64 | expect {browser.dd(id: "no_such_id").id }.to raise_error(Watir::Exception::UnknownObjectException) 65 | expect {browser.dd(title: "no_such_id").id }.to raise_error(Watir::Exception::UnknownObjectException) 66 | expect {browser.dd(index: 1337).id }.to raise_error(Watir::Exception::UnknownObjectException) 67 | end 68 | end 69 | 70 | describe "#title" do 71 | it "returns the title of the element" do 72 | expect(browser.dd(class: "name").title).to eq "someone" 73 | end 74 | end 75 | 76 | describe "#text" do 77 | it "returns the text of the element" do 78 | expect(browser.dd(id: "someone").text).to eq "John Doe" 79 | end 80 | 81 | it "returns an empty string if the element exists but contains no text" do 82 | expect(browser.dd(class: 'noop').text).to eq "" 83 | end 84 | 85 | it "raises UnknownObjectException if the element does not exist" do 86 | expect { browser.dd(id: "no_such_id").text }.to raise_error(Watir::Exception::UnknownObjectException) 87 | expect { browser.dd(title: "no_such_title").text }.to raise_error(Watir::Exception::UnknownObjectException) 88 | expect { browser.dd(index: 1337).text }.to raise_error(Watir::Exception::UnknownObjectException) 89 | expect { browser.dd(xpath: "//dd[@id='no_such_id']").text }.to raise_error(Watir::Exception::UnknownObjectException) 90 | end 91 | end 92 | 93 | describe "#respond_to?" do 94 | it "returns true for all attribute methods" do 95 | expect(browser.dd(index: 0)).to respond_to(:id) 96 | expect(browser.dd(index: 0)).to respond_to(:class_name) 97 | expect(browser.dd(index: 0)).to respond_to(:style) 98 | expect(browser.dd(index: 0)).to respond_to(:text) 99 | expect(browser.dd(index: 0)).to respond_to(:title) 100 | end 101 | end 102 | 103 | # Manipulation methods 104 | describe "#click" do 105 | it "fires events when clicked" do 106 | expect(browser.dd(title: 'education').text).to_not eq 'changed' 107 | browser.dd(title: 'education').click 108 | expect(browser.dd(title: 'education').text).to eq 'changed' 109 | end 110 | 111 | it "raises UnknownObjectException if the element does not exist" do 112 | expect { browser.dd(id: "no_such_id").click }.to raise_error(Watir::Exception::UnknownObjectException) 113 | expect { browser.dd(title: "no_such_title").click }.to raise_error(Watir::Exception::UnknownObjectException) 114 | expect { browser.dd(index: 1337).click }.to raise_error(Watir::Exception::UnknownObjectException) 115 | expect { browser.dd(xpath: "//dd[@id='no_such_id']").click }.to raise_error(Watir::Exception::UnknownObjectException) 116 | end 117 | end 118 | 119 | describe "#html" do 120 | it "returns the HTML of the element" do 121 | html = browser.dd(id: 'someone').html 122 | expect(html).to match(/John Doe/m) 123 | expect(html).to_not include('') 124 | end 125 | end 126 | 127 | end 128 | -------------------------------------------------------------------------------- /frame_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require File.expand_path("../spec_helper", __FILE__) 3 | 4 | # 5 | # TODO: fix duplication with iframe_spec 6 | # 7 | 8 | describe "Frame" do 9 | 10 | before :each do 11 | browser.goto(WatirSpec.url_for("frames.html")) 12 | end 13 | 14 | it "handles crossframe javascript" do 15 | browser.goto WatirSpec.url_for("frames.html", needs_server: true) 16 | 17 | expect(browser.frame(id: "frame_1").text_field(name: 'senderElement').value).to eq 'send_this_value' 18 | expect(browser.frame(id: "frame_2").text_field(name: 'recieverElement').value).to eq 'old_value' 19 | browser.frame(id: "frame_1").button(id: 'send').click 20 | expect(browser.frame(id: "frame_2").text_field(name: 'recieverElement').value).to eq 'send_this_value' 21 | end 22 | 23 | describe "#exist?" do 24 | it "returns true if the frame exists" do 25 | expect(browser.frame(id: "frame_1")).to exist 26 | expect(browser.frame(name: "frame1")).to exist 27 | expect(browser.frame(index: 0)).to exist 28 | expect(browser.frame(class: "half")).to exist 29 | expect(browser.frame(xpath: "//frame[@id='frame_1']")).to exist 30 | expect(browser.frame(src: "frame_1.html")).to exist 31 | expect(browser.frame(id: /frame/)).to exist 32 | expect(browser.frame(name: /frame/)).to exist 33 | expect(browser.frame(src: /frame_1/)).to exist 34 | expect(browser.frame(class: /half/)).to exist 35 | end 36 | 37 | it "returns the first frame if given no args" do 38 | expect(browser.frame).to exist 39 | end 40 | 41 | it "returns false if the frame doesn't exist" do 42 | expect(browser.frame(id: "no_such_id")).to_not exist 43 | expect(browser.frame(name: "no_such_text")).to_not exist 44 | expect(browser.frame(index: 1337)).to_not exist 45 | expect(browser.frame(src: "no_such_src")).to_not exist 46 | expect(browser.frame(class: "no_such_class")).to_not exist 47 | expect(browser.frame(id: /no_such_id/)).to_not exist 48 | expect(browser.frame(name: /no_such_text/)).to_not exist 49 | expect(browser.frame(src: /no_such_src/)).to_not exist 50 | expect(browser.frame(class: /no_such_class/)).to_not exist 51 | expect(browser.frame(xpath: "//frame[@id='no_such_id']")).to_not exist 52 | end 53 | 54 | bug "https://github.com/detro/ghostdriver/issues/159", :phantomjs do 55 | bug "https://bugzilla.mozilla.org/show_bug.cgi?id=1255946", :firefox do 56 | it "handles nested frames" do 57 | browser.goto(WatirSpec.url_for("nested_frames.html")) 58 | 59 | browser.frame(id: "two").frame(id: "three").link(id: "four").click 60 | 61 | Wait.until{ browser.title == "definition_lists" } 62 | end 63 | end 64 | end 65 | 66 | it "raises TypeError when 'what' argument is invalid" do 67 | expect { browser.frame(id: 3.14).exists? }.to raise_error(TypeError) 68 | end 69 | 70 | it "raises MissingWayOfFindingObjectException when 'how' argument is invalid" do 71 | expect { browser.frame(no_such_how: 'some_value').exists? }.to raise_error(Watir::Exception::MissingWayOfFindingObjectException) 72 | end 73 | end 74 | 75 | it "raises UnknownFrameException when accessing elements inside non-existing frame" do 76 | expect { browser.frame(name: "no_such_name").p(index: 0).id }.to raise_error(Watir::Exception::UnknownFrameException) 77 | end 78 | 79 | it "raises UnknownFrameException when accessing a non-existing frame" do 80 | expect { browser.frame(name: "no_such_name").id }.to raise_error(Watir::Exception::UnknownFrameException) 81 | end 82 | 83 | it "raises UnknownFrameException when accessing a non-existing subframe" do 84 | expect { browser.frame(name: "frame1").frame(name: "no_such_name").id }.to raise_error(Watir::Exception::UnknownFrameException) 85 | end 86 | 87 | it "raises UnknownObjectException when accessing a non-existing element inside an existing frame" do 88 | expect { browser.frame(index: 0).p(index: 1337).id }.to raise_error(Watir::Exception::UnknownObjectException) 89 | end 90 | 91 | it "raises NoMethodError when trying to access attributes it doesn't have" do 92 | expect { browser.frame(index: 0).foo }.to raise_error(NoMethodError) 93 | end 94 | 95 | it "is able to set a field" do 96 | browser.frame(index: 0).text_field(name: 'senderElement').set("new value") 97 | expect(browser.frame(index: 0).text_field(name: 'senderElement').value).to eq "new value" 98 | end 99 | 100 | it "can access the frame's parent element after use" do 101 | el = browser.frameset 102 | el.frame.text_field.value 103 | expect(el.attribute_value("cols")).to be_kind_of(String) 104 | end 105 | 106 | describe "#execute_script" do 107 | it "executes the given javascript in the specified frame" do 108 | frame = browser.frame(index: 0) 109 | expect(frame.div(id: 'set_by_js').text).to eq "" 110 | frame.execute_script(%Q{document.getElementById('set_by_js').innerHTML = 'Art consists of limitation. The most beautiful part of every picture is the frame.'}) 111 | expect(frame.div(id: 'set_by_js').text).to eq "Art consists of limitation. The most beautiful part of every picture is the frame." 112 | end 113 | end 114 | 115 | describe "#html" do 116 | it "returns the full HTML source of the frame" do 117 | browser.goto WatirSpec.url_for("frames.html") 118 | expect(browser.frame.html.downcase).to include("frame 1") 119 | end 120 | end 121 | 122 | end 123 | -------------------------------------------------------------------------------- /dt_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require File.expand_path("../spec_helper", __FILE__) 3 | 4 | describe "Dt" do 5 | 6 | before :each do 7 | browser.goto(WatirSpec.url_for("definition_lists.html")) 8 | end 9 | 10 | # Exists method 11 | describe "#exists?" do 12 | it "returns true if the element exists" do 13 | expect(browser.dt(id: "experience")).to exist 14 | expect(browser.dt(class: "current-industry")).to exist 15 | expect(browser.dt(xpath: "//dt[@id='experience']")).to exist 16 | expect(browser.dt(index: 0)).to exist 17 | end 18 | 19 | it "returns the first dt if given no args" do 20 | expect(browser.dt).to exist 21 | end 22 | 23 | it "returns false if the element does not exist" do 24 | expect(browser.dt(id: "no_such_id")).to_not exist 25 | end 26 | 27 | it "raises TypeError when 'what' argument is invalid" do 28 | expect { browser.dt(id: 3.14).exists? }.to raise_error(TypeError) 29 | end 30 | 31 | it "raises MissingWayOfFindingObjectException when 'how' argument is invalid" do 32 | expect { browser.dt(no_such_how: 'some_value').exists? }.to raise_error(Watir::Exception::MissingWayOfFindingObjectException) 33 | end 34 | end 35 | 36 | # Attribute methods 37 | describe "#class_name" do 38 | it "returns the class attribute if the element exists" do 39 | expect(browser.dt(:id , "experience").class_name).to eq "industry" 40 | end 41 | 42 | it "returns an empty string if the element exists but the attribute doesn't" do 43 | expect(browser.dt(:id , "education").class_name).to eq "" 44 | end 45 | 46 | it "raises UnknownObjectException if the element does not exist" do 47 | expect { browser.dt(id: "no_such_id").class_name }.to raise_error(Watir::Exception::UnknownObjectException) 48 | expect { browser.dt(title: "no_such_title").class_name }.to raise_error(Watir::Exception::UnknownObjectException) 49 | expect { browser.dt(index: 1337).class_name }.to raise_error(Watir::Exception::UnknownObjectException) 50 | expect { browser.dt(xpath: "//dt[@id='no_such_id']").class_name }.to raise_error(Watir::Exception::UnknownObjectException) 51 | end 52 | end 53 | 54 | describe "#id" do 55 | it "returns the id attribute if the element exists" do 56 | expect(browser.dt(class: 'industry').id).to eq "experience" 57 | end 58 | 59 | it "returns an empty string if the element exists, but the attribute doesn't" do 60 | expect(browser.dt(class: 'current-industry').id).to eq "" 61 | end 62 | 63 | it "raises UnknownObjectException if the element does not exist" do 64 | expect {browser.dt(id: "no_such_id").id }.to raise_error(Watir::Exception::UnknownObjectException) 65 | expect {browser.dt(title: "no_such_id").id }.to raise_error(Watir::Exception::UnknownObjectException) 66 | expect {browser.dt(index: 1337).id }.to raise_error(Watir::Exception::UnknownObjectException) 67 | end 68 | end 69 | 70 | describe "#title" do 71 | it "returns the title of the element" do 72 | expect(browser.dt(id: "experience").title).to eq "experience" 73 | end 74 | end 75 | 76 | describe "#text" do 77 | it "returns the text of the element" do 78 | expect(browser.dt(id: "experience").text).to eq "Experience" 79 | end 80 | 81 | it "returns an empty string if the element exists but contains no text" do 82 | expect(browser.dt(class: 'noop').text).to eq "" 83 | end 84 | 85 | it "raises UnknownObjectException if the element does not exist" do 86 | expect { browser.dt(id: "no_such_id").text }.to raise_error(Watir::Exception::UnknownObjectException) 87 | expect { browser.dt(title: "no_such_title").text }.to raise_error(Watir::Exception::UnknownObjectException) 88 | expect { browser.dt(index: 1337).text }.to raise_error(Watir::Exception::UnknownObjectException) 89 | expect { browser.dt(xpath: "//dt[@id='no_such_id']").text }.to raise_error(Watir::Exception::UnknownObjectException) 90 | end 91 | end 92 | 93 | describe "#respond_to?" do 94 | it "returns true for all attribute methods" do 95 | expect(browser.dt(index: 0)).to respond_to(:id) 96 | expect(browser.dt(index: 0)).to respond_to(:class_name) 97 | expect(browser.dt(index: 0)).to respond_to(:style) 98 | expect(browser.dt(index: 0)).to respond_to(:text) 99 | expect(browser.dt(index: 0)).to respond_to(:title) 100 | end 101 | end 102 | 103 | # Manipulation methods 104 | describe "#click" do 105 | it "fires events when clicked" do 106 | expect(browser.dt(id: 'education').text).to_not eq 'changed' 107 | browser.dt(id: 'education').click 108 | expect(browser.dt(id: 'education').text).to eq 'changed' 109 | end 110 | 111 | it "raises UnknownObjectException if the element does not exist" do 112 | expect { browser.dt(id: "no_such_id").click }.to raise_error(Watir::Exception::UnknownObjectException) 113 | expect { browser.dt(title: "no_such_title").click }.to raise_error(Watir::Exception::UnknownObjectException) 114 | expect { browser.dt(index: 1337).click }.to raise_error(Watir::Exception::UnknownObjectException) 115 | expect { browser.dt(xpath: "//dt[@id='no_such_id']").click }.to raise_error(Watir::Exception::UnknownObjectException) 116 | end 117 | end 118 | 119 | describe "#html" do 120 | it "returns the HTML of the element" do 121 | html = browser.dt(id: 'name').html 122 | expect(html).to match(%r[
.*Name.*
]mi) 123 | expect(html).to_not include('') 124 | end 125 | end 126 | 127 | end 128 | -------------------------------------------------------------------------------- /html/tables.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Tables 5 | 6 | 7 | 8 | 9 |
10 |

Tables

11 |

Semantic table

12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 |
Income tax information for Gregory House and Hugh Laurie
Before income taxIncome taxAfter income tax
Sum24 3495 57718 722
March 2008
Gregory House5 9341 3474 587
Hugh Laurie6 3001 4794 821
April 2008
Gregory House5 8631 3314 532
Hugh Laurie6 2521 4204 832
73 |

Table inside a table

74 | 75 | 76 | 79 | 82 | 83 | 84 | 87 | 100 | 101 | 102 | 105 | 108 | 109 |
77 | Table 1, Row 1, Cell 1 78 | 80 | Table 1, Row 1, Cell 2 81 |
85 | Table 1, Row 2, Cell 1 86 | 88 | Table 1, Row 2, Cell 2 89 | 90 | 91 | 94 | 97 | 98 |
92 | Table 2, Row 1, Cell 1 93 | 95 | Table 2, Row 1, Cell 2 96 |
99 |
103 | Table 1, Row 3, Cell 1 104 | 106 | Table 1, Row 3, Cell 2 107 |
110 |

Colspan

111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 |
Colspan 2
No colspan attributeNo colspan attribute
120 | 121 | -------------------------------------------------------------------------------- /span_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require File.expand_path("../spec_helper", __FILE__) 3 | 4 | describe "Span" do 5 | 6 | before :each do 7 | browser.goto(WatirSpec.url_for("non_control_elements.html")) 8 | end 9 | 10 | # Exists method 11 | describe "#exist?" do 12 | it "returns true if the 'span' exists" do 13 | expect(browser.span(id: "lead")).to exist 14 | expect(browser.span(id: /lead/)).to exist 15 | expect(browser.span(text: "Dubito, ergo cogito, ergo sum.")).to exist 16 | expect(browser.span(text: /Dubito, ergo cogito, ergo sum/)).to exist 17 | expect(browser.span(class: "lead")).to exist 18 | expect(browser.span(class: /lead/)).to exist 19 | expect(browser.span(index: 0)).to exist 20 | expect(browser.span(xpath: "//span[@id='lead']")).to exist 21 | end 22 | 23 | it "returns the first span if given no args" do 24 | expect(browser.span).to exist 25 | end 26 | 27 | it "returns false if the element doesn't exist" do 28 | expect(browser.span(id: "no_such_id")).to_not exist 29 | expect(browser.span(id: /no_such_id/)).to_not exist 30 | expect(browser.span(text: "no_such_text")).to_not exist 31 | expect(browser.span(text: /no_such_text/)).to_not exist 32 | expect(browser.span(class: "no_such_class")).to_not exist 33 | expect(browser.span(class: /no_such_class/)).to_not exist 34 | expect(browser.span(index: 1337)).to_not exist 35 | expect(browser.span(xpath: "//span[@id='no_such_id']")).to_not exist 36 | end 37 | 38 | it "raises TypeError when 'what' argument is invalid" do 39 | expect { browser.span(id: 3.14).exists? }.to raise_error(TypeError) 40 | end 41 | 42 | it "raises MissingWayOfFindingObjectException when 'how' argument is invalid" do 43 | expect { browser.span(no_such_how: 'some_value').exists? }.to raise_error(Watir::Exception::MissingWayOfFindingObjectException) 44 | end 45 | end 46 | 47 | # Attribute methods 48 | describe "#class_name" do 49 | it "returns the class attribute" do 50 | expect(browser.span(index: 0).class_name).to eq 'lead' 51 | end 52 | 53 | it "returns an empty string if the element exists and the attribute doesn't" do 54 | expect(browser.span(index: 2).class_name).to eq '' 55 | end 56 | 57 | it "raises UnknownObjectException if the span doesn't exist" do 58 | expect { browser.span(id: 'no_such_id').class_name }.to raise_error(Watir::Exception::UnknownObjectException) 59 | end 60 | end 61 | 62 | describe "#id" do 63 | it "returns the id attribute" do 64 | expect(browser.span(index: 0).id).to eq "lead" 65 | end 66 | 67 | it "returns an empty string if the element exists and the attribute doesn't" do 68 | expect(browser.span(index: 2).id).to eq '' 69 | end 70 | 71 | it "raises UnknownObjectException if the span doesn't exist" do 72 | expect { browser.span(id: "no_such_id").id }.to raise_error(Watir::Exception::UnknownObjectException) 73 | expect { browser.span(index: 1337).id }.to raise_error(Watir::Exception::UnknownObjectException) 74 | end 75 | end 76 | 77 | describe "#title" do 78 | it "returns the title attribute" do 79 | expect(browser.span(index: 0).title).to eq 'Lorem ipsum' 80 | end 81 | 82 | it "returns an empty string if the element exists and the attribute doesn't" do 83 | expect(browser.span(index: 2).title).to eq '' 84 | end 85 | 86 | it "raises UnknownObjectException if the span doesn't exist" do 87 | expect { browser.span(id: 'no_such_id').title }.to raise_error(Watir::Exception::UnknownObjectException) 88 | expect { browser.span(xpath: "//span[@id='no_such_id']").title }.to raise_error(Watir::Exception::UnknownObjectException) 89 | end 90 | end 91 | 92 | describe "#text" do 93 | it "returns the text of the span" do 94 | expect(browser.span(index: 1).text).to eq 'Sed pretium metus et quam. Nullam odio dolor, vestibulum non, tempor ut, vehicula sed, sapien. Vestibulum placerat ligula at quam. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.' 95 | end 96 | 97 | it "returns an empty string if the element doesn't contain any text" do 98 | expect(browser.span(index: 4).text).to eq '' 99 | end 100 | 101 | it "raises UnknownObjectException if the span doesn't exist" do 102 | expect { browser.span(id: 'no_such_id').text }.to raise_error(Watir::Exception::UnknownObjectException) 103 | expect { browser.span(:xpath , "//span[@id='no_such_id']").text }.to raise_error(Watir::Exception::UnknownObjectException) 104 | end 105 | end 106 | 107 | describe "#respond_to?" do 108 | it "returns true for all attribute methods" do 109 | expect(browser.span(index: 0)).to respond_to(:class_name) 110 | expect(browser.span(index: 0)).to respond_to(:id) 111 | expect(browser.span(index: 0)).to respond_to(:title) 112 | expect(browser.span(index: 0)).to respond_to(:text) 113 | end 114 | end 115 | 116 | # Other 117 | describe "#click" do 118 | it "fires events" do 119 | expect(browser.span(class: 'footer').text).to_not include('Javascript') 120 | browser.span(class: 'footer').click 121 | expect(browser.span(class: 'footer').text).to include('Javascript') 122 | end 123 | 124 | it "raises UnknownObjectException if the span doesn't exist" do 125 | expect { browser.span(id: "no_such_id").click }.to raise_error(Watir::Exception::UnknownObjectException) 126 | expect { browser.span(title: "no_such_title").click }.to raise_error(Watir::Exception::UnknownObjectException) 127 | end 128 | end 129 | 130 | end 131 | --------------------------------------------------------------------------------