I am using the Ruby gem Rautomation to test a windows based application. The application is running behind a remote Citrix server and therefore I am not able to interact with the app in the usual way. I cannot access any elements on the app using a scraper like windows inspect.exe. What i would like to do is use the keyboard and/or mouse to select text on the app, and then copy it to a file for verification purposes.
Here is a code snippet of what i would like to do:
window = RAutomation::Window.new(:title => /Manager App/i, :adapter => 'ms_uia')
window.move_mouse(60,95)
window.click_mouse_and_hold # is there a 'hold' method??
window.move_mouse(80,95)
window.release_mouse # is there a 'release' method??
window.send_keys [:left_control, 'c']
OR
window.move_mouse(60,95)
window.click
window.send_keys :shift # hold this key down somehow??
window.move_mouse(80,95)
window.release_shift # is there a 'release' key method??
window.send_keys [:left_control, 'c']
What I would like to do is drag the mouse to select a section of text on this app, OR select the start of some text, hold shift, then select the end of the text i need. Basically replicating how a user would select and copy text in real life but through Rautomation. Is this possible?
Thanks
I have not tested it, but with win32 and autoit adapters you should be able to do it with Mouse#press and Mouse#release. Here's a spec for:
it "#press/#release" do
window = RAutomation::Window.new(:title => "MainFormWindow")
window.maximize
text_field = window.text_field(:index => 2)
text_field.set("start string")
text_field.value.should == "start string"
mouse = window.mouse
mouse.move :x => 146, :y => 125
mouse.press
mouse.move :x => 194
mouse.release
window.send_keys [:control, "c"]
text_field.set("new string")
text_field.value.should == "new string"
mouse.move :x => 146
mouse.press
mouse.move :x => 194
mouse.release
window.send_keys [:control, "v"]
text_field.value.should == "start string"
end
Check out documentation for RAutomation to help you even more.
Related
My question is concerning the "para" object. Where can I look up all the methods para has? I tried the shoesrb.com manual but all it says is that para is used to render text. I also tried #shoes at Freenode, but no one answered. Seems that no one is online.
I ask because I don't understand what the pounded (###) line does.
str, t = "", nil
Shoes.app :height => 500, :width => 450 do
background rgb(77, 77, 77)
stack :margin => 10 do
para span("TEXT EDITOR", :stroke => red, :fill => white), " * USE ALT-Q TO QUIT", :stroke => white
end
stack :margin => 10 do
t = para "", :font => "Monospace 12px", :stroke => white
t.cursor = -1 ####### I don't understand this line
end
keypress do |k|
case k
when String
str += k
when :backspace
str.slice!(-1)
when :tab
str += " "
when :left ### This is the part I'm interested in
#### Can you suggest a method to put in here. It moves the cursor to the left.
when :alt_q
quit
when :alt_c
self.clipboard = str
when :alt_v
str += self.clipboard
end
t.replace str
end
end
Does the para class have a cursor method? The official documentation has no answer.
I am trying to extend this into a simple text editor but I can't understand how to move the cursor.
I am a novice programer and new to Ruby as well.
Furthermore, where do the Shoes programmers hang out? I tried the mailing list, apparently it's out of service. Is there are specific forum or a different mailing list?
thanks for trying out Shoes.
Yes, Red Shoes a.k.a. Shoes 3 apparently has a cursor method that lets you set the position of the cursor. It's undocumented though, I had to look up in the sources. Your milage may vary using it.
The Shoes mailing list is definitely alive and active. Just send a message to shoes#librelist.com and you should automatically be signed up. That would be the best channel for help on Shoes, for the rest communication happens mostly through Github issues.
I'm trying to make a small program to mung some data into usable form. One thing I'd like it to do is to be able to select some files and perform actions on them, so I thought i'd use the listbox object in Tk to do that. I want to be able to open a file and see its filename displayed in the listbox. As far as I've read this is precisely what using listvariable in the listbox is for. Yet when I run my code the listbox is never updated (although items already in the listvariable variable are displayed fine).
So here's a close to MWE for this. What am I doing wrong, and what fundamental idea have I misunderstood?
require 'tk'
require 'tkextlib/tile'
$path_list = []
$populate_list = TkVariable.new( $path_list )
def get_file
file = Tk.getOpenFile
file = open(file) unless file.empty?
path = File.basename(file, ".out")
if $path_list.include?(path)
Tk.messageBox(
'type' => "ok",
'icon' => "warning",
'title' => " - Minimum Working Example - ",
'message' => "This file has already been added! Nothing was added to the list"
)
else
$path_list.push(path)
end
end
root = TkRoot.new {title "- Minimum Working Example -"}
frame = Tk::Tile::Frame.new(root) {padding "3 3 12 12"}.grid( :sticky => 'nsew') # 'north south east west'
TkGrid.columnconfigure root, 0, :weight => 1; TkGrid.rowconfigure root, 0, :weight => 1
$file_listbox = Tk::Listbox.new(frame) {
listvariable $populate_list}.grid( :column => 1, :row => 0, :rowspan => 6)
Tk::Tile::Button.new(frame) {
width 15; text 'Open file...'; command {get_file}}.grid( :column => 0, :row => 1)
Tk.mainloop
Do I maybe have to write it in some other order?
Just add one line of code:
$populate_list.value = $path_list
under this one:
$path_list.push(path)
It works for me, although looks weird.
TkVariable create a proxy for you ruby variable, thus bridge your ruby var references with Tk widgets. But i don't know why changes in proxy var don't affect the var it points to. I'm not sure whether it should do that automatically.
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.
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)
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:
It follows a popup box with.
See also http://rubyonwindows.blogspot.com/2007/04/ruby-excel-inputbox-hack.html
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)}
}
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?
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
I've got this as my code
openAll = File.open('N:\Josh\Blondie\db.txt')
allNumbers = Array.new
allNumbers=[]
openAll.each_line {|line|
allNumbers.push line
}
puts allNumbers
and I'd like to be able to display the output of this code in a new window with Ruby Shoes, I can't seem to get it to display anything though. The contents of the file are names and phone numbers.
Any ideas?
Here's an example of outputting text to a shoes window. Using a puts statement just outputs to the shell, not to the Shoes app.
Shoes.app :title => "GUI RAW file converter, for the CLI challenged",
:resizable => true do
background white
stack do
flow {
background gray, :height => 30
caption "Caption", :margin => 8, :stroke => white
stack {
para 'This is a fancy line I just printed to the window'
####### Here's an example line you could use to put out the array...
allNumbers.each do |number|
para "#{number}"
end
}
}
end
end
I guess you should use the method Kernel#alert instead of Kernel#puts.
http://shoesrb.com/manual/Built-in.html
I had a look here: http://wiki.openqa.org/display/WTR/JavaScript+Pop+Ups
Every solution is for IE on Windows. I am using Firefox on Mac. Is there a way to click on OK of a JavaScript alert box?
Proper handling of alerts and prompts is still being worked on in WebDriver, but a common workaround is to overwrite the window functions using execute_script(), i.e.
browser.execute_script("window.alert = function(msg) { window.lastAlert = msg; }")
browser.button(:id => "trigger-alert").click
browser.execute_script("return window.lastAlert") #=> "the message"
Since I'd like to avoid a bunch of monkey patches floating around (a common problem in the Watir community), I've added some helper methods as an optional require - after the next release you should be able to do:
require "watir-webdriver/extensions/alerts"
browser.alert do
browser.button(:id => "alert").click
end #=> "the alert message"
browser.confirm(true) do
browser.button(:id => "confirm").click
end #=> "the confirm message"
browser.prompt("returned value") do
browser.button(:id => "prompt").click
end #=> { :message => "foo", :default => "bar" }
Note that this is temporary and the API may be removed in the future when the issue is resolved in WebDriver.
UPDATE:
Proper alert handling is now implemented. The above example would now be done like this:
browser.button(:id => "alert").click
browser.alert.ok
browser.button(:id => "confirm").click
browser.alert.ok # or browser.alert.close
browser.button(:id => "prompt").click
alert = browser.alert
alert.text #=> "foo"
alert.ok