Selenium with BrowserMob.com - selenium

I am working with Selenium in order to create load balancing tests on a web server. The website has a username/password and in order to work with this I have a csv file filled with username password combinations.
The issue is I am using the random function in Javascript to select a row from the csv file and populate the login functionality or registration details.
var csv = browserMob.getCSV("pickStickEmails.csv");
var row = csv.random();
var Email = row.get("email");
var Password = row.get("password");
selenium.type("ctl00_StandardMainBodyPlaceHolder_ctl00_TextBoxEmail", Email);
selenium.type("ctl00_StandardMainBodyPlaceHolder_ctl00_TextBoxEmailConfirm", Email);
selenium.type("ctl00_StandardMainBodyPlaceHolder_ctl00_TextBoxPassword", Password);
selenium.type("ctl00_StandardMainBodyPlaceHolder_ctl00_TextBoxPasswordConfirm", Password);
This obviously brings up issues when registering if the same record is selected twice during a scheduled run. Obviously with the login situation if a record isn't selected when registering and is then selected on a test that requires an existing account the test fails due to it not existing.
My question is, is it possible to somehow get browserMob to iterate through the records one at a time? Obviously when browserMob begins a load test it ramps up to lets say 10 users using the website at one time each running the script I assume?
I did write the test using Selenium-RC in C# with NUnit and read the csv file into a List and then iterated through the list. Obviously this runs each user after another and doesn't simulate multiple users being on the site at one time.
Any advice on this would be greatly appreciated.
Thanks,
Jon

To enforce unique parameterization you need to call browserMob.getUserNum() as that will get the user number for that node that is processing your test. You can see this in their help. I have updated your code to how I think it should look. Should means I have not tested it :)
var csv = browserMob.getCSV("pickStickEmails.csv");
var row = browserMob.getUserNum();
var Email = row.get("email");
var Password = row.get("password");
selenium.type("ctl00_StandardMainBodyPlaceHolder_ctl00_TextBoxEmail", Email);
selenium.type("ctl00_StandardMainBodyPlaceHolder_ctl00_TextBoxEmailConfirm", Email);
selenium.type("ctl00_StandardMainBodyPlaceHolder_ctl00_TextBoxPassword", Password);
selenium.type("ctl00_StandardMainBodyPlaceHolder_ctl00_TextBoxPasswordConfirm", Password);

I think this could possibly be a way to get a unique record for each user during a load test:
var csv = browserMob.getCSV("pickStickEmails.csv");
var rowNumbers = new Array();
for(i = 0; i <= csv.size(); i++)
{
rowNumbers.push(i);
}
var uniqueRowNumber = rowNumbers[browserMob.getUserNum()];
var row = csv.get(uniqueRowNumber);
var Email = row.get("email");
var Password = row.get("password");
selenium.type("ctl00_StandardMainBodyPlaceHolder_ctl00_TextBoxEmail", Email);
selenium.type("ctl00_StandardMainBodyPlaceHolder_ctl00_TextBoxEmailConfirm", Email);
selenium.type("ctl00_StandardMainBodyPlaceHolder_ctl00_TextBoxPassword", Password);
selenium.type("ctl00_StandardMainBodyPlaceHolder_ctl00_TextBoxPasswordConfirm", Password);
It basically creates an array of numbers which act as row numbers for the csv file. Then it just uses the get() function on the CsvTable instead of random using the unique number selected from your suggestion.
Thank's for the guidance!

Related

