Module: Bauxite::SelectorModule

Included in:
Selector
Defined in:
lib/bauxite/core/selector.rb

Overview

Selector common state and behavior.

Instance Method Summary collapse

Instance Method Details

#find(selector, &block) ⇒ Object

Searches for elements using the specified selector string.

For more information see Context#find.

Selectors calling this method should forward their block as well.

For example:

# === selectors/example.rb ======= #
class Selector
    # :category: Selector Methods
    def example(arg, &block)
        find(arg, &block)
    end
end
# === end selectors/example.rb === #

Raises:

  • (ArgumentError)


49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/bauxite/core/selector.rb', line 49

def find(selector, &block)
	data = selector.split('=', 2)
	type = data[0]
	arg  = data[-1]
	unless data.length == 2 and type =~ /^[a-z_]+$/i
		type = @default
		arg  = selector
	end
	raise ArgumentError, "Invalid selector type '#{type}'" unless Context::selectors.include? type
	
	custom_selectors = Context::selectors(false)
	return send(type            , arg, &block) if custom_selectors.include? type
	return send(type+'_selector', arg, &block) if custom_selectors.include? type+'_selector'
	selenium_find(type, arg, &block)
end

#initialize(ctx, default_selector) ⇒ Object

Constructs a new test selector instance.



28
29
30
31
# File 'lib/bauxite/core/selector.rb', line 28

def initialize(ctx, default_selector)
	@ctx = ctx
	@default = default_selector
end