Jmeter Complex Parametrized Calls - javascript

I'm using Jmeter to simulate a flow between two webpages.
The case is complex since the call to the second webpage is done through a form passing a list of input parameters generated by a javascript function called when the user click on the button to pass to the second webpage
If i open firebug console I can see into POST the list of parameters i'm interested in
Due to the fact that i need to parametrize the Jmeter POST with the list of generated parameters is there any solution?
If it's not suitable any solution i'm considering to use regex to extract from the webpage the parameters the javascript function works with. However i really cannot find the parameter value since it is stored into a javascript variable: if i look at the html source code i see something like:
this.cabinNumber[numeroCabina]=$('#cabinnumber'+numeroCabina).val();
but i do not see the real value; (cabinNumberis te variable i'm interested in)
Is there any chance to read directly from HTTP Response Parameters maybe using BeanShell?
Please note that the webpage is developed with Struts1 technology

JMeter is not a browser and it cannot execute JavaScript on client pages, but:
If JavaScript doesn't assume communication with the server (which is unlikely) you should be able to replicate function using any suitable JMeter scripting extension starting with __javaScript function, Beanshell Scripting or even custom implementation of Java Sampler. Or alternatively "interesting" value is already in the response, it just hidden via styles
If it does (which is more common case) you can catch the request via firebug and replicate it with JMeter to retrieve desired cabin number.
You can also try comparing requests captured with firebug to requests captured by JMeter HTTP(S) Test Script Recorder and investigate the differences if any.

Related

Extract html sourcecode from a javascript generated output

I am currently working on a project of finding empty classrooms in our school in real time. For that purpose, I need to extract substitution published on our school page (https://ssnovohradska.edupage.org/substitution/?), since there might be any additional changes.
But when I try to extract the html source code and parse it with bs4, it cannot find the divs(class: "section print-nobreak") that contain the substitution text. When I took a look at the page source code(Ctrl+U) I found that there is only a javascript that prints it all directly.
Is there any way to extract the html after the javascript output has been already rendered?
Thanks for help!
Parsing HTML is unfortunately necessary to solve your problem. But I will explain how to find ways to avoid that in your future projects (not based on this website).
You've correctly noticed that the text is created by JavaScript code running on the page. This could also indicate that the data is either loaded from another resource (XHR/fetch call getting a response from an API) or is stored as a JSON/JS inside of the website's code. (Or is generated from an algorithm, but this is unlikely to be the case in such websites.)
The website actually uses both methods (initial render gets data stored inside of the website's code, but when you switch dates on the calendar it makes AJAX requests). You can see this by searching for ReactDOM.render(React.createElement( in the code. They're providing a HTML string to the createElement call, so I would suggest looking into the AJAX way of doing things.
Now, to check where the resource is located, all you need to do is opening Developer Tools in your favorite browser (usually Control+Shift+I) and navigating to the Network tab. Now that your network tab is open, you need to cause the website to load external data, for example, by pressing a date on the "calendar bar".
Here you will notice many external requests, but we're actually looking only for XHR calls. Click on the XHR button next to the "Filter" text field. That should result in only one request being shown:
Unfortunately for us, the response only contains HTML. Also, API calls are protected - they require a PHP session ID and some sort of a token (__gsh) to not fail. So, going back to step 1 - seems like our only solution is to use regular expressions to find the text between "report_html":"<div class and </div></div></div> from the source code, if you're interested in today's date only. If you want to get contents for tomorrow or any other date - you will need to either fetch the page, save the cookies and find the token to supply to the request and then make that request, or use something like puppeteer or pyppeteer (since you've mentioned BS4) and load the webpage in that. If you aren't doing the data fetching that often, you should be fine overall.

Jmeter: login recorded script not working: getting error javascript not enabled

login in issue: On running jmeter script recorded through workbench scriptrecorder, getting an error java script is not enabled, not able to complete test. tried to disable cookie manager still login is not working. getting message page got refreshed before navigating to next page. getting login screen only under listener view results tree view.
steps that i did: created test plan, added thread gp, added config element cache manage, cookie manager, HTTP default then added recording controller
recorded script via workbench recording controller.
tried same script via transactional controller and blazemeter recorder.
All scripts are failing at same point. login is not happening so not moving any further.
Any help would be appreciated. thanks
Record and replay will not work in the majority of cases, modern web applications are quite complex and they use dynamic parameters for different reasons, i.e. for page-level state management or security reasons. So if you record this parameter and will try to re-use it while replaying it will not work.
The process of handling dynamic parameters in JMeter is known as correlation and looks like:
Record your scenario 2 times
Compare 2 scripts to identify any dynamic values (don't forget to look not only into HTTP Request parameters, but inspect request headers as well, it can be done using View Results Tree listener)
Once you identify the dynamic parameters you will need to extract them from previous response, convert them info JMeter Variables and add them to the next request. You can consider using the following test elements for extracting the dynamic values from the responses:
Regular Expression Extractor - when response is text-based
CSS/JQuery Extractor - when response is HTML
XPath Extractor - when response is XML, XHTML or HTML
JSON Extractor - when response is JSON
Validate variables values using Debug Sampler and run the whole test to ensure that it is doing what it is supposed to be doing.

Retrieve GET requests with Javascript in Firefox console

Is there a way to retrieve details of GET requests of a web page using JavaScript? I don't mean parameters of the current page's URL but out-going GET requests.
Example:
If you open google's start page with firefox and toggle developer-tools, in the network tab you can see a number of GET request such as that for the logo which is something like https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png
I want to retrieve this URL on console tab using JavaScript. Is it possible to retrieve it via an object attached to the DOM (document) or BOM (window)?
The reason for my question is: I am in an test automation environment where developer-tools are not available. Only JavaScript is available and I need to check the URL of a GET request issued by the current page. I just mentioned developer-tools because it is the simplest way to reproduce the problem (and the easiest way to verify, if a solution works). But it is more about Firefox/HTTP than test automation as such.
I don't think it's possible within devtools, but you may be able to use normal JS to make a global event handler (if it's jQuery) or if using normal JS, replace the XmlHttpRequest object with a duckpunched object that logs the result, as described here.

How to pass array as a parameter to a plsql procedure through javascript

I am calling a plsql procedure from window.opener.location.href, I want to pass an array as a parameter to this procedure.
window.opener.location.href="dt_bulk_test_pkg.pc_bulk_test?ps="+frmresult.ps.value+
"&p_step="+frmresult.p_step.value+
"&p_year="+frmresult.p_year.value+
"&p_quarter="+frmresult.p_quarter.value+
"&p_diagnostic_type="+frmresult.p_diagnostic_type.value+
"&p_overwrite="+frmresult.p_overwrite.value+
"&p_company_id="+v_comp_id;
v_comp_id is an array.
PL/SQL is a database technology, Javascript is an in-browser technology (unless you're doing server side JS with node or Rhino but you are not). The browser can only communicate with web servers. So from the point of javascript, you're not calling a stored procedure, you're calling a web-server that you must have running somewhere that calls that stored procedure.
How exactly arrays are represented is up to the server-side language/web-framework, but a fairly standard approach is that taken by jQuery's $.param method. For example, opening up the console on this site I can do this:
> $.param({example: [1,2,3]})
"example%5B%5D=1&example%5B%5D=2&example%5B%5D=3"
Words of warning.
Exposing database stored procedures directly via HTTP is not only bad design, but likely a crazy-bad security risk.
Embedding parameters in a url means you are using an HTTP GET request. GET requests are meant for resources that do not affect the state of the server so be careful that your stored procedure only gets data, not changes it. The danger is that someone could put that url in an email or even an img src tag on a webpage and people would hit that url simply by clicking a link or visiting a web page.
All parameters should pass through url encoding. Like I mentioned, jQuery.param will do this.
You are likely exposing yourself to XSS attacks as well.
I know that this is an old thread but I landed here so I guess others will.
It is quite possible to pass arrays to PL/SQL via a URL and it is explicitly supported, not a dodgy hack. Link to Oracle doc
You declare the PL/SQL input parameter as a table of varchar2. Then you pass the same parameter name repeatedly in the URL.
1/ Example PL/SQL source:
CREATE OR REPLACE PROCEDURE test_array(
p IN dbms_sql.varchar2_table )
AS
BEGIN
FOR i IN p.FIRST .. p.LAST
LOOP
htp.p(p(i)||'<br>');
END LOOP;
END test_array;
*2/ Example URL to invoke it: - substitute XXXXXXXXXXXXXX with your own setup *
http://XXXXXXXXXXXXXX/test_array?p=first ele&p=second ele
3/ Output
first ele
second ele
You can pass in as many elements as you want, I just used 2 for this example.
If your data type is not varchar2, capture them as varchar2 from the URL anyway and convert them to numbers etc inside the pl/sql.

How does the diigolet bookmarklet get around cross-scripting?

http://www.diigo.com/tools/diigolet
Diigolet essentially allows you to use a bookmarklet to bookmark sites. With the bookmarklet I'm making, I also need to pass the current URL of the site the user is on to my server. Everytime I try this, I get a cross-scripting error.
Does anybody know how to bypass this like the diigolet?
Essentially, they work around the same-origin policy by injecting a script tag with the different-domain URL rather than using an XMLHttpRequest. Note that this is different from a normal JSON request in that the JSON is wrapped in a callback function, for example:
myCallbackFunction(<JSON here>);
(This works because JSON is a subset of JavaScript's object literal notation.)
In their case, they hardcode the name of the callback function as diigolet.callback, but there exists a specification called JSONP that JavaScript libraries such as jQuery support.
Under the JSONP specification, the name of the callback function is passed to the server via a callback=myCallbackFunction parameter in the GET request. Your server-side code needs to handle this appropriately to be able to handle JSONP requests from jQuery.

Categories

Resources