Jmeter-Automation using Spring and Maven - Random Number Generation using javascript Issues - javascript

I have already existing jmeter scripts(which I cant change) which generates a random number using javaScript to generate Url parameters dynamically. Problem is the javascript itself is printed in the url as parameter instead of the number it shoud generate. (All of this happens when using Spring and maven combo(WebService- JAX-RS))
I need it to be a web Project to simplify the execution of the regression scripts. The script is correct as It runs properly when using the Jmeter UI
Interestingly when I run it using a main method It runs and generates the random number using JavaScript. I have all the jars under a standard download of Jmeter Installation in the classpath. I need help in either getting all files in classpath to the maven build or the dependencies of all to be added to get it working.
The Javascript is as follows :
72AE-442A-93C5-SWID1${
__javaScript(vard=newDate();varday=d.getDate();if(day<10){
day='0'+day;
}varmonth=d.getMonth()+1;if(month<10){
month='0'+month;
}varyear=d.getFullYear();varhour=d.getHours();if(hour<10){
hour='0'+hour;
}varmin=d.getMinutes();if(min<10){
min='0'+min;
}varsec=d.getSeconds();if(sec<10){
sec='0'+sec;
}varmsec=d.getMilliseconds();if(msec<10){
msec='00'+msec;
}elseif(msec<100&&msec>=10){
msec='0'+msec;
}currentDate=min+''+sec+''+msec)
}
If more details are required Please tell me
https://blazemeter.com/blog/5-ways-launch-jmeter-test-without-using-jmeter-gui
Using the Fourth way in the following link but calling the same logic via a Webservice
Thanks

Related

How to run a file on server on html-button click

how do I manage to execute a Python-file or a bash-script on a server via a press of a html-button without using a framework?
I have tried several versions of Ajax-Calls suggested in answers to similar questions, but none of them seem to work for me.
Note: Im using an Apache-Server on a RaspberryPi
According to apache documentation, you should configure apache to run CGI script, define an url prefix that maps a directory that contains your script and finally your script must return output in a particular way, or Apache will return an error message.
So, for example, if you define an url prefix like:
ScriptAlias "/cgi-bin/" "/path/to/your/script/cgi-bin/"
you can create a simple anchor to execute your script, you don't need to use ajax for this.
click me
To successful run your script you should follow apache directive in "Apache Tutorial: Dynamic Content with CGI"

How the get the whole source html code of a webpage that is generated by Javascript using Java / Webdriver?