.net core 3.1 & identity issue (claims nameidentifier has an id that doesn't match any user, while claims name is right)

I'm having an issue in an area of my website where i need to retrieve the user Id, i tried both by using the HttpContext.User and the injected IHttpContextAccessor, both give me an id that 1) doesn't match the user and 2) doesn't even exist in my database!
I also tried injecting a UserManager and calling GetUserId on it and that too gives me the wrong id (once again, no clue where from, it's not in the database). Calling GetUserAsync on it returns null.
I'm not using anything special nor fancy, the default page included with idendity core to log in, just a context that inherits from IdentityDbContext, and the login part works just fine as those pages are behind an Authorize tag and do force me to log in. If i was getting an error to begin with i could dig but i'm just getting an Id that seems to come from nowhere and am at a loss at where to look.
Here's what the claims look like when calling
HttpContext.User.Claims.ToList()
[0]: {http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier: f478bf7a-1734-494c-aad6-0882ab24007f} <-- this id is not present in AspNetUsers table
[1]: {http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name: EDITED OUT FOR PRIVACY} <-- my correct username (my email)
[2]: {AspNet.Identity.SecurityStamp: EDITED OUT}
[3]: {http://schemas.microsoft.com/ws/2008/06/identity/claims/role: Administrator} <-- correctly finds my role too
You can use the following code to get the UserId
using System.Security.Claims;
using Microsoft.AspNetCore.Identity;
var claimsIdentity = (ClaimsIdentity)this.User.Identity;
var claim = claimsIdentity.FindFirst(System.Security.Claims.ClaimTypes.NameIdentifier);
var userId = claim.Value;
I had that problem for using this in ExternalLoginCallback:
var user = new SmileAppUser { UserName = email, Email = email };
await _signInManager.SignInAsync(user, isPersistent: false);
Try to retrieve the user from the database to include the id in the claims with SignInAsync.

How to set most recently used parameter value as Default in value prompt or text prompt in Cognos Bi

I am using Cognos Bi 10.2.2 version.
I have created a prompt page for a parameter with value prompt.I am using the parameter as "Term_Code" which containing values such as 201410,201420,201510... and I will select the Parameter value "201420" for the first time while running the report. When i run my report again in future i must get default value as 201420 which is Most recently used parameter Value. Can Anyone Know it,
How to get Most recently used parameter value as the default value in value Prompt. Please help me.
Thanks in advance.
You can create a cookie to set its value to what the user last selected. The way I've done this is to drag an HTML Item to after the prompt then inside the HTML element, you can place the JavaScript to take care of creating the cookie and setting its value.
Here is the JavaScript I used:
<script>
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
function subtractDay ()
{
var dtToday = new Date();
var dtYesterday = new Date( dtToday - 86400000 ); // 86400000 = 24 hours * 60 (minutes per hour) * 60 (seconds per minute) * 1000 (milliseconds per second)
var strYesterday = [dtYesterday.getUTCFullYear(), dtYesterday.getMonth()+1, dtYesterday.getDate()].join("-");
return strYesterday;
}
var x = readCookie('MyCookie');
while (x != 'Value'){
pickerControlpDatePicked.setValue(subtractDay() );
createCookie('MyCookie','Value',0);
x = readCookie('MyCookie');
}
</script>
The function pickerControlpDatePicked get the date selected (that was my use case). I think there should be a similar function for String
this is just a suggestion of a possible solution.
In Framework Manager you can make a query subject linked to a stored procedure. Every time the report is executed, the parameter Team_Code would be passed to the query linked to the stored procedure, and the stored procedure would save its value in a database table.
The next time the report is executed, the prompt page would query the table of the saved parameters for the last parameter saved, and using the JavaScript Prompt API would set this value as the default value of the prompt control in the prompt page.
I hope this helps, good luck!
Cognos is not designed to store information about prompt choices, with the one exception of report views. However, this won't help you as report view prompt values are not dynamic. You set a fixed value and it keeps that value until you change it manually.
What I would do is setup a small Web service. This would be a Web page whose purpose is to receive requests via Web URL and return information or perform some action. A single page could be created to:
Receive a new value and store it in a database, or even a cookie
Retrieve a value from the database/cookie and return it to the requester
The Cognos prompt page would have JavaScript that fired when the prompt page is first generated to retrieve the stored value via the Web service and set the prompt value to the previous selection. There would also be JavaScript that fired when the user selected a new value which would send the choice to the Web service for storage.

Google Spreadsheet API Changes

We are using Spreadsheet API in our .Net Application to change content dynamically in the spreadsheet, and we are using that content to update values in the Google Ads with AdWords Script.
But from 1st June 2015 we are facing issues in our .Net Application, because of the update in the Spreadsheet API.
Our earlier work :- We were making window based application and scheduling it hourly. In the background it was retrieving and adding value in the spreadsheet. In the previous application, we used to authenticate our Gmail id and password only once in our code.
Below is the exact problem we are facing :-
As per the new API we need to authenticate our app each and every time it runs and also every time we need to put unique access code, which will badly affect our automation.
I would appreciate your immediate attention to this matter, and looking forward to your revert.
After lot of R&D I got the solution.
Links:
https://developers.google.com/apps-script/guides/jdbc
//it will insert value into table entries
function main() {
// Replace the variables in this block with real values.
var address = 'Your Server IP:1433';
var user = 'Server username';
var userPwd = Server Password';
var db = 'lms';
var dburl = 'jdbc:sqlserver://Your Server IP:1433;DataBaseName=lms';
// Write one row of data to a table.
var conn = Jdbc.getConnection(dburl, user, userPwd);
Logger.log(conn);
var stmt = conn.prepareStatement('INSERT INTO entries '
+ '(guestName, content) values (?, ?)');
stmt.setString(1, 'First Guest');
stmt.setString(2, 'Hello, world');
stmt.execute();
// Write 500 rows of data to a table in a single batch.
}

(Google App Script) Can i give access to other users to my private Spreadsheet with oAuth?

i need help for my application "Google App Script".
I am the owner of a Spreadsheet that I use as a DB in my application; this spreadsheet must remain private.
My application is executed as Gadget in Google Site, in this application a user runs the script as himself (not under the owner's identity).
I need that all users who access the application can get some data from the DB Spreadsheet.
How can users get this data, if the Spreadsheet is only accessible to me?
Can I use oAuth?
Sorry for the bad English
Following Zig answer and to illustrate, here is an example of such a contentService webapp, one can call it with this url either in a browser or in urlFetch
The app is deployed as follows : execute as me and anyone can access even anonymous
https://script.google.com/macros/s/AKfycbxfk5YR-JIlhv7HG9R7F-cPxmL0NZRzrdGF4VFGxGivBkYeZY4/exec?&user=chris&row=4&sheet=Sheet1
and here is the demo script
function doGet(e) {
if(e.parameter.user!='serge' && e.parameter.user!='chris' ){return ContentService.createTextOutput("logging error, you are not allowed to see this").setMimeType(ContentService.MimeType.TEXT)};
var sheet = e.parameter.sheet;
var row = Number(e.parameter.row);
Logger.log(sheet+' '+row);
var ss = SpreadsheetApp.openById("0AnqSFd3iikE3dENnemR2LVFMTFM5bDczNGhfSG11LVE");// this sheet is private but anyone can call this app
var sh = ss.getSheetByName(sheet);
var range = sh.getRange(row,1,1,sh.getLastColumn());
var val = Utilities.jsonStringify(range.getValues());
var result = ContentService.createTextOutput(val).setMimeType(ContentService.MimeType.JSON);
return result;
}
No you cant use oauth from the gadget as the user doesnt have read permission.
However you can publish a second script to extract needed data that runs as you with anonymous public access and call that one with urlfetch from the 1st. Slower thou.

How can I generate date-dependent passwords?

I'm looking for a simple way to generate passwords that will only work once for a limited amount of time, e.g. 1 day, 1 week, 1 month. This has to be implemented in an application that has no connectivity so a server isn't possible. The use case is something like:
1. Generate password for a specific date and length of time.
2. Send to user (email, phone, etc).
3. User enters in application.
4. Application is enabled for a specific time.
5. Password cannot be reused, even on another PC.
I'm assuming the only way to do this is to generate passwords that only work between a specific set of dates. Can anyone recommend an algorithm that can do this? It doesn't have to be incredibly secure, and I know you can crack this by resetting the time on the PC!
Thanks.
I know I'm late but I'll provide my advice anyway in case someone else who needs it found their way here.
To prevent it being used on another PC, you could probably use the MAC address or hardware address. However, this is subject to the network hardware being still available when checking the password. Please make sure you use the hardware address of the machine where the password will be checked.
private string GetBase64Mac()
{
System.Net.NetworkInformation.NetworkInterface[] interfaces = System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces();
if (interfaces.Length == 0)
{
System.Net.NetworkInformation.PhysicalAddress add = interfaces[0].GetPhysicalAddress();
if (add != null)
return System.Convert.ToBase64String(add.GetAddressBytes());
}
return "";
}
To limit it by some expiry date simply use the text string of the expiry date.
private string GetExpiryDate(DateTime expiryDate)
{
return expiryDate.ToString("yyyyMMdd");
}
Simply use a hash function to hash the combine expiry date, hardware address and a secret key. Prefix or suffix the hash output with the expiry date.
private void GeneratePassword(string prefix)
{
string secretKey = "MySecretKey";
System.Security.Cryptography.SHA1 sha = System.Security.Cryptography.SHA1.Create();
byte[] preHash = System.Text.Encoding.UTF32.GetBytes(prefix + secretKey + GetBase64Mac());
byte[] hash = sha.ComputeHash(preHash);
string password = prefix + System.Convert.ToBase64String(hash);
return password;
}
In the case above, i prefix the hash with the expiry date. So, when we check the password, we simply extract the expiry date from the password, use the same function to generate the same password. If the generated password match the provided password, then you have green light.
private void TestPassword()
{
int duration = 15; // in days
string prefix = GetExpiryDate(DateTime.Today.AddDays(duration));
string generated = GeneratePassword(prefix);
// Positive test
string testPrefix = generated.Substring(0, 8);
string testPassword = GeneratePassword(testPrefix);
if (generated != TestPassword)
return false;
// Negative test
generated[2] = '2';
generated[12] = 'b';
testPrefix = generated.Substring(0, 8);
testPassword = GeneratePassword(testPrefix);
if (generated != TestPassword)
return true;
return false;
}
Sample output password:
20110318k3X3GEDvP0LkBN6zCrkijIE+sNc=
If you can't get the hardware address, then simply use the customer's name. It won't prevent the password from being used in multiple machines, but it will ensure that the same person is using it.
Your application should have a attribute like validity for the password something like this
username password_hash validity_from Validity_end
xyz a73839$56 11-Nov-2010 12-Nov-2010
and then in your application you can validate that your password has expired or not
Generate passwords by any method you'd like (a word list, random letters, etc). Put them into some data structure, like an associative array, where you can associate a date with each password. Then you consult this data structure in the program that hands out passwords to give one out with the proper expiration date. The client program has the same list of passwords and dates, so when it gets a password, it just looks up the associated expiration date there.