OLE problem with IE

55 views
Skip to first unread message

Gary

unread,
May 24, 2010, 12:31:07 PM5/24/10
to FunFX
I'm testing using IE and running into problems. I run the following
code from irb.

require 'funfx/browser/watir'
browser = Watir::IE.new
browser.goto('http://localhost:3000/bin/Registration.html')
flex_app = browser.flex_app('Registration', 'Registration')
flex_app.text_input(:id=>'Username').input('Gary')

Then I get the following error:

WIN32OLERuntimeError: execScript
OLE error code:80020101 in <Unknown>
Could not complete the operation due to error 80020101.
HRESULT error code:0x80020009
Exception occurred.
from c:/ruby/lib/ruby/site_ruby/1.8/funfx/browser/watir.rb:
30:in `method_missing'
from c:/ruby/lib/ruby/site_ruby/1.8/funfx/browser/watir.rb:
30:in `fire_event'
from c:/ruby/lib/ruby/site_ruby/1.8/funfx/flex/element.rb:
24:in `fire_event'
from c:/ruby/lib/ruby/site_ruby/1.8/funfx/flex/element.rb:
55:in `flex_invoke'
from c:/ruby/lib/ruby/site_ruby/1.8/funfx/flex/element.rb:
53:in `loop'
from c:/ruby/lib/ruby/site_ruby/1.8/funfx/flex/element.rb:
53:in `flex_invoke'
from c:/ruby/lib/ruby/site_ruby/1.8/funfx/flex/element.rb:
23:in `fire_event'
from c:/ruby/lib/ruby/site_ruby/1.8/funfx/flex/elements.rb:
759:in `input'
from (irb):7
irb(main):008:0>

It looks to me like the offending code is:

def fire_event(flex_locator, event_name, args) # :nodoc:
@flex_object.fireFunFXEvent(flex_locator, event_name, args)
end

Does anyone have a suggestion on which path to go down?

-Gary


--
You received this message because you are subscribed to the Google Groups "FunFX" group.
To post to this group, send email to fu...@googlegroups.com.
To unsubscribe from this group, send email to funfx+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/funfx?hl=en.

Chip Dale

unread,
May 25, 2010, 11:51:05 AM5/25/10
to fu...@googlegroups.com
Hi, Gary.
It's known issue under IE.
Watir.rb should be changed in order to work with IE in the same as with Firefox - using oleobject.
Following is our variant of watir.rb lib:

----------------------------------------------------------------------
require 'rubygems'
require 'watir'
require 'funfx'

module Watir
  # Watir extension for FunFX. Allows lookup of FlexApp objects via FunFX::Browser::FlexAppLookup#flex_app.
  class IE
    include FunFX::Browser::FlexAppLookup
    def platform_flex_app(dom_id, app_name)
      FlexApp.new(self, dom_id, app_name)
    end

    class FlexApp < Element #:nodoc:
      include FunFX::Flex::Elements
      include FunFX::Flex::FlexAppId

      def initialize(ole_object, dom_id, app_name)
        super(ole_object)
        @ole_obj = ole_object
        @dom_id = dom_id
        find_flex
        @app_name = app_name
      end


      def fire_event(flex_locator, event_name, args) # :nodoc:
        js = %|funfx_property=document.getElementById("#{@dom_id}").fireFunFXEvent(#{flex_locator}, #{event_name.inspect}, "#{args}");|
        exec_script(js)
      end

      def get_property_value(flex_locator, property) # :nodoc:
        js = %|funfx_property=document.getElementById("#{@dom_id}").getFunFXPropertyValue(#{flex_locator}, #{property.inspect});|
        exec_script(js)
      end

      def get_tabular_property_value(flex_locator, property) # :nodoc:
        js = %|funfx_property=document.getElementById("#{@dom_id}").getFunFXTabularPropertyValue(#{flex_locator}, #{property.inspect});\n|
        exec_script(js)
      end

      def invoke_tabular_method(flex_locator, method_name, *args) # :nodoc:
        js = %|funfx_property=document.getElementById("#{@dom_id}").invokeFunFXTabularMethod(#{flex_locator}, #{method_name.inspect},
        exec_script(js)
      end

      private
      def exec_script(js)
        begin
          @ole_obj.ie.Document.parentWindow.execScript(js)
          return @ole_obj.ie.Document.parentWindow.funfx_property
        rescue WIN32OLERuntimeError => e
          if e.message =~/unknown property or method 'funfx_property'/ || (e.message =~/funfx_property/ && e.message =~/Member not found/i)
              find_flex
          end
          #TODO. Maybe it is better to raise FunFXError instead of WIN32OLERuntimeError
          raise e
        end
      end

      def find_flex
        @flex_object = @ole_obj.ie.Document.getElementsByName(@dom_id).item(0)
        raise AppNotFoundError.new("Couldn't find Flex object with id #{@dom_id.inspect}") if @flex_object.nil?
        return true
      end

    end
  end
end
---------------------------------------------------


Note that we add "Errors" module to the "element.rb" lib inside "Flex" module. And we include this module to the Element class ("include FunFX::Flex::Errors") inside element.rb

Following is fragment from "element.rb"
--------------
module FunFX
  module Flex
    module Errors
      class FunFXError < StandardError; end
      class CouldNotFindElementError < FunFXError; end
      class AppNotFoundError < FunFXError; end
    end
    # Base class for all Flex proxy elements
    class Element
      include FunFX::Flex::Errors

#other code from element.rb....
....
-------------------

Files are located in
...\Ruby\lib\ruby\gems\1.8\gems\funfx-0.2.2\lib\funfx\browser\watir.rb
...\Ruby\lib\ruby\gems\1.8\gems\funfx-0.2.2\lib\funfx\flex\element.rb


I wish this will resolve your issue.

Good luck,
Pavel

Gary

unread,
Jun 1, 2010, 10:15:42 AM6/1/10
to FunFX

Thank you Chip!

I have not tried it yet but will soon. It seams to me like the
changes should be incorperated into the live code. Has this been
tried? If not I will work on a cleaner solution.

-Gary

Chip Dale

unread,
Jun 1, 2010, 10:33:42 AM6/1/10
to fu...@googlegroups.com
Hi, Gary.
Yes, we change the initial code of funfx.
And this solution works for us perfectly. But if you have some doubts you can just backup the initial files before changing them.
Reply all
Reply to author
Forward
0 new messages