Sha256: 35abb7e3efa11606d9a3c90668df4d0448312e2b79879145f9334404e27e2d2c

Contents?: true

Size: 1.59 KB

Versions: 2

Compression:

Stored size: 1.59 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

class Notepad < Autogui::Application

  # initialize with the binary name 'notepad' and the window title
  # '<filename> - Notepad' used along with the application pid to find the
  # main application window
  def initialize(options = {})
    defaults = {
                 :name => "notepad",
                 :title => " - Notepad",
                 :logger_level => Autogui::Logging::DEBUG
               }
    super defaults.merge(options)
  end

  # timeout in seconds to wait for desktop windows to appear
  def default_window_timeout
    1
  end

  # the notepad's results window
  def edit_window
    main_window.children.find {|w| w.window_class == 'Edit'}
  end

  # About dialog, hotkey (VK_MENU, VK_H, VK_A)
  def dialog_about(options = {})
    options[:timeout] = default_window_timeout unless options[:timeout]
    Autogui::EnumerateDesktopWindows.new(options).find do |w|
      w.title.match(/About Notepad/) && (w.pid == pid)
    end
  end

  def message_dialog_confirm(options={})
    options[:timeout] = default_window_timeout unless options[:timeout]
    Autogui::EnumerateDesktopWindows.new(options).find do |w|
      w.title.match(/Notepad/) && (w.pid == pid) && (w.window_class == "#32770")
    end
  end

  # menu action File, Exit
  def file_exit
    set_focus
    keystroke(VK_MENU, VK_F, VK_X)
    if message_dialog_confirm(:timeout => 0)
      keystroke(VK_N)
    end
  end

  # menu action File, Save
  def file_save
    set_focus
    keystroke(VK_MENU, VK_F, VK_S)
  end


end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
win32-autogui-0.5.3 spec/applications/notepad.rb
win32-autogui-0.5.2 spec/applications/notepad.rb