Module: SpecTest::Generators

Defined in:
lib/spectest/generators.rb

Instance Method Summary collapse

Instance Method Details

#button(identifier, locator = nil, &block) ⇒ Object

Creates methods to do the following:

Click a button object.
Return a button object.

Parameters:

  • identifier (String)

    how a button will be referred to

  • locator (Hash) (defaults to: nil)

    how a button will be recognized

  • []optional]

    block to be invoked when object method is called



64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/spectest/generators.rb', line 64

def button(identifier, locator=nil, &block)
  define_method(identifier) do
    return @platform.click_button_for locator.clone unless block_given?
    self.send("#{identifer}_object").click
  end

  define_method("#{identifier}_object") do
    return process_block(&block) if block_given?
    @platform.get_button_for locator.clone
  end

  alias_method "#{identifier}_button".to_sym, "#{identifier}_object".to_sym
end

Create methods to do the following:

Select a link object.
Return a link object.

Parameters:

  • identifier (String)

    how a link will be referred to

  • locator (Hash) (defaults to: nil)

    how a link will be recognized

  • block (optional)

    to be invoked when object method is called



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/spectest/generators.rb', line 18

def link(identifier, locator=nil, &block)
  define_method(identifier) do
    return @platform.click_link_for locator.clone unless block_given?
    self.send("#{identifier}_object").click
  end
  
  define_method("#{identifier}_object") do
    return process_block(&block) if block_given?
    @platform.get_link_for locator.clone
  end
  
  alias_method "#{identifier}_link".to_sym, "#{identifier}_object".to_sym
end

#text_field(identifier, locator = nil, &block) ⇒ Object

Creates methods to do the following:

Enter text into a text field object
Get the text that is in a text field object
Return a text field object.

Parameters:

  • identifier (String)

    how a text field will be referred to

  • locator (Hash) (defaults to: nil)

    how a text field will be recognized

  • block (optional)

    to be invoked when object method is called



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/spectest/generators.rb', line 39

def text_field(identifier, locator=nil, &block)
  define_method(identifier) do
    return @platform.get_text_field_value_for locator.clone unless block_given?
    self.send("#{identifier}_object").value
  end

  define_method("#{identifier}=") do |value|
    return @platform.set_text_field_value_for(locator.clone, value) unless block_given?
    self.send("{identifier}_object").value = value
  end

  define_method("#{identifier}_object") do
    return process_block(&block) if block_given?
    @platform.get_text_field_for locator.clone
  end

  alias_method "#{identifier}_text_field".to_sym, "#{identifier}_object".to_sym
end

#url_is(url) ⇒ Object

Allows you to specify a direct URL as part of a page object.

Parameters:

  • url (String)

    the address for the page.



6
7
8
9
10
# File 'lib/spectest/generators.rb', line 6

def url_is(url)
  define_method("goto") do
    @platform.navigate_to url
  end
end