Class: RFormSpec::Window

Inherits:
BaseControl show all
Defined in:
lib/rformspec/window.rb

Direct Known Subclasses

OpenFileDialog, SaveasFileDialog

Instance Attribute Summary collapse

Attributes inherited from BaseControl

#control_id, #parent_win

Instance Method Summary collapse

Methods inherited from BaseControl

#click, #is_enabled?, #is_visible?, #send_text, #set_text

Methods included from Driver

#close_window, #driver, #focus_window, #key_press, #mouse_click, #mouse_move, #open_file_dialog, #try_for, #wait_and_focus_window, #wait_for_window, #window_exists?

Methods included from TestWisePlugin

#connect_to_testwise, #debug, #dump_caller_stack, #notify_screenshot_location, #operation_delay

Constructor Details

#initialize(title, text = '', options = {:present => false, :wait_timeout => 0}) ⇒ Window

title : page title, depends autoit options, might use as substring match or exact match text: some text in window for further identifing the window options:

present => true | false,   already there
wait_timeout: wiat for maxium seconds if not active, throw error
 (active: means the window becomes the active window)

otherwise, inside window class, using focus_window methods



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/rformspec/window.rb', line 17

def initialize(title, text = '', options = {:present => false, :wait_timeout => 0})
  # for some windows, the title might change depends when it is invoked
  if title.class == Array
    title.each { |a_title|
      @title = a_title
      @text = text if text
      timeout = options[:wait_timeout]
      result = driver.WinWaitActive(@title, @text, timeout)
      return if result != 0
    }
    raise "timeout while waiting for window: #{self.to_s}"
  end
  
  @title = title
  # puts "[DEBUG ] setting title => #{@title}"
  @text = text if text
  # useful when ID changes
  
  timeout = options[:wait_timeout]
  if options[:present]
    result = driver.WinActivate(@title, @text)
    raise "window not found: #{self.to_s}" if result == 0
  elsif timeout && timeout.to_i > 1 then
    result = driver.WinWaitActive(@title, @text, timeout)
    raise "timeout while waiting for window: #{self.to_s}" if result == 0
  end
  
end

Instance Attribute Details

#class_listObject

Returns the value of attribute class_list.



7
8
9
# File 'lib/rformspec/window.rb', line 7

def class_list
  @class_list
end

#textObject

Returns the value of attribute text.



7
8
9
# File 'lib/rformspec/window.rb', line 7

def text
  @text
end

#titleObject

Returns the value of attribute title.



7
8
9
# File 'lib/rformspec/window.rb', line 7

def title
  @title
end

Instance Method Details

#button(button_id) ⇒ Object

a list



115
116
117
# File 'lib/rformspec/window.rb', line 115

def button(button_id)
  RFormSpec::Button.new(self, button_id)
end

#click_button(btn_id) ⇒ Object



70
71
72
# File 'lib/rformspec/window.rb', line 70

def click_button(btn_id)
  Button.new(self, btn_id).click
end

#closeObject



50
51
52
# File 'lib/rformspec/window.rb', line 50

def close
  driver.WinClose(@title, @text)
end

#exists?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/rformspec/window.rb', line 54

def exists?
  driver.WinExists(@title, @text)
end

#focusObject



46
47
48
# File 'lib/rformspec/window.rb', line 46

def focus
  driver.WinActivate(@title, @text)
end

#focus_control(ctrl_id) ⇒ Object



86
87
88
# File 'lib/rformspec/window.rb', line 86

def focus_control(ctrl_id)
  BaseControl.new(self, ctrl_id).focus
end

#get_class(name) ⇒ Object

return the class match by name



121
122
123
124
# File 'lib/rformspec/window.rb', line 121

def get_class(name)
  @class_list = get_class_list
  @class_list.select {|x| x.include?(name)}.collect{|y| y.strip}
end

#get_class_listObject



62
63
64
# File 'lib/rformspec/window.rb', line 62

def get_class_list
  driver.WinGetClassList(@title, @text)
end

#get_control_text(ctrl_id) ⇒ Object



94
95
96
# File 'lib/rformspec/window.rb', line 94

def get_control_text(ctrl_id)
  BaseControl.new(self, ctrl_id).get_text
end

#get_textObject



58
59
60
# File 'lib/rformspec/window.rb', line 58

def get_text
  driver.WinGetText(@title, @text)
end

#hide_dropdown(combo_id) ⇒ Object



80
81
82
83
84
# File 'lib/rformspec/window.rb', line 80

def hide_dropdown(combo_id)
  combo = ComboBox.new(self, combo_id)
  combo.hide_dropdown
  combo
end

#pixel_color(x, y) ⇒ Object Also known as: pixel_colour, get_pixel_colour, get_pixel_color



103
104
105
# File 'lib/rformspec/window.rb', line 103

def pixel_color(x,y)
  driver.PixelGetColor(x,y)
end

#send_control_text(ctrl_id, text) ⇒ Object



90
91
92
# File 'lib/rformspec/window.rb', line 90

def send_control_text(ctrl_id, text)
  BaseControl.new(self, ctrl_id).send_text(text)
end

#set_control_text(control_id, new_text) ⇒ Object



66
67
68
# File 'lib/rformspec/window.rb', line 66

def set_control_text(control_id, new_text)
  BaseControl.new(self, control_id).set_text(new_text)
end

#show_dropdown(combo_id) ⇒ Object



74
75
76
77
78
# File 'lib/rformspec/window.rb', line 74

def show_dropdown(combo_id)
  combo = ComboBox.new(self, combo_id)
  combo.show_dropdown
  combo
end

#statusbar_textObject

Not fully verified yet



99
100
101
# File 'lib/rformspec/window.rb', line 99

def statusbar_text
  driver.StatusbarGetText(@title)
end

#to_sObject



110
111
112
# File 'lib/rformspec/window.rb', line 110

def to_s
  "Window{title => '#{@title}', text=>'#{@text}'}"
end