2

I have used VBScript in the past for QTP and I could use the input box function to display a pop up window.

I am wondering if there is a way to do this with Ruby? I need a popup that will allow the user to input some information before the WATIR script executes.

I looked around StackOverflow but didn't see anything.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Joe
  • 743
  • 5
  • 10
  • 26

5 Answers5

3

Here an example of how to get the messagebox from vbscript in Ruby, i'll try to get the inputbox in the same way

require "Win32API"  

message = "This is a sample Windows message box generated using Win32API"  
title = "Win32API from Ruby"  

api = Win32API.new('user32','MessageBox',['L', 'P', 'P', 'L'],'I')  
api.call(0,message,title,0)  
peter
  • 41,770
  • 5
  • 64
  • 108
2

Maybe this example code helps you (win32 only):

require 'win32ole'

def inputbox( message, title="Message from #{__FILE__}" )
  vb_msg = %Q| "#{message.gsub("\n",'"& vbcrlf &"')}"|
  vb_msg.gsub!( "\t", '"& vbtab &"' )
  vb_msg.gsub!( '&""&','&' )
  vb_title = %Q|"#{title}"|
  # go!
  sc = WIN32OLE.new( "ScriptControl" )
  sc.language = "VBScript"
  sc.eval(%Q|Inputbox(#{vb_msg}, #{vb_title})|)
  #~ sc.eval(%Q|Inputbox(#{vb_msg}, #{vb_title}, aa,hide)|)
end
def popup(message)
  wsh = WIN32OLE.new('WScript.Shell')
  wsh.popup(message, 0, __FILE__)
end


str = "a |  does not break it...\n\nOne\n\tTwo tabbed\nThree..."
res = inputbox( str, "demonstration | title")
popup %Q|When asked\n\n"#{str}"\n\nyou answered:\n#{res}| 

This results in:

Inputbox

It follows a popup box with.

See also http://rubyonwindows.blogspot.com/2007/04/ruby-excel-inputbox-hack.html

knut
  • 27,320
  • 6
  • 84
  • 112
1

Since i can't find an inputbox api for windows here is what i do most of the time if i need some simple dialog. Unlike red shoes it is just a gem so easy to install.

require 'green_shoes'
Shoes.app{
  e = edit_line
  button("Click me!"){alert("You entered." + e.text)}
}
peter
  • 41,770
  • 5
  • 64
  • 108
  • @ Peter I tried installing GreenShoes but got this error message: Building native extensions. This could take a while... ERROR: Error installing green_shoes: ERROR: Failed to build gem native extension. /Users/joe.fleck/.rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb Is it because I am running with ruby-1.8.7? Thank you. – Joe Sep 28 '12 at 19:11
  • could be, i use ruby-1.9.3-p194 on windows and had no trouble at all, i even use it on windows pc's with no Ruby installed, just running ruby from a network share – peter Sep 28 '12 at 21:01
0

Ruby is a programing/scripting language, so on it's own it doesn't do any kind of GUI or Graphics related stuff. That being said there are quite a few projects and frameworks that use Ruby to accomplish the type of thing you are looking for. The big ones are Ruby on Rails that uses Ruby to create web applications, and Shoes which is for creating computer applications.

There is also this question What's the best/easiest GUI Library for Ruby?

Community
  • 1
  • 1
user160917
  • 9,211
  • 4
  • 53
  • 63
0

I would suggest shoes, it's a cross-platform toolkit for writing graphical apps.

I used it and it's pretty cool, you can do something like:

Shoes.app :width => 300, :height => 200 do
  stack do
    edit_line :width => 400
  end
end
Kaeros
  • 17
  • 1