2012-07-12 39 views
0

在Ruby on Rails项目中,我发现这个方法的目标是根据环境检索Selenium驱动程序。 (开发,测试或生产)这两种设置Selenium驱动程序的方式有什么区别?

def driver 
    @driver ||= begin 
     if Rails.env.production? 
     driver = Selenium::WebDriver.for :remote, url: 'http://localhost:4444/wd/hub' 
     else 
     driver = Selenium::WebDriver.for :firefox 
     end 
     driver.manage.timeouts.implicit_wait = 1 
     driver 
    end 
    end 

当然,我读的官方文档,但还是没有出现非常明确:

http://code.google.com/p/selenium/wiki/RemoteWebDriver - http://code.google.com/p/selenium/wiki/FirefoxDriver

是什么(这两种方式之间的差异远程和Firefox)?

特别是,对于被删除的方式,为什么将指向的主机设置为localhost ......的确,如果选择localhost,为什么不选择firefox驱动程序呢?

回答

2

:远程意味着您要使用运行Selenium Server的远程服务器:url。在这种情况下,selenium服务器在本地主机上运行。由于没有标识浏览器,因此它将使用服务器设置的任何默认浏览器。

:firefox意味着它会尝试在脚本运行的同一个盒子上使用firefox。

你可以在rubybindings的介绍页面上看到这两个例子。 http://code.google.com/p/selenium/wiki/RubyBindings

对于更一般文档的东西,这可能是一个好地方... http://selenium.googlecode.com/svn/trunk/docs/api/rb/index.html

至于为什么有人会这是什么?也许在prod环境中,除了开发这个代码的人之外,别的人会根据它所在的平台(chrome,也就是ff等)控制selenium服务器(就像一些无法访问代码的prod人员)。我只是在这里猜测。

相关问题