index-ja.rd

# WebUnit

## WebUnitとは

WebUnit はブラウザを使用せずにウェブサイト(html/cgi)を テストするための Ruby API です。 助田さんの書かれたRubyのテストフレームワーク - RubyUnitと組み合わせて使用し、 ウェブサイト(html/cgi)のテストを自動化することができます。

HttpUnitとJUnitを使ってテストをしていたのですが、 プログラムを ruby で書いているときに、 テストを java で書くのは嫌なので、作りました。

## 内部で使用しているソフトウェア

WebUnit では以下のソフトウェアを使用しています。 htmlrepair/htmlsplit と html-parser は WebUnit に同梱しました。

なお、RubyUnit と NQXMLはあらかじめインストールしておく必要があります。

- RubyUnit または testunit
- htmlrepair/htmlsplit
- html-parser
- NQXML または REXML

## ダウンロードとインストール

<URL:http://xpenguin.biz/download/webunit/> から webunit-20YYMMDD-*.tar.gz をダウンロードし、適当なディレクトリに展開して、 `ruby install.rb` してください。

## 使用例

cgi 以下を httpd からアクセスできる場所へ webunit と言う名前でリンクして、 test/test_*.rb を runtest.rb などを利用して実行します。

    % ln -s webunit/cgi $DOCUMENT_ROOT/tmp/webunit
    % cp webunit/cgi/auth/.htpasswd /tmp
    % URLBASE=http://localhost/tmp/ runtest.rb test_link.rb

    require 'webunit/webunit'

    # get start HTML page
    url = 'test-1.html'
    response = WebUnit::Response::get( url )

    # test HTML page contents
    assert_title( 'test-1', response )
    assert_equals( 1, response.forms.size )

    form = response.form

    # test form of HTML page contents
    assert_equals( 'ntext',     form.parameters[0].name )
    assert_equals( 'npassword', form.parameters[1].name )

    # execute CGI script, after setting parameters
    form.parameters[0].value = "this is test"
    form.parameters[1].value = '!@#$%'
    response = form.submit

    # test output from CGI script
    assert_equals( 'result', response.title )
    assert_equals( 1, response.links.size )
    assert_equals( 'http://....', response.links[0] )

    # read link
    response = response.links[0].read

## 配布条件

本プログラムはフリーソフトウェアです。 GPL(the GNU GeneralPublic License)、 または、Ruby本体と同じ条件で本プログラムを再配布できます。 GPLについてはCOPYINGファイルを参照して下さい。

## バグレポート

<URL:mailto:yt@xpenguin.biz>

## 変更履歴

### 20040429+ --> 20040429++

- add <area> to SingleTags in parser.html (Thanks to Philip Plumlee)

### 20040429 --> 20040429+

- fix bug about handling XHTML(like <hr/> tag, in SingleTags at parser.rb)

### 20040211 --> 20040429

