3

我在 Windows/JRuby 上使用 watir-webdriver。我的开发一直使用 Firefox。

Watir::Browser.new :firefox

对于部署,我需要一个无头浏览器,需要 JavaScript 支持。对于无头浏览器,我有哪些选择?

4

2 回答 2

4

I am not quite sure of your requirements for deployment with a headless browser, but my team is using phantomjs along with the jasminerice gem to automate our JavaScript testing on a headless browser with WebKit.

We are using JRuby 1.6.7 and Rails 3.2.3. In our project we are using CoffeeScript, and we wanted to leverage the Rails asset pipeline to do the compiling of CoffeeScript to JavaScript, which is what jasminerice does. If my understanding is correct, this will work for tests and code written in plain ol' JavaScript as well.

The set-up is a bit involved, and you might find wildly varying and probably out-dated accounts of other people getting this to work, but here is a quick guide (gist on Github) that is working for me right now:

  1. Add jasminerice to your Gemfile (gist is here)

  2. Get the latest static build for phantomjs on Windows at http://code.google.com/p/phantomjs/downloads/list

  3. Drop that phantomjs.exe executable somewhere on your PATH. We have this in our Rails project's bin folder, and we have updated our PATH to include that folder.

  4. Create a spec/javascripts folder in your project directory, and create the following spec.js file that will pull into scope any required libraries or folders (gist here)

  5. Create a spec/javascripts/support folder in your project directory, and create the following phantomjs-runner file that will be used to invoke phantomjs to execute your JavaScript test files under spec/javascripts. (gist is here)

  6. Kick up your development Rails server and see jasminerice run your tests by going to http://localhost:5555/jasmine

  7. Alternately, you can create a Rake task that will execute everything for you and return the results to the command line (gist is here).

And those are the hoops we had to jump through in order to get jasminerice and phantomjs to compile and run our CoffeeScript tests headless on Win/JRuby. Hope that helps!

于 2012-04-24T01:17:48.887 回答
2

如果您想在无头 linux 服务器上运行您的东西,请参阅watir-webdriver 博客上的此页面

使用 Watir-Webdriver,您可以获得与 Webdriver 相同的无头选项(因为我们使用 webdriver 来驱动浏览器)。这已经写在几个地方,例如Alister 的 WatirMelon 博客上的这些文章。否则,只需进行谷歌搜索watir-webdriver headless,您就会看到许多有用的结果。但是我会坚持使用去年左右的东西,早期的东西现在可能有点过时了。

于 2012-04-18T18:01:57.137 回答