Module: Selenium::Client::Extensions

Included in:
Base
Defined in:
lib/selenium/client/extensions.rb

Overview

Convenience methods not explicitely part of the protocol

Instance Method Summary collapse

Instance Method Details

#wait_for_ajax(timeout_in_seconds = nil) ⇒ Object

These for all Ajax request to finish (Only works if you are using prototype, the wait in happenning browser side)

See davidvollbracht.com/2008/6/4/30-days-of-tech-day-3-waitforajax for more background.



11
12
13
# File 'lib/selenium/client/extensions.rb', line 11

def wait_for_ajax(timeout_in_seconds=nil)
  wait_for_condition "selenium.browserbot.getCurrentWindow().Ajax.activeRequestCount == 0", timeout_in_seconds
end

#wait_for_effects(timeout_in_seconds = nil) ⇒ Object

Wait for all Prototype effects to be processed (the wait in happenning browser side).

Credits to github.com/brynary/webrat/tree/master



18
19
20
# File 'lib/selenium/client/extensions.rb', line 18

def wait_for_effects(timeout_in_seconds=nil)
  wait_for_condition "window.Effect.Queue.size() == 0", timeout_in_seconds
end

#wait_for_element(locator, timeout_in_seconds = nil) ⇒ Object

Wait for an element to be present (the wait in happenning browser side).



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/selenium/client/extensions.rb', line 23

def wait_for_element(locator, timeout_in_seconds=nil)
  script = <<-EOS
  var element;
  try {
    element = selenium.browserbot.findElement('#{locator}');
  } catch(e) {
    element = null;
  }
  element != null
  EOS

  wait_for_condition script, timeout_in_seconds
end

#wait_for_field_value(locator, expected_value, timeout_in_seconds = nil) ⇒ Object

Wait for a field to get a specific value (the wait in happenning browser side).



79
80
81
82
83
84
85
86
87
88
89
# File 'lib/selenium/client/extensions.rb', line 79

def wait_for_field_value(locator, expected_value, timeout_in_seconds=nil)
  script = "var element;
            try {
              element = selenium.browserbot.findElement('#{locator}');
            } catch(e) {
              element = null;
            }
            element != null && element.value == '#{expected_value}'"

  wait_for_condition script, timeout_in_seconds
end

#wait_for_no_element(locator, timeout_in_seconds = nil) ⇒ Object

Wait for an element to NOT be present (the wait in happenning browser side).



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/selenium/client/extensions.rb', line 38

def wait_for_no_element(locator, timeout_in_seconds=nil)
  script = <<-EOS
  var element;
  try {
    element = selenium.browserbot.findElement('#{locator}');
  } catch(e) {
    element = null;
  }
  element == null
  EOS

  wait_for_condition script, timeout_in_seconds
end

#wait_for_no_text(locator, original_text, timeout_in_seconds = nil) ⇒ Object

Wait for some text to NOT be present (the wait in happenning browser side).



66
67
68
69
70
71
72
73
74
75
76
# File 'lib/selenium/client/extensions.rb', line 66

def wait_for_no_text(locator, original_text, timeout_in_seconds=nil)
  script = "var element;
            try {
              element = selenium.browserbot.findElement('#{locator}');
            } catch(e) {
              element = null;
            }
            element != null && element.innerHTML != '#{original_text}'"

  wait_for_condition script, time
end

#wait_for_text(locator, text, timeout_in_seconds = nil) ⇒ Object

Wait for some text to be present (the wait in happenning browser side).



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/selenium/client/extensions.rb', line 53

def wait_for_text(locator, text, timeout_in_seconds=nil)
  script = "var element;
            try {
              element = selenium.browserbot.findElement('#{locator}');
            } catch(e) {
              element = null;
            }
            element != null && element.innerHTML == '#{text}'"

  wait_for_condition script, timeout_in_seconds
end