I'm trying to do performance testing using browsermob proxy and webdriver with below code. I was able to setup everything and run sample test case. But how to get har output and view HAR viewer to analyse the results?
ProxyServer server = new ProxyServer(9090);
server.start();
Proxy proxy = server.seleniumProxy();
FirefoxProfile profile = allProfiles.getProfile("webdriver");
WebDriver driver=new FirefoxDriver(profile);
profile.setProxyPreferences(proxy);
server.newHar("google.com");
driver.get("http://google.com");
Har har = server.getHar();
Am exploring Browsermob as well. I think once u have the har, you can use the har.writeTo function to write to a file. Then use a HAR viewer (http://www.softwareishard.com/har/viewer/) to view the file.
http://code.google.com/p/harviewer/.
After getting the Har object, you need to write it to a file. For example:
Har har = server.getHar();
try
{
FileOutputStream fos = new FileOutputStream("mycapture.har");
har.writeTo(fos);
}
catch (Exception e)
{
e.printStackTrace();
}
After this runs, you'll have a file named mycapture.har in the current working directory, and you can open it with a text editor. The file format is JSON. As niharika_neo noted, you can then upload the .har file to an online .har viewer.
Related
I'm creating blazor server app. I use external file storage with RestAPI.
I want to create download button to get file from storage. This may seem easy, but not necessarily.
From file storage I download HttpContent like that
var request = new HttpRequestMessage(HttpMethod.Get, _url);
request.Headers.Add("auth-token", token);
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/octet-stream"));
HttpResponseMessage response = await _Http.SendAsync(request, HttpCompletionOption.ResponseHeadersRead);
response.EnsureSuccessStatusCode();
var content = response.Content;
next I act like this tutorial https://learn.microsoft.com/en-us/aspnet/core/blazor/file-downloads?view=aspnetcore-6.0
var fileStream = content.ReadAsStream();
using (var streamRef = new DotNetStreamReference(fileStream))
{
await JS.InvokeVoidAsync("downloadFileFromStream", "file.txt", streamRef);
}
For small files everything work great. But if I try to download large file (100mb), algoritm firstable download file to memory(RAM) of server and later save on local disk of client.
In ideal world I dream that when I click button download, file from external storage will download after delay (with progressbar) like physical file (no stream buffer) form http server e.g. https://www.example.com/file.txt. Of course by my BlazorServer Application with authorization and authentication, and whole neccesery services.
I have solution.
Create Service to service File Storage API
Create controller to avoid cros-origin error
Use microsoft tutorial to create download button https://learn.microsoft.com/en-us/aspnet/core/blazor/file-downloads?view=aspnetcore-6.0
I'm using milton, and my upload code as follows:
#PutChild
#Transactional
public FileContentItem uploadFile(FolderContentItem parent, String name, byte[] bytes){
String traceId = UuidGenUtil.createUuid();
try {
QUERY_LOGGER.info("[uploadFile][NetdiskController],action=Request, name={}, size={},traceId={}",name,bytes.length,traceId);
In windows, i can upload file successfully, but with Mac Finder, the length of bytes is always 0, and the error as follow:
The Finder can't complete the operation because some data in "Shot.png" can't be read or written (Error code -36)
Anyone know why? Thanks
Update: I try ForkLift webdav client in mac and can upload file successfully
The problem is that mac finder sends first request for creating new file without any byte
After it - call LOCK, which is not available for Dav Level 1, that's why you have bad response from server and mac stop uploading a file. This method availiable only for Dav level 2, so you have to get enterprise license of milton to make it work
After Locking object Finder uploads the file
After - calls UNLOCK method
SO if you want to use mac finder for webdav in milton you have several options:
Get the trial enterprise license and look into this example:https://github.com/miltonio/milton2/tree/master/examples/milton-anno-ref
Realize these methods by yourself by webdav specs
Mock it - extend from MiltonFilter or look into MyOwnServlet in example and in method doFilter/service write something like this:
//mock method, do not use it in production!
HttpServletRequest request = (HttpServletRequest)req;
HttpServletResponse response = (HttpServletResponse) resp;
if(request.getMethod().equals("LOCK")){
response.setStatus(200);
response.addHeader("Lock-Token", "<opaquelocktoken:e71d4fae-5dec-22d6-fea5-00a0c91e6be4>");
} else if(request.getMethod().equals("UNLOCK")){
response.setStatus(204);
}else {
doMiltonProcessing((HttpServletRequest) req, (HttpServletResponse) resp);
}
I've checked this code working in the examble by link above: make in web.xml method serving by MyOwnServlet, disable authentication in init by implementing empty security manager, set controller packages to scan "com.mycompany"
p.s. to build the example project I've to delete milton client dependency from pom.xml file
I am trying to figure out a way to to upload an image from the mobile phone to a remote server using Icenium+Cordova (mobile) and ASP.NET.
I did try to use FileTransfer() command while providing a remote webservice address but without success. I am using Icenium simulator and Visual Studio to test the code locally.
What I need is a code example of the mobile (Javascript) and Server (.NET) side to support that image upload communication. Thanks.
The code that I am currently using:
function uploadPhoto(imageURI) {
var options = new FileUploadOptions();
options.fileKey="image_file"; // recFile
var imagefilename = Number(new Date())+".png";
options.fileName=imagefilename;
options.mimeType= "text/plain";
options.chunkedMode = false;
params = {
val1: "some value",
val2: "some other value"
};
options.params = params;
var ft = new FileTransfer();
ft.upload(imageURI,"http://127.0.0.1:1691/ImageWebService.asmx/SaveImage", success, fail, options);
}
On the server side:
[WebMethod]
[ScriptMethod]
public string SaveImage()
{
try
{
HttpPostedFile file = HttpContext.Current.Request.Files[0];
if (file == null)
return "0";
HttpPostedFile file =
HttpContext.Current.Request.Files[0];
string targetFilePath = "c:\\" + file.FileName;
file.SaveAs(targetFilePath);
}
catch (Exception ex)
{
}
return "1";
}
I also have:
<access origin="*" />
In the config.xml for cordova.
Note: I tested the webservice for image upload using the standard file upload control using "Advanced Rest Client" and it returned 200 OK.
Other than that, I'm stuck and can find a way to successfully upload am image to the remote server. I am open to using other method, but I think that using the native Cordova FileTransfer() is the safer way to do that if I want the best comparability.
You should use machine name and your device should be connected to the same network. There is no way for your device to know what 127.0.0.1 is, as it is a loopback address. Always test your services by trying to access them from a browser from another machine.
Cordova version has nothing to do with it, Icenium provides all device API even now, there is no need to manually include them as separate plugins.
I suppose you are trying to compile with cordova version 3.
From what I have understood, in cordova-3 most of the device-level API has been moved to external plugins:
Read "Accessing the Feature" in
http://cordova.apache.org/docs/en/3.0.0/cordova_file_file.md.html#File
So in Icenium it doesn't work anymore.
If you try to go in you project properties and set cordova 2.7.0 everything will works.
To be sure add this line in your main javascript, in the deviceready event:
alert("deviceReady!");
alert(device.platform);
if you get both alert msg, the app is working correctly and also the filetransfer will work.
But if you import the File-Transfer GitHub project in Icenium, still using the cordova-3, it will work correctly. That's really a mistery and only Telerik can explain us what they are doing!
Ciao
Marco
Well, I already tried a lot of stuff to solve this issue, but none did.
I developed a Reporting Service (2005) and deployed it.
This report will be used by everyone who access a website (it's a internet site, so, won't be accessed by intranet) developed on the framework 3.5 (but I think the framework's version is not the source of the problem).
When the user clicks on the button to download the .pdf which the Reporting automatically generates (the end-user never sees the html version of the Report), it asks for windows credentials.
If the user enters a valid credential (and this credential must be a valid credential on the server which the Reporting Service is deployed), the .pdf is obviously downloaded.
But this can't happen. The end-user must download the .pdf directly, without asking for credentials. Afterall, he doesn't even have the credentials.
Response.Redirect("http://MyServer/ReportServer/Pages/ReportViewer.aspx?%2fReportLuiza%2fReportContract&rs:Format=PDF&NMB_CONTRACT=" + txtNmbContractReport.Text);
The code snippet above, shows the first version of my code when the user clicks the button. This one propmts for the Windows credentials.
I already tried to change on IIS the Authentication of the virtual directory ReportServer, but the only one which works is the Windows Credentials. The other ones doesn't even let me open the virtual directory of the Report or the Report Manager's virtual directory.
When I tried to change it to Anonymous Authentication he couldn't access the DataBase. Then I choose the option to Credentials stored securely on the report server. Still doesn't work.
The physical directory of my ReportServer virtual directory points to the reporting server folder on the Hard Disk (C:\Program Files\Microsoft SQL Server\MSSQL.5\Reporting Services\ReportServer). I moved the same folder to my wwwroot directory.
Didn't work. The virtual directory didn't even open. Then I read this could be a problem because I had the same name on two folders (one in C: and other in wwwroot). So I changed the name of the one in wwwroot. Same issue of the DataBase connection couldn't be done.
I returned the physical path to C:
Below, is the second version of my button's event code:
ReportExecutionService rs = new ReportExecutionService();
rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
rs.Url = "http://MyServer/ReportServer/ReportExecution2005.asmx";
// Render arguments
byte[] result = null;
string reportPath = "/ReportLuiza/ReportContract";
string format = "PDF";
// Prepare report parameter.
ParameterValue[] parameters = new ParameterValue[1];
parameters[0] = new ParameterValue();
parameters[0].Name = "NMB_CONTRACT";
parameters[0].Value = txtNmbContractReport.Text;
string encoding;
string mimeType;
string extension;
Warning[] warnings = null;
string[] streamIDs = null;
ExecutionInfo execInfo = new ExecutionInfo();
ExecutionHeader execHeader = new ExecutionHeader();
rs.ExecutionHeaderValue = execHeader;
execInfo = rs.LoadReport(reportPath, null);
rs.SetExecutionParameters(parameters, "pt-br");
String SessionId = rs.ExecutionHeaderValue.ExecutionID;
try
{
result = rs.Render(format, null, out extension, out encoding, out mimeType, out warnings, out streamIDs);
execInfo = rs.GetExecutionInfo();
}
catch (SoapException se)
{
ShowMessage(se.Detail.OuterXml);
}
// Write the contents of the report to an pdf file.
try
{
using (FileStream stream = new FileStream(#"c:\report.pdf", FileMode.Create, FileAccess.ReadWrite))
{
stream.Write(result, 0, result.Length);
stream.Close();
}
}
catch (Exception ex)
{
ShowMessage(ex.Message);
}
For this code, I had to add a WebReference to the .asmx file mentioned in it.
When I'm debugging (on Visual Studio 2010), the code above works fine, doesn't asking for credentials (unfortunately, it doesn't prompt the option to open, save or cancel de file download. But this is another problem, no need to worry with it now) and save the file on C:.
When published, the code doesn't work. An erros says: The permission granted to user 'IIS APPPOOL\ASP.NET v4.0' are insuficient for performing this operation. So I added to the Reporting Service's users this user. When I tried again, the error is: Login failed for user IISAPPPOOL\ASP.NET v4.0. Cannot create a connection to data source 'MyDataSourceName'.
Both Report and WebSite are deployed/published on the same server with a IIS 7.5 version.
Summarizing: I need a solution where there is no credential prompt, and the user can choose where it wants to save the .pdf file.
Any help will be appreciated.
If you need more information to help me, just ask.
Thanks in advance.
One solution would be to create a new App Pool with an account that has the rights to access your restricted resources and then assign your web application to it.
How can I download file from SVN repository from my web application in C#.net?
I want to download file programatically. When button is clicked, it should download file from URL given in TextBox.
First off, you should be able to access (read-only) the file directly on the repository without the need for an SVN client (though you may need authentication). In that case, it's just like downloading any file from any URL:
using (WebClient client = new WebClient())
{
// In case you need authentication...
// client.Credentials = new NetworkCredential("username", "password");
client.DownloadFile(fileUrl, localDestinationPath);
}
However, like Vinayak said, SharpSvn is not a bad way to go-- it's pretty good for handling SVN interactions. So if using the standard WebClient doesn't work, you can do the following in SharpSvn to get the file stream:
MemoryStream stream = new MemoryStream();
using (SvnClient client = new SvnClient())
{
client.Authentication.DefaultCredentials = new NetworkCredential("username", "password");
client.Write(SvnTarget.FromUri(svnFilePath), stream);
}
return stream;
Hope this helps!
Edit:
I've also found another SharpSvn Tutorial which i hope u'll find helpful. It has everything from Introduction to SVN Operations(checkout,commit, etc)
Also,
Read about SharpSVN and check out this blog
there are few related examples for Checkout, update, commit in c#
The source code contains an example project as well