18 January 2026:


This forum is now archived and is in read-only mode. Please continue discussions on our improved new Sahi Pro Community forum.



Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.

Ruby gem on Mac

beemanbeeman Members
edited November -1 in Sahi - Open Source
Hi:

OS Name: OS X Version 10.6.8
Browser Name and Version: FireFox 5.0
Sahi Build: Sahi V3.5

I am following the instructions on sahi ruby link on a mac.
After installing the sahi gem, I ran the test sample and received an error.

I changed the example based on the browser_types.xml settings:
  def init_browser()
    # Look at sahi/userdata/config/browser_types.xml to configure browsers.
    browser_path = "open -n -a Firefox.app"
    browser_options = "--args -profile '/Users/bbbelyk/Library/Application Support/Firefox/Profiles/hdfedmuj.Sahi Proxy' -no-remote"
    return Sahi::Browser.new(browser_path, browser_options)
  end

Now when I run, Firefox opens, has the correct proxy setting but displays SAHI_ERROR
and the ff address has "sahi example"

I searched for the "sahi example" and found it sahi.rb in the open method. I have to ask for help. How do I get this running?

Thanks

Bryan

Comments

  • Hi beeman,

    You can pass one of these as parameters to create a new instance of the Browser class.
    1. Browser type (as available in <name> in browser_types.xml)
    2. browser path, browser options, browser executable (<path>, <options>, <processName> in browser_types.xml)

    Use:
    def init_browser()
        # Look at sahi/userdata/config/browser_types.xml to configure browsers.
        @browser_name = "firefox"
        return Sahi::Browser.new(@browser_name)
      end
    

    This uses the browser type.

    Regards
    Sumitra
  • Hi Sumitra:

    Thanks for the reply. When I use the (at)browser_name as the only argument for new and run the test, there is an wrong number of arguments error:
    1) Error:
    test_google(SahiDriverTest):
    ArgumentError: wrong number of arguments (1 for 2)
        test/unit/sahi_test.rb:23:in `new'
        test/unit/sahi_test.rb:23:in `init_browser'
        test/unit/sahi_test.rb:7:in `setup'
    
    Finished in 0.050934 seconds.
    

    I can't seem to use one argument.

    Using (at)browser_path and (at)browser_options got past this error but then displayed the SAHI_ERROR. It looks like the error happens in the Browser open method.

    Bryan
  • I added some puts statements to the open method . is_ready? never returns true for the 500 tries. (I put ... for urls in the code)
        #opens the browser
        def open()
          puts "using the gem copy"
          check_proxy()
          
          (at)sahisid = Guid.new.to_s
          cmd = "#{(at)browser_path} #{(at)browser_options} ... 
          
          if Platform::OS == :win32
            require "win32/process"
            (at)pid = Process.create(:app_name  => cmd,
                                    :process_inherit => true,
                                    :thread_inherit  => true,
                                    :inherit         => true).process_id
          else
            puts "mac fork"
            (at)pid = fork { exec(cmd) }
          end
          
          puts "(at)pid = #{(at)pid}"
          puts "(at)proxy_host = #{(at)proxy_host}"
          puts "(at)proxy_port = #{(at)proxy_port}"
          
          i = 0
          while (i < 500)
            puts "i = #{i}"
            i+=1
            break if is_ready?
            sleep(0.1)
          end
        end 
        
        def is_ready?
          return  "true".eql?(exec_command("isReady"))
        end
        
        def exec_command(cmd, qs={})
          res = response( ... )
          puts "res = #{res}"
          return res
        end
        
        def response(url, qs={})
          return Net::HTTP.post_form(URI.parse(url), qs).body
        end
        
        
    $ rake test:units
    Loaded suite /Users/bbbelyk/.rvm/gems/ruby-1.9.2-p136(at)rails307/gems/rake-0.9.2/lib/rake/rake_test_loader
    Started
    using the gem copy
    mac fork
    (at)pid = 18561
    (at)proxy_host = localhost
    (at)proxy_port = 9999
    i = 0
    res = false
    i = 1
    res = false
    i = 2
    res = false
    i = 3
    res = false
    i = 4
    
    ... up to 500
    


    Thanks
    Bryan
  • Hi beeman,

    What version of Sahi Ruby driver are you using?

    Alos,can you try with latest Sahi Ruby driver and check if it solves your issue.

    Regards
    Sumitra
  • Hi Sumitra:

    I am using sahi 1.0.1. Is this the latest version? I did a 'gem install sahi' and this was the version installed.

    Thanks
    Bryan
Sign In or Register to comment.