- fit htmlsplit to XHTML(like <p/> tag, it's temporary and defective)

### 20030121 --> 20040211

- fix for ruby 1.8.1

### 20020410-alpha -> 20030121

- enable using "Test::Unit" for Testing Framework. (by Kouhei Sutou)
- appends XML Parser support "REXML". (by Kouhei Sutou)
- supports multipart formdata. ready file transfer test. (by Narushima Hironori)
- changes document type sdf to rd. (by Narushima Hironori)
- changes installer to setup.rb. (by Narushima Hironori)
- fix Textarea#query_data and Parser#feed. (Thanks to Torsten Rueger)

### 20020330-alpha -> 20020410-alpha

- XmlDocument -> DomWalker : rename
- fix for 1.7 parser.(Thanks to Kazuhiro NISHIYAMA)
- fix install.rb for "--program-suffix".(Thanks to Kazuhiro NISHIYAMA)

### 20011019-alpha -> 20020330-alpha

- XmlDocument#size : new.
- mail addres of author is changed.

### 20011019-alpha -> 20011022-alpha

- XmlDocument#change_node : bug fix.

### 20011002-alpha -> 20011019-alpha

- XmlDocument : new - class to test xml document.

### 20010919-alpha -> 20011002-alpha

- Parser#do_input : support input tag without form tag. (Thanks to IKAGAWA, Kauztomo)
- Response#init_http : append header(Content-Type) for POST method.
- Response#init_http : catch IOError of HTTP::finish (for ruby 1.6.5)

### 20010912-alpha -> 20010919-alpha

- Response#get,post,init_http : to use BasicAuth.
- sample/cgi : remove space charactor between '#!' and '/usr/bin/env'

### 20010714-alpha -> 20010912-alpha

- Responss : use Net::HTTP::new_implementation.
- HtmlElem : fix inspect output when @tag is nil.( as toplevel )
- sgml-parser.rb(line:257) : bug fix, fail when nested tags.
- html-parser/install.rb : fix.

### 20010618-alpha -> 20010714-alpha

- Parser : add link tag to SingleTags.
- Parser#start_a : execute complete_url, unless the href begins '#'.
- Link : append onClick attribute, and reader.
- Response#init_http : retry, when Errno::EPIPE
- Response::html : append <html> tag, when there is no <html> tag.

### 20010611-alpha -> 20010618-alpha

- add sample

### 20010604-alpha -> 20010611-alpha

- HtmlElem#name : new
- Response#init_html : new, to use WebUnit without http access.
- (code using Response#new) : change to Response#new.init_http
- Response#init_http,feed, : divide initialize.
- perse_url : correspond to relative url and 'file:' prefix.
- perse_url : add '-' to regexp, will match to hostname.
- assert_urls : add success case, use orthop_url for expected url.

### 20010521-alpha -> 20010604-alpha

- include contrib/{html-parser,htmlrepair} : Thanks these authors. - html-parser : Takahiro Maebashi - htmlrepair : MoonWolf
- installer supports to install contrib/{html-parser,htmlrepair}

### 20010507-alpha -> 20010521-alpha

- Response#initialize : use $URLBASE when url is relational
- Parser#do_img: new
- Response#add_image, Response#images, Response#image : new
- Image : new

### 20010330-alpha -> 20010507-alpha

- sample, contrib: only directory
- install.rb : new
- all files : reject TAB code ( expect COPYING and Makefile )
- bin : make some commands
- doc : separate document files from cgi directory
- tests : split files, and add testcase methods.
- Utils#complete_url : bug fix
- TestCase#setup : set $URLBASE as @urlbase, Response::reset, restore Cookies
- TestCase#teardown : Response::reset, keep Cookies
- Cookies#cookies/cookies= : new
- Response#reset: close http connection
- assert_urls : new
- WebUnit#assert_equal_url : -> assert_urls
- Select#value : new
- assert_select_option : new
- HtmlElem#initialize : add default value for 2nd argument.
- assert_title : new - show response.body with message.
- HtmlElem#extract : new - make string with nested HtmlElems.
- Response#pbody : use Response#format
- Response#format : new
- MemWriter : new - used by Response#format

### 20010314-alpha -> 20010330-alpha

- Response#pbody : new - print orthopped Response#body.
- Select#select : accept Array of String(value|data) and Integer(index)
- assert_include : add using HtmlElem#has?
- Link#target : new
- Response#freeze,Form#freeze : new
- Select#value= :
- Form#submit :

### 20010223-alpha -> 20010314-alpha

- Paser#start_a : replace "&amp;" -> "&" of href. bug of sgml-parser?
- Table#row_index,col_index : new
- Form#store_test_data : new
- assert_input,assert_attrs,assert_include : new
- InputRadio#value= : bug fix
- Textarea#initialize, Select#initialize, SelectOption#initialize : set type
- Parser#attrs_to_hash : bug fix
- Response#push : no longer support, puts WARNING
- Response#click : support for readlink and submit
- Utils#complete_url : <- Response#complete_url & Parser#complete_url
- JSciriptOpenObject : new
- Response#redirect : new
- Form#submit, Response#submit : support InputImage ( add args )
- InputImage : new
- Input#inspect : bug fix.
- Response#initialize : better performance with keeping connection.
- Table#at : to access TableRow with one argument. ( two args for Cell )
- Parser#complete_url : use orthop_url
- Utils#orthop_url : '//', '/\./', '[^/]*/\.\./' -> '/'
- TestCase#initialize : append '/' if last char of URLBASE isn't '/'
- TableRow : new ( Table is also changed )
- Response : attr_accessor -> attr_reader
- HtmlElem#inspect : change format, and stop recursive.
- HtmlElem#print : change format as inspect.
- Response#readlink : use HtmlElem#readlink
- HtmlElem#readlink : new
- Response#click : alias of Response#readlink
- Response#submit,push : same as Response#forms[0].submit
- Response#params : same as Response#forms[0].params
- Response#link,form,table,frame : same as Response#*[0]
- Response#search,find : new
- HtmlElem#search : new
- change file struct.

### 20010216-alpha -> 20010223-alpha

- Cookies#header : bug fix. ( handle when path == nil )
- Parser#endtag : raise BadHtmlTags exception
- Response#readlink : new ( raise ElemNotFound when failed )
- rename exception : NotFound -> HttpNotFound
- unify linefeed code to '\n'(0x0a) on each files.

### 20010215-alpha -> 20010216-alpha

- Frame#read : bug fix.
- Response#initialize : raise NotFound exception
- Param#query_data : rename method from data
- InputRadio#query_data : rename method from data
- InputCheckBox#query_data : rename method from data
- InputSubmit#query_data : rename method from data
- InputReset#query_data : rename method from data
- Select#query_data : rename method from data, and so on.
- SelectOption#query_data : rename method from data
- Form#submit : Param#query_data -> Param#query_data
- SelectOption#value : return data, when value is nil
- SelectOption#value= : remove
- SelectOption#data : remove
- SelectOption#data= : remove
- SelectOption#stat= : remove
- Param#value : method -> attr_accessor
- InputRadio#value= : new ( from Param#value )
- Textarea#value : new ( as SelectOption#value )
- Cookies#add : new