I am a newbie in programming and I have a task here I need to solve. I am trying to get the html source code of a webpage using Java / Webdriver method getPageSource(). Problem is, that page is somehow generated, probably by javascript, so the result I get is html code containing just page skeleton - a table that is empty, not filled by data. But, there is tag like <script type="text/javascript" src="/x/js/main.c0e805a3.js"></script> in the very bottom of that html code.
The question is, how can I force Webdriver to run that Javascript and give me the result - the whole source html with data. I already tried to use this (js.executeScript("window.location = '/x/js/main.c0e805a3.js'");) before calling getPageSource() but not successful.
Any help will be appreciated, thanks!
There are quite a few setups, now, that can run the Java-Script on a web-page. The most well known, I think, is likely Selenium since I think it has been around for a while. Others include karate, Puppeteer, and even an old tool called Rhino. Puppeteer is a Google, Inc. project that uses Java-Script (server-side Java-Script, called Node.js. They don't like us comparing, contrasting libraries here.
I haven't had the time to engage Selenium, yet, but I write HTML parser, search and update code all the time. If your only goal is to load a page whose contents are dynamically "filled in by AJAX calls" - and what I mean by that, you only want the contents of an HTML that would normally see when you visit the sites web-page, and you are not concerned with button presses then the one I have been using for that is called Splash This tool does have the ability to let you invoke Java-Script, but if all you want to do is see the JS on a page dynamically load the table, then, literally, all you have to do is start-the tool, and add one line to your program.
On Google Cloud Platform, these 2 lines will start a Splash Proxy Server. If you are writing your code on AWS (Amazon) or Azure (Microsoft), it would likely be similar. If you are running your code in an office on the local machine, you would have to research how to start it.
Install Docker. Make sure Docker version >= 17 is installed.
Pull the image:
$ sudo docker pull scrapinghub/splash
Start the container:
$ sudo docker run -it -p 8050:8050 --rm scrapinghub/splash
Then, in your code, all you have to do is the following:
// If your original code looked like this:
URL url = new URL("https://en.wikipedia.org/wiki/Christopher_Columbus");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("GET");
con.setRequestProperty("User-Agent", USER_AGENT);
return new BufferedReader(new InputStreamReader(con.getInputStream()));
Change the first line of code in this example to this, and (theoretically), and dynamically loaded HTML tables that are completed with the onload page events will be automatically loaded before returning the HTML page.
// Add this line to your methods
String splashProxy = "http://localhost:8050/render.html?url=";
URL url = new URL(splashProxy + "https://en.wikipedia.org/wiki/Christopher_Columbus");
For most web-sites, any initial tables that are filled by JS/jQuery/AJAX will be filled in. If you are willing to learn teh Lua Programming Language, you can also start invoking the methods there. It has been pretty convenient for my purposes, since I am not writing web-page testing code (code that simulates user button presses). If that is what you are doing, Selenium is likely worth spending time learning / studying the A.P.I.

c++ tiny-js execute javascript function from external file

I have a C++ application which has to execute a Javascript-function from a dynamic file. (I need to read a proxy.pac file).
E.g. I have a C++ application running which reads the following file: proxy.pac (which contains the javascript function FindProxyForURL(url, host), which I have to call with the two parameters.
However, I have no idea how to start off and I can't find anything on the internet so far.
So basically my question is: how doe I load dynamic Javascript from a file and execute a function within that code(/file)
I made application server using TinyJS.
see this.
https://github.com/pochi0701/wizdlive

How to remove the optional call for 'library-preload.json' in SAPUI5 application?

I am developing a SAPUI5 mobile app using cordova. Now I need to include another library (cordova-plugin-file) into my project. I've already tried to do this, but my problem is, that if the plugin is included, my 'sap-ui-core.js' file tries to load 'library-preload.json' (see screenshot).
screenshot console
And I do not want to load a library-preload.json. How could I solve this problem?
An Answer on how to solve this problem by adding a 'library-preload.json' file
would also not be bad :)
Set the data-sap-ui-preload="" in SAPUI5 Boostrapping.
To Quote from Source:
The library-preload.json files which contain all controls from a
library to reduce the number of HTTP requests are not required in
hybrid apps because there is no HTTP latency. SAPUI5 will by default
try to access them, so you might see a failed attempt to load these
files in the log file or developer tools. These error messages do not
hurt, though, and you can get rid of them by declaring that no such
files exist and by setting the following configuration in the SAPUI5
bootstrap script tag:
`data-sap-ui-preload="" `
Read: https://sapui5.netweaver.ondemand.com/sdk/#docs/guide/293eb945f0e945aaa776812481b4c533.html
Preload has 3 more variants. Read More here:
https://help.sap.com/saphelp_nw74/helpdata/en/91/f1cea36f4d1014b6dd926db0e91070/frameset.htm?original_fqdn=help.sap.de

Visual Studio - JS file versioning

I'm working on a thin client web project - front end part only - with visual studio. I need to have the js and css file versioning within the htmls to remove the browser caching issue. Is there any way that I can achieve this with VS? ( I'm using SVN for the code repo )
If I understand it right, you are trying to burst the cache or invalidate the cache by trying to have new version of file every time the client requests the page from server. You can either append a query string to the URL of the CSS/javscript file links embedded in your HTML like :
<script src="//xyz.com/abc.js?12345"></script>
You can generate the query string dynamically using current date time or using some random number generation and add it as query string to the URL.
Or if you wish to maintain the files with different version numbers in the source code, something like abc.v1.js and abc.v2.js, you can use gulp or grunt task to generate the file and update the html with the version link
Finally found it. You can add a ?v=3.4.5.2 like versioning to the file and then replace the matching regex with the update revision num + timestamp by a before build script

Categories

Resources