代码之家  ›  专栏  ›  技术社区  ›  Karl

浏览字段

  •  1
  • Karl  · 技术社区  · 17 年前

    2 回复  |  直到 17 年前
        1
  •  2
  •   Sarah Mei    17 年前

    用Ruby编写selenium脚本时,可以控制浏览器的所有窗口。但是文件选择器对话框和文件下载对话框实际上是系统窗口,因此您不能通过selenium来控制它们。

    但是,对于在Windows上运行的测试,您可以通过win32olegem来控制它们。但当然,你不能在mac或Linux上运行这些测试。

     require 'selenium'
     require 'test/unit'
     require 'win32ole'
    
     class DownloadFileTest < Test::Unit::TestCase
       def setup()
         @wsh = WIN32OLE.new('Wscript.Shell')
       end
       def teardown
         WIN32OLE.ole_free(@wsh) # yes, this is required *rolls eyes*
       end
       def test_download_file
         # ...stuff that causes a download window to pop up...
         @wsh.AppActivate("Opening")
         sleep(2)
         @wsh.SendKeys("{RIGHT}{ENTER}") # Hits ok button - file downloads
         sleep(3)
         # Use regular Ruby File methods to assert stuff on the file content
       end
    
        2
  •  0
  •   Patrick Lightbody    17 年前

    只要你能在富硒模式下运行就行了。如果您使用的是最新的1.0 beta 2,则默认情况下会使用这些选项。

    推荐文章