require 'spec_helper' describe "Element for Watir" do before(:each) do @watir_driver = ::Watir::Element.new(nil, {}) @watir_element = ::PageObject::Elements::Element.new(@watir_driver, :platform => :watir_webdriver) end it "should know when it is visible" do @watir_driver.should_receive(:present?).and_return(true) @watir_element.visible?.should == true end it "should know when it is not visible" do @watir_driver.should_receive(:present?).and_return(false) @watir_element.visible?.should == false end it "should know when it exists" do @watir_driver.should_receive(:exists?).and_return(true) @watir_element.exists?.should == true end it "should know when it does not exist" do @watir_driver.should_receive(:exists?).and_return(false) @watir_element.exists?.should == false end it "should be able to return the text contained in the element" do @watir_driver.should_receive(:text).and_return("my text") @watir_element.text.should == "my text" end it "should know when it is equal to another" do @watir_driver.should_receive(:==).and_return(true) @watir_element.should == @watir_element end it "should return its tag name" do @watir_driver.should_receive(:tag_name).and_return("h1") @watir_element.tag_name.should == "h1" end it "should know its value" do @watir_driver.should_receive(:value).and_return("value") @watir_element.value.should == "value" end it "should know how to retrieve the value of an attribute" do @watir_driver.should_receive(:attribute_value).and_return(true) @watir_element.attribute("readonly").should be_true end it "should be clickable" do @watir_driver.should_receive(:click) @watir_element.click end it "should be double clickable" do @watir_driver.should_receive(:double_click) @watir_element.double_click end it "should be right clickable" do @watir_driver.should_receive(:right_click) @watir_element.right_click end it "should be able to block until it is present" do @watir_driver.should_receive(:wait_until_present).with(10) @watir_element.when_present(10) end it "should return the element when it is present" do @watir_driver.should_receive(:wait_until_present).with(10) element = @watir_element.when_present(10) element.should === @watir_element end it "should be able to block until it is visible" do ::Watir::Wait.should_receive(:until).with(10, "Element was not visible in 10 seconds") @watir_element.when_visible(10) end it "should return the element when it is visible" do ::Watir::Wait.should_receive(:until).with(10, "Element was not visible in 10 seconds") element = @watir_element.when_visible(10) element.should === @watir_element end it "should be able to block until it is not visible" do ::Watir::Wait.should_receive(:while).with(10, "Element still visible after 10 seconds") @watir_element.when_not_visible(10) end it "should return the element when it is not visible" do ::Watir::Wait.should_receive(:while).with(10, "Element still visible after 10 seconds") element = @watir_element.when_not_visible(10) element.should === @watir_element end it "should be able to block until a user define event fires true" do ::Watir::Wait.should_receive(:until).with(10, "Element blah") @watir_element.wait_until(10, "Element blah") {} end it "should send keys to the element" do @watir_driver.should_receive(:send_keys).with([:control, 'a']) @watir_element.send_keys([:control, 'a']) end it "should clear its' contents" do @watir_driver.should_receive(:clear) @watir_element.clear end end