Read JS variable in C # / Forwarding JS variable for visual studio performance test?

People use visual studio to test performance. Now there are some minor problems with some parts of javascript: they cannot test the performance of the javascript part with testing web performance in visual studio.

I never used a studio studio performance test, so I really have no idea how to make a bench there, but I saw that there are many solutions to test web + js performance. I thought we could use other tools and frameworks, but this is not allowed. People here want to use a visual studio for everything. So it makes things more complicated.

If I need to test javascript performance, I would easily do something like this:

var begin = new Date(); functionA(); functionB(); functionX(); var end = new Date(); var bench = end - begin; 

At the end, I see my result in the variable bench . Now I just need to pass this variable β€œsomehow” to the visual studio performance test? Via C #? Or how does it work? Could this be a good solution? Any other ideas?

+6
source share
4 answers

I do not think this is possible, because the VS Performance Test Engine does not run any client code at all, it works only at the HTTP level. That way, the code you provided as an example will never run.

Take a look here for proof - http://msdn.microsoft.com/en-us/library/ff520100.aspx

Since the Web performance testing module works at the HTTP level, it does not run client scripts such as JavaScript or ActiveX control. Testing web performance is associated with generating a load on the server .. Therefore, client scripts that only affect the appearance of a web page are not significant for web performance Verification. A client-side script that sets parameter values ​​or results to additional HTTP requests, such as AJAX, affects the load on the server and may require you to manually change the performance of the Internet Test to simulate scripts.

A common misconception is that since it is being recorded on the Internet, Explorer and the Web Page Performance Testing Tool displays the results in browser management. Web performance tests must somehow use Internet Explorer. This is not the case. All queries are executed directly using the Web Performance Test Engine; no interaction with Internet Explorer or any other browser. Web Performance Test Engine communicates directly with the target web server using standard HTTP requests / response messages.

Thus, the only way is to use other solutions to test javascript performance or implement your own, for example, based on Selenium. I think that you can automate such measurements with Selenium RC, which can be run from Visual Studio as part of the assembly (if you need to use Visual Studio for everything).

+5
source

Of course, this might work, but I'm not sure if it can connect directly using the VS performance test. An alternative can simply be created if you want to integrate with C # and VS.

In this case, the question will lead to how JS and C # can be combined. This can be done with the .NET platform if you embed your JS on a page and then launch it using the WebBrowser control. In your javascript, you can pass the information back to the C # application by specifying window.external . Here is an example of your javascript:

 window.external.performanceCallback([yourdata]); 

to call the performanceCallback () method on the class that your WebBrowser control is in. However, before you can do this, you must make your class visible to the page that your web browser opens (window.external is the instance class you are referring to).

So, to set window.external when you create webBrowser in C #:

 webBrowser1.ObjectForScripting = this; 

In addition, you must mark the class with the ComVisible attribute.

 [ComVisible(true)] 

We remind you that WebBrowserControl depends on the version on IE installed on your computer. Therefore, be careful when versioning, javascript will only work to the extent that its IE can work. Make sure JS works in all reasonable versions of IE.

+2
source

You cannot directly control JavaScript, but you can force JavaScript to periodically call the C # web service with a timestamp. (Of course, this adds extra overhead, which will certainly distort the results and may deny the whole goal. If you run this test on a local network, latency should be somewhat mitigated.)

Javascript

 var log = function (message) { $.ajax('/path/to/log', { type: "POST", contentType: "application/json; charset=utf-8", data: JSON.stringify({message:message}) }); } // then just call it like so in appropriate places: log('started foo at 12:34:56'); 

WITH#:

asmx service or MVC controller or whatever accepts ajax message

+1
source

All Articles