![]()
|
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
WebUnit Tips¥Ù¡¼¥¹¤È¤Ê¤ëURL¤ò·è¤á¤ë¥Æ¥¹¥È¤Ï¤É¤³¤Î¥Þ¥·¥ó¤Ç¤âưºî¤¹¤ë¤³¤È¤¬¤Ç¤¤ë¤è¤¦¤Ë¡¢Î㤨¤Ð¡¢¥Æ¥¹¥È¤·¤è¤¦¤È¤¹¤ë ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤ÎURL¤¬ http://kona.xxx.jp/~yuichi/tmp/test/ ¤Î²¼¤Ë¤¢¤ë¤Ê¤é¤Ð¡¢ ¤³¤ÎURL¤ò´Ä¶ÊÑ¿ôURLBASE¤ØÀßÄꤹ¤ë¡£ ¥Æ¥¹¥È¥±¡¼¥¹¤ÎÃæ¤Ç¤Ï @urlbase ¤È¤·¤Æ»²¾È¤¹¤ë¡£ ¥ì¥¹¥Ý¥ó¥¹¤ò¼õ¤±¼è¤ë!block example url = @urlbase + 'xxx/xxxx.html' response = Response::get( url ) !endblock HtmlElemtree ¤Ë´Þ¤á¤¿¤¯¤Ê¤¤¾ì¹ç¤Ï ¥Õ¥©¡¼¥à¤Î¥Æ¥¹¥È¥Æ¥¹¥ÈÂоÝ!block example <form action="xxxx" method="POST"> <input type="text" name="login" value="x"> <form> !endblock ¥Æ¥¹¥È½àÈ÷!block example response = Response::get( url ) form = response.form parameters = form.parameters !endblock ¥Æ¥¥¹¥È¥Õ¥£¡¼¥ë¥É¤Ê¤É¤Î¥Æ¥¹¥È¥Æ¥¥¹¥È¥Õ¥£¡¼¥ë¥É¤Ê¤É(hidden¤äpassword)¤Ï°Ê²¼¤Î¤è¤¦¤Ë¤·¤Æ¡¢ ¤½¤ì¤¾¤ì¤Î°À¤ÎÃͤò¼èÆÀ¤¹¤ë¤³¤È¤¬¤Ç¤¤ë¡£
!block example assert_input( 'login', 'text', 'x', parameters[0] ) # ---(1) spec = { 'name'=>'user', 'type'=>'text', 'value'='x' } # ---(2) assert_attrs( spec, parameters[0] ) # ---(2) assert_equals( 'login', parameters[0].name ) # ---(3) assert_equals( 'text', parameters[0].type ) # ---(3) assert_equals( 'x', parameters[0].value ) # ---(3) assert_equals( 'login', parameters[0].attrs['name'] ) # ---(4) assert_equals( 'text', parameters[0].attrs['type'] ) # ---(4) assert_equals( 'x', parameters[0].attrs['value'] ) # ---(4) !endblock ¥Æ¡¼¥Ö¥ë¤Î¥Æ¥¹¥È¥Æ¥¹¥ÈÂоÝ!block example <table> <tr bgcolor='white'> <td>EUC</td> <td><a href='sjis.html'>SJIS</a></td> </tr> <tr bgcolor='red'> <td><a href='jis.html'>JIS</a></td> <td>UTF-8</td> </tr> </table> !endblock ¥Æ¥¹¥È½àÈ÷!block example response = Response::get( url ) table = response.tables[0] !endblock ¥Æ¡¼¥Ö¥ë¥»¥ë¤Î¥Æ¥¹¥Èñ½ã¤Êʸ»úÎó¤ò¥Æ¥¹¥È¤¹¤ë¾ì¹ç¡¢°Ê²¼¤Î£²¤Ä¤ÎÊýË¡¤Çµ½Ò¤Ç¤¤ë¡£ assert_equals( "EUC", table.at(1,1).data ) # a. assert_include( "EUC", table.at(1,1) ) # b. ¥ê¥ó¥¯¤¬ÀßÄꤵ¤ì¤Æ¤¤¤ëʸ»úÎó¤ò¥Æ¥¹¥È¤·¤¿¤¤¾ì¹ç¤Ï ¥ê¥ó¥¯¼«ÂΤΠdata ¤ò¥Æ¥¹¥È¤¹¤ëɬÍפ¬¤¢¤ë¡£ ¤³¤Î¤¿¤á¡¢c. ¤Ïfail¤¹¤ë¤Î¤Ç¡¢d. ¤« e. ¤Î·Á¼°¤Çµ½Ò¤¹¤ëɬÍפ¬¤¢¤ë¡£ e. ¤Îµ½Ò¤ò¹Ô¤¦¤È¤½¤Î¾¤Î¥¿¥°¤Ç°Ï¤Þ¤ì¤Æ¤¤¤Æ¤âÀ®¸ù¤¹¤ë¡£ assert_equals( "SJIS", table.at(1,2).data ) # c. assert_equals( "SJIS", table.at(1,2).find("a").data ) # d. assert_include( "SJIS", table.at(1,2) ) # e. ¤Þ¤¿¡¢ÆÃÄê¤Î HtmlElem ¤¬ÆÃÄê¤Î¥»¥ë¤Ë´Þ¤Þ¤ì¤Æ¤¤¤ëɬÍפ¬¤¢¤ë¾ì¹ç¡¢ f. ¤Î¤è¤¦¤Ëµ½Ò¤¹¤ë¤³¤È¤¬¤Ç¤¤ë¡£ assert( table.at(2,1).has?( response.links[1] ) ) # f. ¥Æ¡¼¥Ö¥ë¹Ô¤Î¥Æ¥¹¥È¹Ô¤Î°À¤ò¥Æ¥¹¥È¤¹¤ë¡£ assert_equals( 'red', table.at(2).attrs['bgcolor'] ) ¹Ô¤Ë´Þ¤Þ¤ì¤ë¥Ç¡¼¥¿¤ò¥Æ¥¹¥È¤¹¤ë assert_include( "SJIS", table.at(1) ) ¥ê¥À¥¤¥ì¥¯¥ÈHTTP¥ê¥À¥¤¥ì¥¯¥È¥ì¥¹¥Ý¥ó¥¹¤¬HTTP¥ê¥À¥¤¥ì¥¯¥È¤À¤Èʬ¤«¤Ã¤Æ¤¤¤ë¾ì¹ç¤Ï°Ê²¼¤Î¤è¤¦¤Ëµ½Ò¤¹¤ë ¤³¤È¤¬¤Ç¤¤ë¡£HTTP¥ê¥À¥¤¥ì¥¯¥È(¥³¡¼¥É:302)¤Ç¤Ê¤¤¾ì¹ç¤Ï¡¢Îã³°¤¬È¯À¸¤¹¤ë¡£ response = Response::get( url ).redirect JavaScript¤Ë¤è¤ë¥ê¥À¥¤¥ì¥¯¥È(open)response = Response::get( url ).open.read response = Response::get( url ).opens[0].read ¥Ñ¥é¥á¡¼¥¿¤Î¿ô
name°À¤ËƱ¤¸¤â¤Î¤¬Ìµ¤±¤ì¤Ð¡¢¤³¤ÎÆó¤Ä¤ÏƱ¤¸ÃͤȤʤ롣 ¾Êά·Á
|