2

I'm writing tests using Selenium WebDriver and rautomation to handle system popup. I tried it on irb like following:

require 'selenium-webdriver'
require 'rautomation'

driver = Selenium::WebDriver.for :firefox
driver.get "http://rubygems.org/gems/rautomation-0.9.2.gem"

window = RAutomation::Window.new :title => "Opening rautomation-0.9.2.gem"

ok_button = window.button(:text => "&OK")
ok_button.exists?

cancel_button = window.button(:text => "&Cancel")
cancel_button.exists?

ok_button.exists? and cancel_button.exists? are returning false. Hence I can't click on the buttons.

I also tried:

window.buttons.length

to find number of buttons, but it's returning 0.

Could someone please help me why the buttons aren't detected using rautomation? Please correct me if I'm doing something wrong.

Here is a popup:

window popup

Alpha
  • 13,320
  • 27
  • 96
  • 163
  • What kind of system popup it is? – Jarmo Pertman Jul 22 '13 at 17:39
  • Could you please open link - http://rubygems.org/gems/rautomation-0.9.2.gem ? You'll see a popup that I want to handle using rautomation. – Alpha Jul 23 '13 at 03:12
  • 1
    I do not see any popups while opening that link either. What browser do you use? – Jarmo Pertman Jul 23 '13 at 10:31
  • 1
    You'll see popup if you open link in Firefox – Alpha Jul 23 '13 at 14:51
  • Jarmo, could you please help me to understand whether I'm doing something wrong or this is a bug? – Alpha Jul 24 '13 at 09:47
  • What kind of a popup it is? I can imagine that it is not using standard Windows GUI components? E.g. can you see all controls when using AutoIt's window info tool or something similar? If you can't then you can't use RAutomation really well. You can however probably send keys to it and operate with them. – Jarmo Pertman Jul 24 '13 at 16:03
  • Jarmo, looks you didn't open the url in Firefox, otherwise you would have seen popup. Anyway, I added popup screenshot in the question. Please refer to it. I had googled and heard RAutomation is better than Autoit hence I chose to use RAutomation. I also tried with authentication popup using site https://ispace.igate.com/ still neither buttons nor text fields detected. Looks RAutomation doesn't automate windows and their controls. I will have to go for Autoit or Sikuli to handle these kind of popups. – Alpha Jul 24 '13 at 17:11
  • You can't use AutoIt either because that window is not using native Windows controls. That's why i suggested you to use AutoIt Window Info tool to see if that detects all the individual controls. I bet it won't. I will create an answer which will show possible solutions. – Jarmo Pertman Jul 24 '13 at 18:46

4 Answers4

2

For my condition, I have to send two :tab key and then send :enter to save the file. like:

driver.get "http://rubygems.org/gems/rautomation-0.9.2.gem" 
window = RAutomation::Window.new :title => /Opening/i
if window.exist?
  window.activate
  window.send_keys :tab;
  sleep 2;
  window.send_keys :tab;
  sleep 2;
  window.send_keys :enter
end

I don't know why I can't just save the file with:

window.activate; sleep 1; window.send_keys :enter
shyan1
  • 1,003
  • 15
  • 17
1

The problem with this dialog is that it does not use native Windows controls. When you use Spy++ or AutoIt Window Info Tool then they do not show you any controls in that window either.

When using RAutomation you can check if it has native controls on it or not like this:

win = RAutomation::Window.new :title => /Opening rautomation/
p win.present?
p win.controls.length
p win.text
win.close

The output of this script will be:

true
0
""

In other words - window was present, it had zero controls of any kind and text was an empty string. Also, closing the window really closed it which you can verify visually - this means that we were interacting with the correct window and not accidentally with some other empty window (beware: this might sometimes happen too).

This all means that you cannot interact with the controls directly with AutoIt, RAutomation or many other automation tools. There might be some specific automation tools available for handling these kind of dialogs - i'm not sure.

There is however a workaround how to work with these kind of windows - send needed keystrokes to the window. In this case, sending a return/enter key would do the trick since that is the same as clicking on the "OK" button - you can try that manually.

Here is example code, which works the same as clicking on the "OK" button:

win = RAutomation::Window.new :title => /Opening rautomation/
win.activate
sleep 1
win.send_keys :enter

I'm not sure why, but for some reason you have to activate the window manually by calling Window#activate and wait a second before sending that enter key.

After doing that a new dialog will pop up, which uses native Windows controls - you can handle that as you would have expected RAutomation to work in the first place.

However, if you would use a :ms_uia adapter instead of the default :win32 then you don't need to activate and sleep.

Here is a fully working example with :ms_uia adapter:

win = RAutomation::Window.new :title => /Opening rautomation/, :adapter => :ms_uia
win.send_keys :enter

file_dialog = RAutomation::Window.new :title => /Enter name of file/
file_dialog.button(:value => "&Save").click

To click "Cancel" on the first dialog instead of "OK" you can just use Window#close as i was using to test the window above.

I would recommend you to use :ms_uia adapter instead of :win_32 since it is getting more stable every day and will be a new default one in the far future.

To set :ms_uia adapter for default one you can use environment variable RAUTOMATION_ADAPTER before loading RAutomation itself like this:

ENV["RAUTOMATION_ADAPTER"] ||= :ms_uia
require "rautomation"
Jarmo Pertman
  • 1,905
  • 1
  • 12
  • 19
  • Thank you so much for such a great details!!! I tried with different kind of dialogs but for every dialog 0 is returned for win.controls.length means those dialogs don't use native windows controls. Now, I'm in search of dialog which uses native windows controls. Hope I'll get it soon. – Alpha Jul 25 '13 at 17:50
  • You can use whatever Windows application's (for example, Paint) dialogs for example. If my answer was helpful anyhow then please set it as an accepted answer. Thanks! – Jarmo Pertman Jul 26 '13 at 19:05
  • Jarmo, once again thank you so much for helping me to understand RAutomation better!!! Accepted the answer :) – Alpha Jul 26 '13 at 19:24
0

I do not see any popup when I click that link. Chrome just downloads a file. :) This could help: http://watirwebdriver.com/browser-downloads/

Željko Filipin
  • 56,372
  • 28
  • 94
  • 125
  • If you open the link on Firefox, you will see a popup. I'm doing this for learning purpose. What I want to learn here is how to handle system popup using RAutomation. – Alpha Jul 23 '13 at 10:42
0

This code worked for me:

window = RAutomation::Window.new(:title => /Opening rautomation-0.9.2.gem/i)
              window.activate
              p window.exists? # => true
              sleep 2
              window.send_keys(:down)
              window.send_keys(:enter)
Sakib
  • 85
  • 2
  • 11