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
/
tbody_spec.rb
97 lines (80 loc) · 3.63 KB
/
tbody_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
# encoding: utf-8
require File.expand_path("../spec_helper", __FILE__)
describe "TableBody" do
before :each do
browser.goto(WatirSpec.url_for("tables.html"))
end
describe "#exists?" do
it "returns true if the table body exists (page context)" do
expect(browser.tbody(id: 'first')).to exist
expect(browser.tbody(id: /first/)).to exist
expect(browser.tbody(index: 0)).to exist
expect(browser.tbody(xpath: "//tbody[@id='first']")).to exist
end
it "returns true if the table body exists (table context)" do
expect(browser.table(index: 0).tbody(id: 'first')).to exist
expect(browser.table(index: 0).tbody(id: /first/)).to exist
expect(browser.table(index: 0).tbody(index: 1)).to exist
expect(browser.table(index: 0).tbody(xpath: "//tbody[@id='first']")).to exist
end
it "returns the first table body if given no args" do
expect(browser.table.tbody).to exist
end
it "returns false if the table body doesn't exist (page context)" do
expect(browser.tbody(id: 'no_such_id')).to_not exist
expect(browser.tbody(id: /no_such_id/)).to_not exist
expect(browser.tbody(index: 1337)).to_not exist
expect(browser.tbody(xpath: "//tbody[@id='no_such_id']")).to_not exist
end
it "returns false if the table body doesn't exist (table context)" do
expect(browser.table(index: 0).tbody(id: 'no_such_id')).to_not exist
expect(browser.table(index: 0).tbody(id: /no_such_id/)).to_not exist
expect(browser.table(index: 0).tbody(index: 1337)).to_not exist
expect(browser.table(index: 0).tbody(xpath: "//tbody[@id='no_such_id']")).to_not exist
end
it "raises TypeError when 'what' argument is invalid" do
expect { browser.tbody(id: 3.14).exists? }.to raise_error(TypeError)
expect { browser.table(index: 0).tbody(id: 3.14).exists? }.to raise_error(TypeError)
end
it "raises MissingWayOfFindingObjectException when 'how' argument is invalid" do
expect { browser.tbody(no_such_how: 'some_value').exists? }.to raise_error(Watir::Exception::MissingWayOfFindingObjectException)
expect { browser.table(index: 0).tbody(no_such_how: 'some_value').exists? }.to raise_error(Watir::Exception::MissingWayOfFindingObjectException)
end
end
describe "#[]" do
it "returns the row at the given index (page context)" do
expect(browser.tbody(id: 'first')[0].text).to eq 'March 2008'
expect(browser.tbody(id: 'first')[1][0].text).to eq 'Gregory House'
expect(browser.tbody(id: 'first')[2][0].text).to eq 'Hugh Laurie'
end
it "returns the row at the given index (table context)" do
expect(browser.table(index: 0).tbody(id: 'first')[0].text).to eq 'March 2008'
expect(browser.table(index: 0).tbody(id: 'first')[1][0].text).to eq 'Gregory House'
expect(browser.table(index: 0).tbody(id: 'first')[2][0].text).to eq 'Hugh Laurie'
end
end
describe "#row" do
it "finds the first row matching the selector" do
row = browser.tbody(id: 'first').row(id: "gregory")
expect(row.tag_name).to eq "tr"
expect(row.id).to eq "gregory"
end
end
describe "#rows" do
it "finds rows matching the selector" do
rows = browser.tbody(id: 'first').rows(id: /h$/)
expect(rows.size).to eq 2
expect(rows.first.id).to eq "march"
expect(rows.last.id).to eq "hugh"
end
end
describe "#strings" do
it "returns the text of child cells" do
expect(browser.tbody(id: 'first').strings).to eq [
["March 2008", "", "", ""],
["Gregory House", "5 934", "1 347", "4 587"],
["Hugh Laurie", "6 300", "1 479", "4 821"]
]
end
end
end