require File.dirname(__FILE__) + '/spec_helper.rb' describe TableHeader do before :all do @browser = IE.new add_spec_checker(@browser) end before :each do @browser = IE.new @browser.goto(TEST_HOST + "/tables.html") end describe "#exists" do it "should return true if the table theader exists (page context)" do @browser.thead(:id, 'tax_headers').should exist @browser.thead(:id, /tax_headers/).should exist @browser.thead(:index, 1).should exist @browser.thead(:xpath, "//thead[@id='tax_headers']").should exist end it "should return true if the table theader exists (table context)" do @browser.table(:index, 1).thead(:id, 'tax_headers').should exist @browser.table(:index, 1).thead(:id, /tax_headers/).should exist @browser.table(:index, 1).thead(:index, 1).should exist @browser.table(:index, 1).thead(:xpath, "//thead[@id='tax_headers']").should exist end it "should return true if the element exists (default how = :id)" do @browser.thead("tax_headers").should exist @browser.table(:index, 1).thead("tax_headers").should exist end it "should return false if the table theader exists (page context)" do @browser.thead(:id, 'no_such_id').should_not exist @browser.thead(:id, /no_such_id/).should_not exist @browser.thead(:index, 1337).should_not exist @browser.thead(:xpath, "//thead[@id='no_such_id']").should_not exist end it "should return false if the table theader exists (table context)" do @browser.table(:index, 1).thead(:id, 'no_such_id').should_not exist @browser.table(:index, 1).thead(:id, /no_such_id/).should_not exist @browser.table(:index, 1).thead(:index, 1337).should_not exist @browser.table(:index, 1).thead(:xpath, "//thead[@id='no_such_id']").should_not exist end it "should raise ArgumentError when 'what' argument is invalid" do lambda { @browser.thead(:id, 3.14).exists? }.should raise_error(ArgumentError) lambda { @browser.table(:index, 1).thead(:id, 3.14).exists? }.should raise_error(ArgumentError) end it "should raise MissingWayOfFindingObjectException when 'how' argument is invalid" do lambda { @browser.thead(:no_such_how, 'some_value').exists? }.should raise_error(MissingWayOfFindingObjectException) lambda { @browser.table(:index, 1).thead(:no_such_how, 'some_value').exists? }.should raise_error(MissingWayOfFindingObjectException) end end describe "#length" do it "should return the correct number of table bodies (page context)" do @browser.thead(:id, 'tax_headers').length.should == 1 end it "should return the correct number of table bodies (table context)" do @browser.table(:index, 1).thead(:id, 'tax_headers').length.should == 1 end end describe "#[]" do it "should return the row at the given index (page context)" do @browser.thead(:id, 'tax_headers')[1].text.should == 'Before income tax Income tax After income tax' @browser.thead(:id, 'tax_headers')[1][2].text.should == 'Before income tax' @browser.thead(:id, 'tax_headers')[1][3].text.should == 'Income tax' end it "should return the row at the given index (table context)" do @browser.table(:index, 1).thead(:id, 'tax_headers')[1].text.should == 'Before income tax Income tax After income tax' @browser.table(:index, 1).thead(:id, 'tax_headers')[1][2].text.should == 'Before income tax' @browser.table(:index, 1).thead(:id, 'tax_headers')[1][3].text.should == 'Income tax' end end describe "#each" do it "should iterate through rows correctly" do theader = @browser.table(:index, 1).thead(:id, 'tax_headers') index = 1 theader.each do |r| r.name.should == @browser.row(:index, index).name r.id.should == @browser.row(:index, index).id r.value.should == @browser.row(:index, index).value index += 1 end index.should_not == 1 end end after :all do @browser.close end end