forked from watir/watirspec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hidden_spec.rb
103 lines (86 loc) · 3.92 KB
/
hidden_spec.rb
1
2
3
4
5
6
7
8
9
10
11
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# encoding: utf-8
require File.expand_path("../spec_helper", __FILE__)
describe "Hidden" do
before :each do
browser.goto(WatirSpec.url_for("forms_with_input_elements.html"))
end
# Exist method
describe "#exists?" do
it "returns true if the element exists" do
expect(browser.hidden(id: 'new_user_interests_dolls')).to exist
expect(browser.hidden(id: /new_user_interests_dolls/)).to exist
expect(browser.hidden(name: 'new_user_interests')).to exist
expect(browser.hidden(name: /new_user_interests/)).to exist
expect(browser.hidden(value: 'dolls')).to exist
expect(browser.hidden(value: /dolls/)).to exist
expect(browser.hidden(class: 'fun')).to exist
expect(browser.hidden(class: /fun/)).to exist
expect(browser.hidden(index: 0)).to exist
expect(browser.hidden(xpath: "//input[@id='new_user_interests_dolls']")).to exist
end
it "returns the first hidden if given no args" do
expect(browser.hidden).to exist
end
it "returns false if the element does not exist" do
expect(browser.hidden(id: 'no_such_id')).to_not exist
expect(browser.hidden(id: /no_such_id/)).to_not exist
expect(browser.hidden(name: 'no_such_name')).to_not exist
expect(browser.hidden(name: /no_such_name/)).to_not exist
expect(browser.hidden(value: 'no_such_value')).to_not exist
expect(browser.hidden(value: /no_such_value/)).to_not exist
expect(browser.hidden(text: 'no_such_text')).to_not exist
expect(browser.hidden(text: /no_such_text/)).to_not exist
expect(browser.hidden(class: 'no_such_class')).to_not exist
expect(browser.hidden(class: /no_such_class/)).to_not exist
expect(browser.hidden(index: 1337)).to_not exist
expect(browser.hidden(xpath: "//input[@id='no_such_id']")).to_not exist
end
it "raises TypeError when 'what' argument is invalid" do
expect { browser.hidden(id: 3.14).exists? }.to raise_error(TypeError)
end
it "raises MissingWayOfFindingObjectException when 'how' argument is invalid" do
expect { browser.hidden(no_such_how: 'some_value').exists? }.to raise_error(Watir::Exception::MissingWayOfFindingObjectException)
end
end
# Attribute methods
describe "#id" do
it "returns the id attribute if the text field exists" do
expect(browser.hidden(index: 1).id).to eq "new_user_interests_dolls"
end
it "raises UnknownObjectException if the text field doesn't exist" do
expect { browser.hidden(index: 1337).id }.to raise_error(Watir::Exception::UnknownObjectException)
end
end
describe "#name" do
it "returns the name attribute if the text field exists" do
expect(browser.hidden(index: 1).name).to eq "new_user_interests"
end
it "raises UnknownObjectException if the text field doesn't exist" do
expect { browser.hidden(index: 1337).name }.to raise_error(Watir::Exception::UnknownObjectException)
end
end
describe "#type" do
it "returns the type attribute if the text field exists" do
expect(browser.hidden(index: 1).type).to eq "hidden"
end
it "raises UnknownObjectException if the text field doesn't exist" do
expect { browser.hidden(index: 1337).type }.to raise_error(Watir::Exception::UnknownObjectException)
end
end
describe "#value" do
it "returns the value attribute if the text field exists" do
expect(browser.hidden(index: 1).value).to eq "dolls"
end
it "raises UnknownObjectException if the text field doesn't exist" do
expect { browser.hidden(index: 1337).value }.to raise_error(Watir::Exception::UnknownObjectException)
end
end
describe "#respond_to?" do
it "returns true for all attribute methods" do
expect(browser.hidden(index: 1)).to respond_to(:id)
expect(browser.hidden(index: 1)).to respond_to(:name)
expect(browser.hidden(index: 1)).to respond_to(:type)
expect(browser.hidden(index: 1)).to respond_to(:value)
end
end
end