sunnybrad
asked on
Testing a link using HttpUnit...........
Hi All:
I have a small testing project. I have to test the web-site link and forms using HttpUnit. I am trying to create a WebLink class without any success. Please show me a way how to test form and links. My code fragment is as follows:
import com.meterware.httpunit.Get MethodWebR equest;
import com.meterware.httpunit.Web Conversati on;
import com.meterware.httpunit.Web Form;
import com.meterware.httpunit.Web Request;
import com.meterware.httpunit.Web Response;
import com.meterware.httpunit.Web Link;
public class MyDemo {
public void testHomePage() throws Exception
{
// Initiate WebConversation
WebConversation wc = new WebConversation();
WebRequest request = new GetMethodWebRequest ("http://www.test.net");
WebResponse response = wc.getResponse(request);
WebForm myact = response.getForms()[0];
WebLink myvoice = new WebLink();
// I am not able to create above constructor, show me a way how to test links and forms.
}
}
A code fragment will help greatly. I just need to navigate through links and test the web form and links. Look forward to quick response.
Regards
-Gyan
I have a small testing project. I have to test the web-site link and forms using HttpUnit. I am trying to create a WebLink class without any success. Please show me a way how to test form and links. My code fragment is as follows:
import com.meterware.httpunit.Get
import com.meterware.httpunit.Web
import com.meterware.httpunit.Web
import com.meterware.httpunit.Web
import com.meterware.httpunit.Web
import com.meterware.httpunit.Web
public class MyDemo {
public void testHomePage() throws Exception
{
// Initiate WebConversation
WebConversation wc = new WebConversation();
WebRequest request = new GetMethodWebRequest ("http://www.test.net");
WebResponse response = wc.getResponse(request);
WebForm myact = response.getForms()[0];
WebLink myvoice = new WebLink();
// I am not able to create above constructor, show me a way how to test links and forms.
}
}
A code fragment will help greatly. I just need to navigate through links and test the web form and links. Look forward to quick response.
Regards
-Gyan
public class MyDemo {
public void testHomePage() throws Exception
{
// Initiate WebConversation
WebConversation wc = new WebConversation();
WebRequest request = new GetMethodWebRequest ("http://www.test.net");
WebResponse response = wc.getResponse(request);
WebForm myact = response.getForms()[0];
// to get link with text "myvoice"
WebLink myvoice = response.getLinkWith("myvo ice");
}
}
public void testHomePage() throws Exception
{
// Initiate WebConversation
WebConversation wc = new WebConversation();
WebRequest request = new GetMethodWebRequest ("http://www.test.net");
WebResponse response = wc.getResponse(request);
WebForm myact = response.getForms()[0];
// to get link with text "myvoice"
WebLink myvoice = response.getLinkWith("myvo
}
}
ASKER
Hi All:
I have a few additional question, since I am new to HttpUnit:
I have to test a few webpages.
This mean I have to confirm the presence of few links and form elements.
I know how to navigate through these pages. How can I do that.
Is there a method to do all this.
AssertLink something of that nature.
Can someone give me readable and nice way to report failures and success.
Link found then it is a success.
Link not found then it is a failure. Code fragment would be greatly appreciated.
Regards
-Gyan
I have a few additional question, since I am new to HttpUnit:
I have to test a few webpages.
This mean I have to confirm the presence of few links and form elements.
I know how to navigate through these pages. How can I do that.
Is there a method to do all this.
AssertLink something of that nature.
Can someone give me readable and nice way to report failures and success.
Link found then it is a success.
Link not found then it is a failure. Code fragment would be greatly appreciated.
Regards
-Gyan
WebLink myvoice = response.getLinkWith("myvo ice");
assertNotNull("myvoice link not found", myvoice);
assertNotNull("myvoice link not found", myvoice);
public static Map testLinks(WebResponse response, String[] links) {
Map results = new HashMap();
final String FAIL = "FAIL";
final String SUCCESS = "SUCCESS";
for(int i = 0;i < links.length;i++) {
WebLink wl = response.getLinkWith(links [i]);
results.put(links[i], wl != null? SUCCESS : FAIL);
}
return results;
}
Map results = new HashMap();
final String FAIL = "FAIL";
final String SUCCESS = "SUCCESS";
for(int i = 0;i < links.length;i++) {
WebLink wl = response.getLinkWith(links
results.put(links[i], wl != null? SUCCESS : FAIL);
}
return results;
}
ASKER
Hi:
Thanks for the response. How do you make sure certain form elements are present.
Is there a quick and easy way like testing the forms.
Regards
-sunnybrad
Thanks for the response. How do you make sure certain form elements are present.
Is there a quick and easy way like testing the forms.
Regards
-sunnybrad
same way, look for them in the response and add an assert that they are present.
ASKER
Hi All:
I am not able to get the webpage because of some javascript in the page. The code that causes error is below:
WebLink myvoice = response.getLinkWith("myVo ice");
WebResponse myVoicepage = myvoice.click();
The error message is below. It is not full but partial error message from console. The javascript sets the focus in the form and that causes error. Please let me know how to get round it. This is all that remains from the successful execution of my demo. Thanks in advance. Look forward to your response.
Javascript that causes error:
Error: Script 'if (document.forms['login_for m'][0].val ue != '') {
document.forms['login_form '][1].focu s();
} else {
document.forms['login_form '][0].focu s();
}
// ' failed: ConversionError: The undefined value has no properties. (httpunit; line 676)
Console error message:
ConversionError: The undefined value has no properties. (httpunit; line 676)
at org.mozilla.javascript.Nat iveGlobal. constructE rror(Nativ eGlobal.ja va:597)
at org.mozilla.javascript.Nat iveGlobal. constructE rror(Nativ eGlobal.ja va:557)
at org.mozilla.javascript.Scr iptRuntime .getProp(S criptRunti me.java:71 2)
at org.mozilla.javascript.Int erpreter.i nterpret(I nterpreter .java:2035 )
at org.mozilla.javascript.Int erpretedSc ript.call( Interprete dScript.ja va:62)
at org.mozilla.javascript.Int erpretedSc ript.exec( Interprete dScript.ja va:55)
at org.mozilla.javascript.Con text.evalu ateReader( Context.ja va:820)
at org.mozilla.javascript.Con text.evalu ateString( Context.ja va:784)
at com.meterware.httpunit.jav ascript.Ja vaScript$J avaScriptE ngine.exec uteScript( JavaScript .java:132)
at com.meterware.httpunit.scr ipting.Scr iptableDel egate.runS cript(Scri ptableDele gate.java: 65)
at com.meterware.httpunit.par sing.Scrip tFilter.ge tTranslate dScript(Sc riptFilter .java:151)
at com.meterware.httpunit.par sing.Scrip tFilter.en dElement(S criptFilte r.java:131 )
at org.cyberneko.html.filters .DefaultFi lter.endEl ement(Unkn own Source)
at org.cyberneko.html.filters .Namespace Binder.end Element(Un known Source)
at org.cyberneko.html.HTMLTag Balancer.c allEndElem ent(Unknow n Source)
at org.cyberneko.html.HTMLTag Balancer.e ndElement( Unknown Source)
at org.cyberneko.html.HTMLSca nner$Speci alScanner. scan(Unkno wn Source)
at org.cyberneko.html.HTMLSca nner.scanD ocument(Un known Source)
at org.cyberneko.html.HTMLCon figuration .parse(Unk nown Source)
at org.cyberneko.html.HTMLCon figuration .parse(Unk nown Source)
at org.apache.xerces.parsers. XMLParser. parse(Unkn own Source)
at org.apache.xerces.parsers. DOMParser. parse(Unkn own Source)
at com.meterware.httpunit.par sing.NekoH TMLParser. parse(Neko HTMLParser .java:41)
at com.meterware.httpunit.HTM LPage.pars e(HTMLPage .java:255)
at com.meterware.httpunit.Web Response.g etReceived Page(WebRe sponse.jav a:1109)
at com.meterware.httpunit.Web Response.g etFrames(W ebResponse .java:1098 )
at com.meterware.httpunit.Web Response.g etFrameReq uests(WebR esponse.ja va:875)
at com.meterware.httpunit.Fra meHolder.u pdateFrame s(FrameHol der.java:1 79)
at com.meterware.httpunit.Web Window.upd ateFrameCo ntents(Web Window.jav a:252)
at com.meterware.httpunit.Web Client.upd ateFrameCo ntents(Web Client.jav a:485)
at com.meterware.httpunit.Web Window.upd ateWindow( WebWindow. java:146)
at com.meterware.httpunit.Web Window.get SubframeRe sponse(Web Window.jav a:130)
at com.meterware.httpunit.Web Window.get Response(W ebWindow.j ava:121)
at com.meterware.httpunit.Web Window.upd ateWindow( WebWindow. java:144)
at com.meterware.httpunit.Web Window.get SubframeRe sponse(Web Window.jav a:130)
at com.meterware.httpunit.Web Window.get Response(W ebWindow.j ava:121)
at com.meterware.httpunit.Web Window.upd ateWindow( WebWindow. java:144)
at com.meterware.httpunit.Web Window.get SubframeRe sponse(Web Window.jav a:130)
at com.meterware.httpunit.Web Window.get Response(W ebWindow.j ava:121)
at com.meterware.httpunit.Web Window.upd ateWindow( WebWindow. java:144)
at com.meterware.httpunit.Web Window.get SubframeRe sponse(Web Window.jav a:130)
at com.meterware.httpunit.Web Window.get Response(W ebWindow.j ava:121)
at com.meterware.httpunit.Web Window.upd ateWindow( WebWindow. java:144)E rror: Script 'if (document.forms['login_for m'][0].val ue != '') {
document.forms['login_form '][1].focu s();
} else {
document.forms['login_form '][0].focu s();
}
// ' failed: ConversionError: The undefined value has no properties. (httpunit; line 676)
at com.meterware.httpunit.Web Window.get SubframeRe sponse(Web Window.jav a:130)
at com.meterware.httpunit.Web Window.get Response(W ebWindow.j ava:121)
at com.meterware.httpunit.Web Window.sen dRequest(W ebWindow.j ava:110)
at com.meterware.httpunit.Web RequestSou rce.submit Request(We bRequestSo urce.java: 253)
at com.meterware.httpunit.Web RequestSou rce.submit Request(We bRequestSo urce.java: 232)
at com.meterware.httpunit.Web Link.click (WebLink.j ava:98)
Regards
sunnybrad
I am not able to get the webpage because of some javascript in the page. The code that causes error is below:
WebLink myvoice = response.getLinkWith("myVo
WebResponse myVoicepage = myvoice.click();
The error message is below. It is not full but partial error message from console. The javascript sets the focus in the form and that causes error. Please let me know how to get round it. This is all that remains from the successful execution of my demo. Thanks in advance. Look forward to your response.
Javascript that causes error:
Error: Script 'if (document.forms['login_for
document.forms['login_form
} else {
document.forms['login_form
}
// ' failed: ConversionError: The undefined value has no properties. (httpunit; line 676)
Console error message:
ConversionError: The undefined value has no properties. (httpunit; line 676)
at org.mozilla.javascript.Nat
at org.mozilla.javascript.Nat
at org.mozilla.javascript.Scr
at org.mozilla.javascript.Int
at org.mozilla.javascript.Int
at org.mozilla.javascript.Int
at org.mozilla.javascript.Con
at org.mozilla.javascript.Con
at com.meterware.httpunit.jav
at com.meterware.httpunit.scr
at com.meterware.httpunit.par
at com.meterware.httpunit.par
at org.cyberneko.html.filters
at org.cyberneko.html.filters
at org.cyberneko.html.HTMLTag
at org.cyberneko.html.HTMLTag
at org.cyberneko.html.HTMLSca
at org.cyberneko.html.HTMLSca
at org.cyberneko.html.HTMLCon
at org.cyberneko.html.HTMLCon
at org.apache.xerces.parsers.
at org.apache.xerces.parsers.
at com.meterware.httpunit.par
at com.meterware.httpunit.HTM
at com.meterware.httpunit.Web
at com.meterware.httpunit.Web
at com.meterware.httpunit.Web
at com.meterware.httpunit.Fra
at com.meterware.httpunit.Web
at com.meterware.httpunit.Web
at com.meterware.httpunit.Web
at com.meterware.httpunit.Web
at com.meterware.httpunit.Web
at com.meterware.httpunit.Web
at com.meterware.httpunit.Web
at com.meterware.httpunit.Web
at com.meterware.httpunit.Web
at com.meterware.httpunit.Web
at com.meterware.httpunit.Web
at com.meterware.httpunit.Web
at com.meterware.httpunit.Web
at com.meterware.httpunit.Web
at com.meterware.httpunit.Web
document.forms['login_form
} else {
document.forms['login_form
}
// ' failed: ConversionError: The undefined value has no properties. (httpunit; line 676)
at com.meterware.httpunit.Web
at com.meterware.httpunit.Web
at com.meterware.httpunit.Web
at com.meterware.httpunit.Web
at com.meterware.httpunit.Web
at com.meterware.httpunit.Web
Regards
sunnybrad
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi:
One additional question. I get a security alert...because of a bad certificate (through HTTPS).
Is there a way to go around it (e.g. by pressing yes button.)
Let me know if there is any way to get rid of it.
Thanks for all the responses so far, I really appreciate it.
Regards
-sunnybrad
One additional question. I get a security alert...because of a bad certificate (through HTTPS).
Is there a way to go around it (e.g. by pressing yes button.)
Let me know if there is any way to get rid of it.
Thanks for all the responses so far, I really appreciate it.
Regards
-sunnybrad
ASKER
Hi:
Just some clarification:
I want to keep interacting with the server after ignoring the security alert.
Please let me know of a way todo that.
Regards,
-sunnybrad
Just some clarification:
I want to keep interacting with the server after ignoring the security alert.
Please let me know of a way todo that.
Regards,
-sunnybrad
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi objects:
I might have misrepresented myself, the security alert comes from the server.
DialogResponder seems to get an user input from the program user.
Whereas I need to respond.....to server presenting me a cert and asking me if I want to continue
I want to say yes. and continue working with the form. This we can do WebConversation etc....normal
interaction with form.
I just want to say yes on cert window that https pops up.
Regards
-sunnybrad
I might have misrepresented myself, the security alert comes from the server.
DialogResponder seems to get an user input from the program user.
Whereas I need to respond.....to server presenting me a cert and asking me if I want to continue
I want to say yes. and continue working with the form. This we can do WebConversation etc....normal
interaction with form.
I just want to say yes on cert window that https pops up.
Regards
-sunnybrad
Thats what DialogAdapter does by default, ie. confirms all dialogs
ASKER
Hi:
One more question connecting to https server compared to http server
WebRequest request = new GetMethodWebRequest ("http://www.test.net");
This works
WebRequest request = new GetMethodWebRequest ("https://208.70.234.12");
Does not work, gives the following error:
Error: HTTPS hostname wrong: should be <208.70.234.12>
Should I be doing something different.
Look forward to your respond.
Regards
-sunnybrad
One more question connecting to https server compared to http server
WebRequest request = new GetMethodWebRequest ("http://www.test.net");
This works
WebRequest request = new GetMethodWebRequest ("https://208.70.234.12");
Does not work, gives the following error:
Error: HTTPS hostname wrong: should be <208.70.234.12>
Should I be doing something different.
Look forward to your respond.
Regards
-sunnybrad
http://httpunit.sourceforge.net/doc/api/com/meterware/httpunit/WebResponse.html#getLinks()