summaryrefslogtreecommitdiff
path: root/_posts/2012-08-27-testing-website-with-capybara-webkit-and-testunit.md
blob: b8dfd53802753ce061ad2131f2beb8c7f22c22a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
---
layout: post
title: "Testing website with capybara-webkit and minitest"
description: ""
category: Development
tags: [Headless browser, Testing]
---
{% include JB/setup %}
---

# Setup for headless browser tests with minitest and capybara-webkit.

You need to install selenium-webdriver and capybara-webkit as gem. Capybara-webkit requires two system libraries **qt** and **xvfb**. To install execute:

  `apt-get install libqtwebkit-dev`<br>
  `apt-get install xvfb`

as sudo. This works for Debian Wheezy.

# Install the gems:

  `gem install selenium-webdriver`<br>
  `gem install capybara-webkit`

To run the headless browser you have to execute:

  `DISPLAY=localhost:1.0 xvfb-run ruby TEST.rb`<br>

or you integrate it to your test.

For the following example `export 'DISPLAY=localhost:1.0'` is already in ~/.bashrc.

# Example test:

`

    require 'rubygems'
    require 'minitest/autorun'
    require 'capybara/dsl'
    require 'capybara-webkit'
 
    Capybara.default_driver = :selenium
    Capybara.default_wait_time = 20
    Capybara.javascript_driver = :webkit
    Capybara.run_server = false
    Capybara.app_host = 'https://services.in-silico.ch'

    class LazarWebTest < MiniTest::Test
      include Capybara::DSL

      def test_00_start
        `Xvfb :1 -screen 0 1024x768x16 2>/dev/null &`
        sleep 2
      end
      
      def test_01_visit
        visit('/')
        puts page.source
      end

      def test_99_kill
        `pidof Xvfb|xargs kill`
      end

    end
`