-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
get Har Log as java object from selenium #9
Comments
I don't have much experience with Java and Selenium, but could you just store the HAR log (as a text) inside an element on the page:
...and then do something like as follows in Java:
Honza |
That's awesome! Thanks for the tip. It works! |
Excellent, out of curiosity, can you paste the full example here? |
Here is code I have, it uses sessionStorage to store the har.
This works for most of the websites I tested. But I ran into two edge cases.
Do you know how to resolve those two edge cases when I try to get har through the API? autoExportToFile works for all cases, but I don't really want to read har file in as string if I don't have to. Thanks! |
Both these cases look like a bug. I'll investigate it Honza |
@chemicwepn - it should work if you use executeAsyncScript. I'm using a similar setup, but from node.js. const script = `
var callback = arguments[arguments.length - 1];
function triggerExport() {
HAR.triggerExport({'token':'test', 'getData':true})
.then((result) => callback(result.data))
.catch((e) => callback(e));
};
if (typeof HAR === 'undefined') {
addEventListener('har-api-ready', triggerExport, false);
} else {
triggerExport();
}`;
return driver.executeAsyncScript(script); I guess in you case replace the callback(result.data) with {
sessionStorage.har = result.data;
callback();
} to indicate that the async process of generating and storing the har is done. |
Hi Team, Is the issue for the case 2] solved? My test case is: Result generated: Only the step 3] and step 4] har logs are captured in the .har file The step 1] and step 2] har logs are not captured. Is there any tracking bug for this? When I set "devtools.netmonitor.har.enableAutoExportToFile" set to true, logs are generated for all steps. Thanks. |
Hi,
I am wondering if there is way to get the har log as a string or object using selenium in java? Currently I would have to read from the saved har file and read that in as a string. I know we can trigger the har export through java script, but I don't know how to get it in the java code...
Something like this?
driver.get("https://google.com");
if(driver instanceof JavascriptExecutor) {
((JavascriptExecutor) driver).executeScript(
" var options = { token: "mySpecialValue", getData: true, title: "Title for the HAR log", jsonp: false,};" +
"HAR.triggerExport(options).then(result => { var har = JSON.parse(result.data); console.log("HAR log: ", har.log);}, err => { console.error(err);});");
}
then, how do I get it in java code...
Thanks!
The text was updated successfully, but these errors were encountered: