forked from watir/watirspec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tr_spec.rb
90 lines (73 loc) · 2.82 KB
/
tr_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
# encoding: utf-8
require File.expand_path("../spec_helper", __FILE__)
describe "TableRow" do
before :each do
browser.goto(WatirSpec.url_for("tables.html"))
end
describe "#exists?" do
it "returns true if the table row exists" do
expect(browser.tr(id: "outer_first")).to exist
expect(browser.tr(id: /outer_first/)).to exist
expect(browser.tr(index: 0)).to exist
browser.tr(xpath: "//tr[@id='outer_first']")
end
it "returns the first row if given no args" do
expect(browser.tr).to exist
end
it "returns false if the table row doesn't exist" do
expect(browser.tr(id: "no_such_id")).to_not exist
expect(browser.tr(id: /no_such_id/)).to_not exist
expect(browser.tr(index: 1337)).to_not exist
browser.tr(xpath: "//tr[@id='no_such_id']")
end
it "raises TypeError when 'what' argument is invalid" do
expect { browser.tr(id: 3.14).exists? }.to raise_error(TypeError)
end
it "raises MissingWayOfFindingObjectException when 'how' argument is invalid" do
expect { browser.tr(no_such_how: 'some_value').exists? }.to raise_error(Watir::Exception::MissingWayOfFindingObjectException)
end
end
describe "#click" do
bug "http://github.com/watir/watir-webdriver/issues/issue/32",
%i(webdriver internet_explorer),
%i(webdriver chrome) do
it "fires the row's onclick event" do
browser.tr(id: 'inner_first').click
expect(messages).to include('tr')
end
end
end
describe "#[]" do
let(:table) { browser.table(id: 'outer') }
it "returns the nth cell of the row" do
expect(table[0][0].text).to eq "Table 1, Row 1, Cell 1"
expect(table[2][0].text).to eq "Table 1, Row 3, Cell 1"
end
not_compliant_on :webdriver do #[] returns watir elements (lazy locate)
it "raises UnknownCellException if the index is out of bounds" do
expect { table.tr(index: 0)[1337] }.to raise_error(Watir::Exception::UnknownCellException)
expect { table[0][1337] }.to raise_error(Watir::Exception::UnknownCellException)
end
end
end
describe "#cells" do
let(:table) { browser.table(id: 'outer') }
it "returns the correct number of cells" do
expect(table[0].cells.length).to eq 2
expect(table[1].cells.length).to eq 2
expect(table[2].cells.length).to eq 2
end
it "finds cells in the table" do
expect(table[0].cells(text: /Table 1/).size).to eq 2
end
it "does not find cells from nested tables" do
expect(table[1].cell(id: "t2_r1_c1")).to_not exist
expect(table[1].cell(id: /t2_r1_c1/)).to_not exist
end
it "iterates correctly through the cells of the row" do
browser.table(id: 'outer').row(index: 1).cells.each_with_index do |cell, idx|
expect(cell.id).to eq "t1_r2_c#{idx + 1}"
end
end
end
end