Use Browser as Gui in Ruby

use browser as GUI in Ruby

You could use the Watir gem. The gem was originally intended to drive the IE browser, but would fit your need.

To see:

1) Install the Watir gem

2) Create a test.htm file with the following:

Give me a name<br>
<form name="myForm" title="myForm">
<input type="text" id="name" >
<input id="submit" type="button" value="OK" onclick='document.myForm.submit.value="Done"'>
</form>

3) Run the following watir script, which will open the browser to your form. After you input the name and click [OK], the name is outputted. Note that you may need to change the location of the file in the script depending on where you saved your test.htm:

require 'watir'

b = Watir::IE.new
begin
b.goto('file:///C:/Documents%20and%20Settings/Setup/Desktop/test.htm')
begin
sleep(5)
end until b.button(:id, 'submit').value != "OK"
name = b.text_field.value
ensure
b.close
end
puts name

I think this shows the general feasibility of doing what you want. Validation and dynamic creation of the forms would also be possible.

Is it possible to open a browser window in Ruby Shoes?

Sure, you didn't mension the color of shoes so i'll use my favorite, green shoes

require 'green_shoes'

Shoes.app do
gem 'watir'
chrome_proc = Proc.new {
require 'watir'
browser = Watir::Browser.new :chrome
browser.goto("http://www.google.com")
}
para link("Go to google", &chrome_proc)
end

Embedding a browser window.. I wish it could but i'd be suprised..
But you could use watir (html) as your gui all the way.

Here another way based on your comment, this is on windows but i'm sure you will know how to tranpose this to a Mac.

require 'green_shoes'

Shoes.app do
proc = Proc.new {
system('"C:\Users\Gebruiker\AppData\Local\Google\Chrome\Application\chrome.exe" http://www.google.be')
}
para link("Go to google", &proc)
end

How to encapsulate Watir browser instance in a GUI using Ruby?

This is a bit of a tall order. Watir itself is just running from the command line, so you'd need to see if there is a way to do what you want with a command line window in the OS you are using. But then watir invokes an instance of the browser (which with Watir-webdriver can be a large number of different browsers), and each of those is their own beast, reacting with the OS and UI in their own way, and I've no idea who you might 'wrap' IE or Chrome or Firefox in the way you are describing..

It MAY be easier from that perspective to see if there would be a way to wrap the interface of a virtual machine perhaps? (maybe some way to do this with virtualbox or vmware?)

This seems like a pretty quirky request if you ask me, I'm having a hard time seeing the business value in what you are being asked to do.

Is Ruby any good for GUI development?

The short answer: no (because you said cross-platform).

The long answer: cross-platform GUIs are an age-old problem. Qt, GTK, wxWindows, Java AWT, Java Swing, XUL -- they all suffer from the same problem: the resulting GUI doesn't look native on every platform. Worse still, every platform has a slightly different look and feel, so even if you were somehow able to get a toolkit that looked native on every platform, you'd have to somehow code your app to feel native on each platform.

It comes down to a decision: do you want to minimise development effort and have a GUI that doesn't look and feel quite right on each platform, or do you want to maximise the user experience? If you choose the second option, you'll need to develop a common backend and a custom UI for each platform.

ruby is not a bad choice for your common backend.

Saving a browser url with Ruby and watir-webdriver

To write a string to a file you can just do that:

 File.open('path/to/yourfile', 'w') { |file| file.write(@browser.url) }

You can use it in the other test like this:

File.open('path/to/yourfile', "rb") { |file| @browser.goto(file.read) }

What's the best/easiest GUI Library for Ruby?

Ruby Shoes (by why) is intended to be a really simple GUI framework. I don't know how fully featured it is, though.

Some good code samples can be found in the tutorials.

Also, I think shoes powers hackety hack, a compelling programming learning environment for youngsters.



Related Topics



Leave a reply



Submit