HttpUnit的基礎使用(一)
HttpUnit的基礎使用(一)
首頁地址
http://httpunit.sourceforge.net/doc/cookbook.html
1.WebConversation is the center of HttpUnit
It is responsible for maintaining session context via cookies returned by the server.
we can get web response like this:
WebConversation wc = new WebConversation();
WebResponse resp = wc.getResponse( "http://www.httpunit.org/doc/cookbook.html" ); // read this page
And we can examine and follow links like this:
WebLink link = resp.getLinkWith( "response" );// find the link
System.out.println(link.getURLString());
System.out.println(link.getText());
link.click();// follow it
WebResponse jdoc = wc.getCurrentPage();
System.out.println(jdoc.getTitle());
the link text in cookbook.html is like this:
<a href="api/com/meterware/httpunit/WebResponse.html">response</a>
The WebResponse.getLinkWithImageText() method can look up links by examining the ALT text, or the HttpUnitOptions.setImagesTreatedAsAltText method can cause ALT text to be treated as ordinary searchable text.
We can deal with tables too:
WebTable table = resp.getTables()[0];
table.getRowCount()
table.getColumnCount()
table.getTableCell( 0, 2 )
String[][] colors = resp.getTables()[1].asText();
colors[0][0]
2.Working with forms
WebForm form = resp.getForms()[0]; // select the first form in the page
form.getParameterValue( "Name" )
the Name html element is the page is like this:
<input name="Name" type="text" value="La Cerentolla">
form.setParameter( "Food", "Italian" ); // select one of the permitted values for food
form.removeParameter( "CreditCard" ); // clear the check box
form.submit(); // submit the form
3.Working with frames
WebConversation wc = new WebConversation();
WebResponse top = wc.getResponse( "http://www.meterware.com/Frames.html" ); // read a page with two frames
WebResponse summary = wc.getFrameContents( "summary" ); // read the summary frame
WebLink link = summary.getLinkWith( "Cake Recipe" ); // find the link (which targets "details" );
link.click(); // click on it
WebResponse response= wc.getFrameContents( "details" ); // retrieve the details frame
首頁地址
http://httpunit.sourceforge.net/doc/cookbook.html
1.WebConversation is the center of HttpUnit
It is responsible for maintaining session context via cookies returned by the server.
we can get web response like this:
WebConversation wc = new WebConversation();
WebResponse resp = wc.getResponse( "http://www.httpunit.org/doc/cookbook.html" ); // read this page
And we can examine and follow links like this:
WebLink link = resp.getLinkWith( "response" );// find the link
System.out.println(link.getURLString());
System.out.println(link.getText());
link.click();// follow it
WebResponse jdoc = wc.getCurrentPage();
System.out.println(jdoc.getTitle());
the link text in cookbook.html is like this:
<a href="api/com/meterware/httpunit/WebResponse.html">response</a>
The WebResponse.getLinkWithImageText() method can look up links by examining the ALT text, or the HttpUnitOptions.setImagesTreatedAsAltText method can cause ALT text to be treated as ordinary searchable text.
We can deal with tables too:
WebTable table = resp.getTables()[0];
table.getRowCount()
table.getColumnCount()
table.getTableCell( 0, 2 )
String[][] colors = resp.getTables()[1].asText();
colors[0][0]
2.Working with forms
WebForm form = resp.getForms()[0]; // select the first form in the page
form.getParameterValue( "Name" )
the Name html element is the page is like this:
<input name="Name" type="text" value="La Cerentolla">
form.setParameter( "Food", "Italian" ); // select one of the permitted values for food
form.removeParameter( "CreditCard" ); // clear the check box
form.submit(); // submit the form
3.Working with frames
WebConversation wc = new WebConversation();
WebResponse top = wc.getResponse( "http://www.meterware.com/Frames.html" ); // read a page with two frames
WebResponse summary = wc.getFrameContents( "summary" ); // read the summary frame
WebLink link = summary.getLinkWith( "Cake Recipe" ); // find the link (which targets "details" );
link.click(); // click on it
WebResponse response= wc.getFrameContents( "details" ); // retrieve the details frame
相關文章
- RxJava基礎使用(一)RxJava
- DataBinding基礎使用一
- web workers簡介(一)基礎使用Web
- Golang 基礎之函式使用 (一)Golang函式
- vue1 x 基礎使用(一)Vue
- Spring基礎使用(一)--------IOC、Bean的XML方式SpringBeanXML
- C++基礎(十二)一個巨集使用的坑C++
- Git Bash的基礎使用Git
- AIDL使用學習(一):基礎使用學習AI
- 『動善時』JMeter基礎 — 6、使用JMeter傳送一個最基礎的請求JMeter
- Rxjava2(一)、基礎概念及使用RxJava
- 一、基礎
- 【基礎篇索引】索引基礎(一)索引
- 測試基礎(四)Jmeter基礎使用JMeter
- mongoose基礎使用Go
- webpack 基礎使用Web
- Markdown基礎使用
- WCDB基礎使用
- vim基礎使用
- WebRTC基礎使用Web
- Git基礎使用Git
- mysql基礎使用MySql
- Swift之SQLite的基礎使用SwiftSQLite
- vuex 的概念和基礎使用Vue
- MYSQL基礎語法的使用MySql
- Oracle之procedure的基礎使用Oracle
- JavaScript 基礎卷(一):基礎語法JavaScript
- 逆向基礎(一)
- JS·基礎(一)JS
- Dart基礎(一)Dart
- django基礎(一)Django
- React基礎(一)React
- JavaScript基礎(一)JavaScript
- 基礎題一
- swift的基礎語法(一)Swift
- 廣播基礎使用
- Laravel Excel 基礎使用LaravelExcel
- EasyExcel基礎使用教程Excel