HarRequest.Postdata() returning NULL - JAVA + SELENIUM+BROWSER PROXY

461 views
Skip to first unread message

robin...@gmail.com

unread,
Apr 2, 2012, 4:37:26 PM4/2/12
to BrowserMob Proxy
I'm currently working on Selenium to automate a web testing framework
For HTTP traffic , i am using browsermob proxy I am getting the
POST,GET commands correctly through har classes

But on a post command with correct post data , i'm not able to track
the post data, It returns NULL

I'm using getPostData() for this Can you please help me on this Will
getPostData() returns the actual post data

Code Snippet :
System.out.println("getting the HAR data");
har = server.getHar();
if(har==null){
System.out.println("Har is NULL");
}
HarLog harLog = har.getLog();
List<HarEntry> logEntries = harLog.getEntries();
System.out.println("getting the HAR data");
String httpgetMethod =null;
String
posttext=null,postFileName=null,postContentType=null,postName=null,postValue=null;
harRequest = new HarRequest();

for (HarEntry harEntry : logEntries){
//Retrieve the Request values
org.browsermob.core.har.HarResponse response =
harEntry.getResponse();

org.browsermob.core.har.HarRequest harRequest =
harEntry.getRequest();
if (response == null){
System.out.println("Null response -
"+harRequest.getUrl());
continue;
}


int status = response.getStatus();
httpgetMethod = harRequest.getMethod();
System.out.println(harRequest.getUrl()+" - "+status);
System.out.println("Method = "+httpgetMethod);

if (httpgetMethod.equals("POST"))
{
postdata1 = harRequest.getPostData(); //HERE I AM GETTING
NULL INSTEAD:-(
if (postdata1!=null){
System.out.println("Hurray!!!!!!!!!!!!!!!!postdata!
=null");
}
else{
System.out.println("postdata is null");
}
}

if (httpgetMethod.equals(postcommand) && (postdata1!=null)){

try{
posttext =postdata1.getText();
}

catch(Exception e){
e.printStackTrace();
}

if (posttext == null){
System.out.println("Post Data NULL");
//continue;
}
else{
System.out.println("postdata text = "+posttext);
}


if (((HarPostDataParam)
postdata1.getParams()).getFileName() != null)
System.out.println("postFileName = "+((HarPostDataParam)
postdata1.getParams()).getFileName());
if (((HarPostDataParam)
postdata1.getParams()).getContentType() != null)
System.out.println("getContentType = "+
((HarPostDataParam) postdata1.getParams()).getContentType());
if (((HarPostDataParam) postdata1.getParams()).getName() !
= null)
System.out.println("getName = "+((HarPostDataParam)
postdata1.getParams()).getName());
if (((HarPostDataParam) postdata1.getParams()).getValue() !
= null)
System.out.println("getValue = "+((HarPostDataParam)
postdata1.getParams()).getValue());
List<HarPostDataParam> postdataparams =
postdata1.getParams();
for(HarPostDataParam posdatap : postdataparams)
{
postFileName=posdatap.getFileName();
postContentType = posdatap.getContentType();
postName = posdatap.getName();
postValue=posdatap.getValue();
if ((postFileName) != null){
System.out.println("postFileName =
"+postFileName);

}
else{
System.out.println("postFileNameis NULL");
}
if ((postContentType) != null){
System.out.println("postContentType =
"+postContentType);
}
else{
System.out.println("postContentType is NULL");
}
if ((postName) != null){
System.out.println("postName = "+postName);

}
else{
System.out.println("postName is NULL");
}
if ((postValue) != null){
System.out.println("postValue = "+postValue);

}
else{
System.out.println("postValue is NULL");
}
}


} }

robin...@gmail.com

unread,
Apr 3, 2012, 4:20:33 AM4/3/12
to BrowserMob Proxy
Can anyone reply on this please
harRequest.getMethod(); gives POST command , but
harRequest.getPostData() is always giving NULL instead

On Apr 2, 9:37 pm, "robinpau...@gmail.com" <robinpau...@gmail.com>
wrote:

robin...@gmail.com

unread,
Apr 3, 2012, 12:07:24 PM4/3/12
to BrowserMob Proxy
During the POST command , postdataparams is having size zero , meaning
it doesnt contain any valid data postdataparams.size()=0
Any insight on this plz?

On Apr 3, 9:20 am, "robinpau...@gmail.com" <robinpau...@gmail.com>
wrote:

robin paul

unread,
Apr 4, 2012, 4:10:07 AM4/4/12
to BrowserMob Proxy
Hi Guys
Have anyone integrated har library with webdriver in java and successfully got the POSTDATA for a POST command
I tried dumping the data to a .har file directly.
Still i can see only the POST command has been send , but the data went along with it is missing in the har file 
my code is 
 Har har = server.getHar(); 
     try { har.writeTo(new File("c:\\test1.har")); 
     } 
     catch (IOException e) 
     { e.printStackTrace();
     }

hope someone could reply please

thanks
robin

robin paul

unread,
Apr 4, 2012, 4:18:00 AM4/4/12
to BrowserMob Proxy
Do i need to set any variable true for that ?

Patrick Lightbody

unread,
Apr 22, 2012, 11:12:34 PM4/22/12
to browserm...@googlegroups.com
Robin,
The reason this wasn't working was because it wasn't implemented. However, I just took a first stab at capturing POST parameters in the Har file. Just make sure you start the proxy this way:

        ProxyServer server = new ProxyServer(4444);
        server.start();
        server.setCaptureContent(true);

Let me know how that works for you.

Patrick

--
Patrick Lightbody



robin...@gmail.com

unread,
Jul 10, 2012, 6:57:08 AM7/10/12
to browserm...@googlegroups.com
Hi Patrick
Do i need to update the latest har and browsermob proxy jars for this
Because still i am not getting any post data contents after your suggested modifications
Currently i am using harlib-jackson-1.0b10.jar and browsermob-proxy-2,0-beta-6.jar


Thanks
RobinPaul

vasanth velayudham

unread,
Jul 10, 2012, 8:03:30 AM7/10/12
to browserm...@googlegroups.com
Hi Patrick,

Even I am facing this issue..I could not capture 'postdata' using
browsermob proxy. I have set the capture content value to 'True' as
well. But still the HAR file does not contatin the PostData. It would
be great if you help us in solving this issue.

Thanks,
V.Vasanth

Leong HE

unread,
Jul 19, 2012, 10:27:38 PM7/19/12
to browserm...@googlegroups.com
Patrick, 

+1 eagerly need this feature to be added. 

Thanks,
Leong

在 2012年7月10日星期二UTC+8下午8时03分30秒,VVasanth Kumar写道:

venkata raghuram

unread,
Jul 31, 2012, 12:53:50 AM7/31/12
to browserm...@googlegroups.com
I running my test using grid2 and Testng. Running the test remotely.

The problem am facing is when i have two test methods in one suite only one test HTTP request and response is recorded instead of two. 
I have used Beforesuite and Aftersuite annotations.

If they are replaced with AfterTest and BeforeTest they are properly recodred.

@BeforeSuite
ProxyServer server = new ProxyServer(4444);
try {
server.start();
} catch (Exception e) {
e.printStackTrace();
}
Proxy proxy = server.seleniumProxy();
proxy.setHttpProxy("xxx.xxx.xxx.xxx:4444");
server.setCaptureHeaders(true);
server.setCaptureContent(true);
server.newHar("Testpage");

@AfterSuite
HAR har = server.getHar();
try {
FileOutputStream fos = new FileOutputStream(strFilePath);
har.writeTo(fos);
server.stop();
}catch (Exception e) {
e.printStackTrace();
}

Can any one help me on this.
Reply all
Reply to author
Forward
0 new messages