This repository has been archived by the owner on Jun 6, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathimage_spec.rb
165 lines (136 loc) · 6.3 KB
/
image_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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# encoding: utf-8
require File.expand_path("../spec_helper", __FILE__)
describe "Image" do
before :each do
browser.goto(WatirSpec.url_for("images.html"))
end
# Exists method
describe "#exists?" do
it "returns true when the image exists" do
expect(browser.image(id: 'square')).to exist
expect(browser.image(id: /square/)).to exist
expect(browser.image(src: 'images/circle.png')).to exist
expect(browser.image(src: /circle/)).to exist
expect(browser.image(alt: 'circle')).to exist
expect(browser.image(alt: /cir/)).to exist
expect(browser.image(title: 'Circle')).to exist
end
it "returns the first image if given no args" do
expect(browser.image).to exist
end
it "returns false when the image doesn't exist" do
expect(browser.image(id: 'no_such_id')).to_not exist
expect(browser.image(id: /no_such_id/)).to_not exist
expect(browser.image(src: 'no_such_src')).to_not exist
expect(browser.image(src: /no_such_src/)).to_not exist
expect(browser.image(alt: 'no_such_alt')).to_not exist
expect(browser.image(alt: /no_such_alt/)).to_not exist
expect(browser.image(title: 'no_such_title')).to_not exist
expect(browser.image(title: /no_such_title/)).to_not exist
end
it "raises TypeError when 'what' argument is invalid" do
expect { browser.image(id: 3.14).exists? }.to raise_error(TypeError)
end
it "raises MissingWayOfFindingObjectException when 'how' argument is invalid" do
expect { browser.image(no_such_how: 'some_value').exists? }.to raise_error(Watir::Exception::MissingWayOfFindingObjectException)
end
end
# Attribute methods
describe "#alt" do
it "returns the alt attribute of the image if the image exists" do
expect(browser.image(id: 'square').alt).to eq "square"
expect(browser.image(title: 'Circle').alt).to eq 'circle'
end
it "returns an empty string if the image exists and the attribute doesn't" do
expect(browser.image(index: 0).alt).to eq ""
end
it "raises UnknownObjectException if the image doesn't exist" do
expect { browser.image(index: 1337).alt }.to raise_error(Watir::Exception::UnknownObjectException)
end
end
describe "#id" do
it "returns the id attribute of the image if the image exists" do
expect(browser.image(title: 'Square').id).to eq 'square'
end
it "returns an empty string if the image exists and the attribute doesn't" do
expect(browser.image(index: 0).id).to eq ""
end
it "raises UnknownObjectException if the image doesn't exist" do
expect { browser.image(index: 1337).id }.to raise_error(Watir::Exception::UnknownObjectException)
end
end
describe "#src" do
it "returns the src attribute of the image if the image exists" do
expect(browser.image(id: 'square').src).to include("square.png")
end
it "returns an empty string if the image exists and the attribute doesn't" do
expect(browser.image(index: 0).src).to eq ""
end
it "raises UnknownObjectException if the image doesn't exist" do
expect { browser.image(index: 1337).src }.to raise_error(Watir::Exception::UnknownObjectException)
end
end
describe "#title" do
it "returns the title attribute of the image if the image exists" do
expect(browser.image(id: 'square').title).to eq 'Square'
end
it "returns an empty string if the image exists and the attribute doesn't" do
expect(browser.image(index: 0).title).to eq ""
end
it "raises UnknownObjectException if the image doesn't exist" do
expect { browser.image(index: 1337).title }.to raise_error(Watir::Exception::UnknownObjectException)
end
end
describe "#respond_to?" do
it "returns true for all attribute methods" do
expect(browser.image(index: 0)).to respond_to(:class_name)
expect(browser.image(index: 0)).to respond_to(:id)
expect(browser.image(index: 0)).to respond_to(:style)
expect(browser.image(index: 0)).to respond_to(:text)
end
end
# Manipulation methods
describe "#click" do
it "raises UnknownObjectException when the image doesn't exist" do
expect { browser.image(id: 'missing_attribute').click }.to raise_error(Watir::Exception::UnknownObjectException)
expect { browser.image(class: 'missing_attribute').click }.to raise_error(Watir::Exception::UnknownObjectException)
expect { browser.image(src: 'missing_attribute').click }.to raise_error(Watir::Exception::UnknownObjectException)
expect { browser.image(alt: 'missing_attribute').click }.to raise_error(Watir::Exception::UnknownObjectException)
end
end
describe "#height" do
it "returns the height of the image if the image exists" do
expect(browser.image(id: 'square').height).to eq 88
end
it "raises UnknownObjectException if the image doesn't exist" do
expect { browser.image(index: 1337).height }.to raise_error(Watir::Exception::UnknownObjectException)
end
end
describe "#width" do
it "returns the width of the image if the image exists" do
expect(browser.image(id: 'square').width).to eq 88
end
it "raises UnknownObjectException if the image doesn't exist" do
expect { browser.image(index: 1337).width }.to raise_error(Watir::Exception::UnknownObjectException)
end
end
# Other
bug "https://bugzilla.mozilla.org/show_bug.cgi?id=1297339", :firefox do
describe "#loaded?" do
it "returns true if the image has been loaded" do
expect(browser.image(title: 'Circle')).to be_loaded
expect(browser.image(alt: 'circle')).to be_loaded
expect(browser.image(alt: /circle/)).to be_loaded
end
it "returns false if the image has not been loaded" do
expect(browser.image(id: 'no_such_file')).to_not be_loaded
end
it "raises UnknownObjectException if the image doesn't exist" do
expect { browser.image(id: 'no_such_image').loaded? }.to raise_error(Watir::Exception::UnknownObjectException)
expect { browser.image(src: 'no_such_image').loaded? }.to raise_error(Watir::Exception::UnknownObjectException)
expect { browser.image(alt: 'no_such_image').loaded? }.to raise_error(Watir::Exception::UnknownObjectException)
expect { browser.image(index: 1337).loaded? }.to raise_error(Watir::Exception::UnknownObjectException)
end
end
end
end