Module: Symbiont::Enclosers

Included in:
Symbiont
Defined in:
lib/symbiont/enclosers.rb

Instance Method Summary collapse

Instance Method Details

#wait_for(timeout = Symbiont.page_level_wait, message = nil, &block) ⇒ Object

Provides a context for an action that must succeed within a given time period. The logic here is simply that the result of the action will be true (meaning the action was carried out) or false, which means the action did not succeed in the time allotted.

Examples:

@page.wait_for(5, 'page with expected title not found') do
  @page.title.should == "Test App"
end

Parameters:

  • timeout (Integer) (defaults to: Symbiont.page_level_wait)

    the amount of time in seconds to wait

  • message (String) (defaults to: nil)

    the text to return if the action did not occur in time

  • block (Proc)

    the code that calls the desired action



16
17
18
# File 'lib/symbiont/enclosers.rb', line 16

def wait_for(timeout=Symbiont.page_level_wait, message=nil, &block)
  platform.wait_for(timeout, message, &block)
end

#will_alert(encloser = nil, &block) ⇒ String

Provides a context for an action that will generate a JavaScript alert message box. The alert invocation will be overridden by the platform.

Examples:

response = @page.will_alert do
  @page.submitForm
end

Parameters:

  • block (Proc)

    the code that generates the alert

Returns:

  • (String)

    the message contained in the alert message box



81
82
83
# File 'lib/symbiont/enclosers.rb', line 81

def will_alert(encloser=nil, &block)
  platform.will_alert(encloser, &block)
end

#will_confirm(response, encloser = nil, &block) ⇒ String

Provides a context for an action that will generate a JavaScript confirmation message box. The confirmation invocation will be overridden by the platform.

Examples:

response = @page.will_confirm(true) do
  @page.areYouSure
end

Parameters:

  • response (bool)

    true to accept the confirmation, false to cancel it

  • block (Proc)

    the code that generates the confirmation

Returns:

  • (String)

    the message contained in the confirmation message box



97
98
99
# File 'lib/symbiont/enclosers.rb', line 97

def will_confirm(response, encloser=nil, &block)
  platform.will_confirm(response, encloser, &block)
end

#will_prompt(response, encloser = nil, &block) ⇒ Hash

Provides a context for an action that will generate a JavaScript prompt message box. The prompt invocation will be overridden by the platform.

the value that the prompt had before the response was applied

Examples:

response = @page.will_prompt("use this") do
  @page.useValue
end

Parameters:

  • response (String)

    the value to be used in the prompt

  • block (Proc)

    the code that generates the prompt

Returns:

  • (Hash)

    :message for the prompt message, :default_value for



113
114
115
# File 'lib/symbiont/enclosers.rb', line 113

def will_prompt(response, encloser=nil, &block)
  platform.will_prompt(response, encloser, &block)
end

#within_frame(locator, encloser = nil, &block) ⇒ Object

Used to identify a web object as existing within an enclosing object like a frame or an iframe. It is possible to nest by passing in parent enclosers as the second parameter.

only valid locators here are :id, :index, and :name encloser

Examples:

within_frame(id: "loginSection") do |encloser|
  text_field :username, id: "userName", frame: encloser
  button :login, id: "btnSubmit", frame: encloser
end

Parameters:

  • locator (String)

    how an encloser will be referenced; the

  • encloser (defaults to: nil)

    a parent encloser that is passed from a previous call

  • block (optional)

    that contains calls to web objects within the



51
52
53
# File 'lib/symbiont/enclosers.rb', line 51

def within_frame(locator, encloser=nil, &block)
  platform.within_frame(locator, encloser, &block)
end

#within_modal(&block) ⇒ Object

Used to identify a web object as existing within an enclosing object like a modal dialog box. What this does is override the normal call to showModalDialog and opens a window instead. In order to use this new window, you have to attach to it.



59
60
61
62
63
64
65
66
67
68
69
# File 'lib/symbiont/enclosers.rb', line 59

def within_modal(&block)
  convert_modal_to_window = %Q{
    window.showModalDialog = function(sURL, vArguments, sFeatures) {
      window.dialogArguments = vArguments;
      modalWin = window.open(sURL, 'modal', sFeatures);
      return modalWin;
    }
  }
  @browser.execute_script(convert_modal_to_window)
  yield if block_given?
end

#within_window(locator, &block) ⇒ Object

Used to identify a web object or action on a web object as existing within an enclosing window object. The window can be referenced using either the title attribute of the window or a direct URL. The URL does not have to be the entire URL; it can just be a page name.

action on or within the window

Examples:

page.within_window(title: "Report Page")
page.within_window(url: report.html)

Parameters:

  • locator (Hash)

    the :title or :url of the window

  • block (Proc; optional)

    any code that should be executed as an



32
33
34
# File 'lib/symbiont/enclosers.rb', line 32

def within_window(locator, &block)
  platform.within_window(locator, &block)
end