Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Looking for a "headless browser" equivalent for PHP for Cucumber testing

I'm trying to set up some functional/acceptance/integration testing using Cucumber for my PHP project. I'm trying to understand the best approach to implementing these types of tests.

I understand that Selenium can test javascript, but Selenium is slow and I don't always need to test javascript. I'm looking for a "headless browser" equivalent for PHP.

Would either of these be classified as "headless browsers?"

  • SimpleTest web testing
  • Zend_Test_PHPUnit_ControllerTestCase

What have you done to implement integration testing of your Zend Framework project?

like image 732
Andrew Avatar asked Jan 21 '23 09:01

Andrew


2 Answers

If you set up Cucumber to use Webrat, you can set up Webrat to use Mechanize by default. Mechanize is essentially a headless browser. This is what my env.rb file looks like:

# RSpec
require 'rspec/expectations'

# Webrat
require 'webrat'

require 'test/unit/assertions'
World(Test::Unit::Assertions)

Webrat.configure do |config|
  config.mode = :mechanize
end

World do
  session = Webrat::Session.new
  session.extend(Webrat::Methods)
  session.extend(Webrat::Matchers)
  session
end

Also, according to this article, you can set up Cucumber to use Capybara and configure it to use Celerity (a headless browser with javascript support). It also includes instructions on how to configure Capybara to use Selenium RC (which I thought was not possible). I have not attempted this approach yet, so I don't know how well it works.

like image 149
Andrew Avatar answered Jan 29 '23 17:01

Andrew


Why not use behat ( http://behat.org/ ) ?

It should have all the requirements you listed above, and it's written in php.

It has a SahiDrvier to handle "in-browser" testing, and a Simple php browser too.

like image 26
Florian Klein Avatar answered Jan 29 '23 17:01

Florian Klein