require 'spec_helper' describe Symbiont::Enclosers do let(:watir_browser) { mock_browser_for_watir } let(:watir_definition) { DefinitionTest.new(watir_browser) } describe "browser-level actions" do context "a definition using watir-webdriver" do it "should visit a page" do watir_browser.should_receive(:goto).with("http://localhost:4567") watir_definition.visit("http://localhost:4567") end it "should get the active url" do watir_browser.should_receive(:url).and_return("http://localhost:4567") watir_definition.url.should == "http://localhost:4567" end it "should get a screenshot" do watir_browser.should_receive(:wd).and_return(watir_browser) watir_browser.should_receive(:save_screenshot) watir_definition.screenshot("testing.png") end it "should run a script against the browser" do watir_browser.should_receive(:execute_script).twice.and_return("input") watir_definition.run_script("return document.activeElement").should == "input" watir_definition.execute_script("return document.activeElement").should == "input" end end end describe "page-level actions" do context "a definition using watir-webdriver" do it "should return all the text on a page" do watir_browser.should_receive(:text).and_return("page text") watir_definition.text.should == "page text" end it "should return all the markup on a page" do watir_browser.should_receive(:html).twice.and_return("

Page Title

") watir_definition.markup.should == "

Page Title

" watir_definition.html.should == "

Page Title

" end it "should return the title of a page" do watir_browser.should_receive(:title).and_return("Page Title") watir_definition.title.should == "Page Title" end it "should return the web object that has focus" do watir_browser.should_receive(:execute_script).and_return(watir_browser) watir_browser.should_receive(:tag_name).twice.and_return(:input) watir_browser.should_receive(:type).and_return(:submit) watir_definition.focus.class.should == Symbiont::WebObjects::Button end it "should wait for jquery pending requests to finish" do watir_browser.should_receive(:run_script).with('return jQuery.active').and_return(0) watir_definition.wait_for_pending_requests end it "should return an exception if pending requests did not finish" do watir_browser.should_receive(:run_script).with('return jQuery.active') watir_browser.should_receive(:run_script).with('return jQuery.active').and_return(1) expect { watir_definition.wait_for_pending_requests(1) }.to raise_error end end end end