Sha256: 0c11d16a558567b1f2feead84708fe5fd8b2d77dd38b4a0e2a42d5d09b9809db

Contents?: true

Size: 1.8 KB

Versions: 3

Compression:

Stored size: 1.8 KB

Contents

require File.expand_path("../spec_helper", __FILE__)

describe "SearchContext" do
  class TestSearchContext
    attr_reader :bridge, :ref

    include Selenium::WebDriver::SearchContext

    def initialize(bridge)
      @bridge = bridge
    end
  end

  let(:element)        { double(:Element)}
  let(:bridge)         { double(:Bridge).as_null_object   }
  let(:search_context) { TestSearchContext.new(bridge)  }

  context "finding a single element" do
    it "accepts a hash" do
      bridge.should_receive(:find_element_by).with('id', "bar", nil).and_return(element)
      search_context.find_element(:id => "bar").should == element
    end

    it "accepts two arguments" do
      bridge.should_receive(:find_element_by).with('id', "bar", nil).and_return(element)
      search_context.find_element(:id, "bar").should == element
    end

    it "raises an error if given an invalid 'by'" do
      lambda {
        search_context.find_element(:foo => "bar")
      }.should raise_error(ArgumentError, 'cannot find element by :foo')
    end

    it "does not modify the hash given" do
      selector = {:id => "foo"}

      search_context.find_element(selector)

      selector.should == {:id => "foo"}
    end
  end

  context "finding multiple elements" do
    it "accepts a hash" do
      bridge.should_receive(:find_elements_by).with('id', "bar", nil).and_return([])
      search_context.find_elements(:id => "bar").should == []
    end

    it "accepts two arguments" do
      bridge.should_receive(:find_elements_by).with('id', "bar", nil).and_return([])
      search_context.find_elements(:id, "bar").should == []
    end

    it "raises an error if given an invalid 'by'" do
      lambda {
        search_context.find_elements(:foo => "bar")
      }.should raise_error(ArgumentError, 'cannot find elements by :foo')
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
browserstack-webdriver-2.40.1 spec/unit/selenium/webdriver/search_context_spec.rb
browserstack-webdriver-0.0.22 spec/unit/selenium/webdriver/search_context_spec.rb
browserstack-webdriver-0.0.1 spec/unit/selenium/webdriver/search_context_spec.rb