How to Encrypt data in JMeter script - selenium-webdriver

I am writing a simple script in Jmeter to pass username and password to the logging page of a website. I want password to be encrypted but I am not sure if Selenium Webdriver API provide any functions to encerypt data before passing it into the sendKeys() function.
Here's what my script looks like:
WDS.sampleResult.sampleStart()
WDS.browser.get('url')
var pkg = JavaImporter(org.openqa.selenium, org.openqa.selenium.support.ui)
var wait = new pkg.WebDriverWait(WDS.browser, 5000)
var user = WDS.browser.findElement(pkg.By.id('userName'))
user.sendKeys(['username])
var pass = WDS.browser.findElement(pkg.By.id('password'))
pass.sendKeys(['password'])
PS: I know the approach to pass data from CSV but that's not exactly encryption.

Put the jar that contains the encryption algorithm in jmeter/lib.
Suppose this class is in class com.foo.utils.encryption.EncryptionUtils, you would do:
var pkg = JavaImporter(com.foo.utils.encryption)
var encryptUtils = new pkg.EncryptionUtils()
vars.put("result", encryptUtils.method(inputString));
You can then use the ${result} variable.

Related

How to move a shortcut in google drive

I need to move a shortcut file from one destination to another using google apps script.
Usually I would move a file or folder like this:
function move(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sStamdata = ss.getSheetByName("New");
var folderOld = DriveApp.getFolderById(folderOldId);
var destination = DriveApp.getFolderById(folderId);
var id = sStamdata.getRange('D77').getValue();
var file = DriveApp.getFileById(id);
folderOld.removeFile(file)
destination.addFile(file)
But this doesn't work with shortcuts. Any ideas?
How about this answer?
Modification points:
It seems that in the current stage, the shortcut cannot be moved using Drive service. I think that this might be resolve in the future update.
So as the current workaround, in this answer, I would like to propose to use the method of "Files: patch" Drive API v2, because Drive API of Advanced Google services is used.
When your script is modified, please modify as follows.
Modified script:
Before you run the script, please enable Drive API at Advanced Google services.
function move(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sStamdata = ss.getSheetByName("New");
// var folderOld = DriveApp.getFolderById(folderOldId);
// var destination = DriveApp.getFolderById(folderId);
var id = sStamdata.getRange('D77').getValue();
// var file = DriveApp.getFileById(id);
Drive.Files.patch({parents: [{id: folderId}]}, id); // Added
}
folderId is the destination folder ID.
Please confirm the file ID of the shortcut again.
Note:
For example, when the file ID of the shortcut is confirmed with the shared link using the browser, the file ID is ID of the original file. Please be careful this.
References:
Advanced Google services
Files: patch

How to write groovy Script in Jmeter

Hello Stackoverflow Community,
I am new to Jmeter and Related Stuff.
Just Finished with Login Request and Response through Selenium WebDriver Sampler(using Java Script) .
Screen shot is also attached with this post.
All working Well.
Now i go through some articles ,they stress on using groovy script(under JSR223 Sampler) but i am not able to figure out how to convert this same Javascript(WDS sampler) in Groovy(JSR223 sampler) runnable Script.I will be very thankful for any Kind of help in this direction.
Thanks
groovy(Groovy 2.4.15/Groovy Scripting Engine 2.0) is already displayed in my JSR223 Sampler [i m using apache-jmeter-5.0 ] i run hello world program its working fine..further i have no idea abt how to play with groovy script.
Below is my code in Javascipt(selenium WDS)
WDS.sampleResult.sampleStart();
WDS.log.info("Maximo Application ---- Sample started");
var pkg = JavaImporter(org.openqa.selenium); //WebDriver classes
var support_ui = JavaImporter(org.openqa.selenium.support.ui.WebDriverWait);
var wait = new support_ui.WebDriverWait(WDS.browser, 5000);
var conditions=org.openqa.selenium.support.ui.ExpectedConditions;
var selenium_keys=JavaImporter(org.openqa.selenium.Keys);
WDS.sampleResult.getLatency();
//-----------------------------Login in Application---------------------------------------------
WDS.browser.get('http://xxxxxxxxxxxxxxx/maximo/webclient/login/login.jsp'); //opens website
WDS.log.info("Maximo Application ---- Username and Password dynamicly picked from C:/user.csv ");
//UserName
var userName = WDS.browser.findElement(pkg.By.id('username'));
WDS.log.info("Maximo Application ---- Username "+'${username}');
userName.click();
userName.sendKeys('${username}');
//Password
var password=WDS.browser.findElement(pkg.By.id("password"));
password.click();
WDS.log.info("Maximo Application ---- password "+'${password}');
password.clear();
password.sendKeys('${password}');
WDS.browser.findElement(pkg.By.id("loginbutton")).click();
WDS.log.info("Maximo Application ---- Logged by USER Name--- "+ '${username}');
WDS.sampleResult.sampleEnd();
I really Wann to switch on groovy as all coming scenarios are going to be complex
WDS_javascript
i could give you the guidance about your code.
in general, even when you are using javascript in jmeter - you are calling java methods.
groovy will do the same but in syntax it's closer to java.
so:
declare variables with def instead of var
change JavaImporter(XYZ) to import XYZ at the beginning of script
remove all java imported variables as they not needed. such as support_ui
just an example:
import org.openqa.selenium.*; //need .* to import all classes from package
import org.openqa.selenium.support.ui.WebDriverWait; //import exact class
WDS.sampleResult.sampleStart(); //code remains the same
//var pkg = JavaImporter(org.openqa.selenium); //moved to import
//var support_ui = JavaImporter(org.openqa.selenium.support.ui.WebDriverWait); //moved to import
def wait = new WebDriverWait(WDS.browser, 5000); //removed `support_ui.`
def userName = WDS.browser.findElement(By.id('username')); //removed `pkg.`
and finally just learn java & groovy

Solr 4.3.1 Data-Import command

I'm currently using Solr 4.3.1. i have configured dih for my solr. i would like to do a full import through command prompt. I know the url will be something like this http://localhost:8983/solr/corename/dataimport?command=full-import&clean=true&commit=true is there any method i can do this without using curl ?
Thanks
Edit
string Text = "http://localhost:8983/solr/Latest_TextBox/dataimport?command=full-import&clean=true&commit=true";
var wc = new WebClient();
var Import = wc.DownloadString(Text);
Currently using the above code
Call it like a normal REST url that's it !! I am using it in my application for importing and indexing data from my Local drive and it just works fine ! :) . Use HttpURLConnection to make a request and capture response to see whether it was successful or not . You don't need any specific API to do that . This is a sample code to make a GET request correctly in C# .Try data import handler url with this, it may work !
Console.WriteLine("Making API Call...");
using (var client = new HttpClient(new HttpClientHandler { AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate }))
{
client.BaseAddress = new Uri("https://api.stackexchange.com/2.2/");
HttpResponseMessage response = client.GetAsync("answers?order=desc&sort=activity&site=stackoverflow").Result;
response.EnsureSuccessStatusCode();
string result = response.Content.ReadAsStringAsync().Result;
Console.WriteLine("Result: " + result);
}
Console.ReadLine();
}
}
}
You'll have to call the URL in some way - Solr only operates through a REST API. There is no command line API (the command line tools available just talk to the API). So use your preferred way to talk to a HTTP endpoint, that being curl, wget, GET or what's available for your programming language of choice.
The bundled solrCli application does not have any existing command for triggering a full-import as far as I were able to see (which would just talk to the REST API by calling the URL you've already referenced).

Python 2.7 and blobkeys: how to return the filename instead of the url?

Very new to Python/Google App Engine and just trying to work my way around a pretty massive application. This is what I currently have:
file_keys = self.request.get_all('blobKey').filename
file_links = []
for key in file_keys:
file_links.append('https://www.mysite.com/admin/downloads/%s' % key)
This will return something similar to this:
https://www.mysite.com/admin/downloads/4NLNpXrzZ0vjOZcOPzZpiQVoASeSXlZukbq0AMyFlmGYDhNZrWaRASBxL8TC6gjw
How would I go about returning just the file name? (It's a form where you enter some information and provide a file, and I would like to return that specific file's filename in the email sent out instead of the generated URL).
I would think filename would work as shown here: https://developers.google.com/appengine/docs/python/blobstore/blobinfoclass
But have not had any luck with that.
Any input is appreciated.
This is the solution I came up with:
file_keys = self.request.get_all('blobKey')
blob_info_list = blobstore.BlobInfo.get(file_keys)
file_info_list = []
for blob in blob_info_list:
info = {"file_name":blob.filename, "key":blob.key()}
file_info_list.append(info)
template_dict = { 'file_info_list':file_info_list}

nodejs connecting to db only once

I have a db.js file that has this line in the top to connect to the database.. i call this file to run queries from inside other js files:
var sqlite3 = require('sqlite3').verbose();
var db = new sqlite3.Database('./mydatabase');
db.serialize(function() {
db.each("SELECT rowid AS id, info FROM lorem", function(err, row) {
console.log(row.id + ": " + row.info);
});
db.close();
If i require() this above file 4 times in different files, does this mean sqlite database will be initialized that many times?
I want to initalize it only the first time..
Is this inefficient? Is there a more efficient way?
Official documentation: https://github.com/mapbox/node-sqlite3/wiki/Caching
Sqlite3 module can do caching internally if you use require('sqlite3').cached, i.e. it won't create new connections on new sqlite3.cached.Database(file) as long as string held by file is identical, but reuse existing ones. See in the source for yourself here:
https://github.com/mapbox/node-sqlite3/blob/master/lib/sqlite3.js
However, you should not depend on that. Do some kind of dependency injection, it will save many headaches along the way. In simplest form it will be writing your modules that they export functions accepting database object as their argument:
//module1.js
module.exports = function(db){
db.serialize(...)
//dostuff
}
//start.js
var sqlite3 = require('sqlite3').verbose();
var module1 = require('./module1.js');
var db = new sqlite3.Database('./mydatabase');
module1(db);

Resources