I am working on selenium with c#.In a test script I need to reset outstanding balance of account in database and then do purchase transaction through UI and see the final balance showing on UI is decreased.
I ran update linq query and in the next steps I had written code to purchase product and checkout. This test case is passing in debug mode but failing in run mode. The final balance is not reducing when running the test case and it is reducing when debugging the test case. What is the issue.
You can set a standard wait time, but you may find you're waiting way too long, making your tests slooooow, or your test will fail if your server has a slow down.
Try a loop to check if the update has been made:
var iterationCount = 10;
var iterationWaitTime = 250;
var hasChanged = false;
var currentValue = /*get current value*/;
var i = 0;
while (!hasChanged && i++ < iterationCount)
{
var newValue = /*get new value*/;
hasChanged = object.Equals(currentValue, newValue);
currentValue = newValue;
}
Assert.IsTrue(!hasChanged && i++ < iterationCount, "No update detected");
/* do test on currentValue here */
(P.S. This is freehand so may not be perfectly correct)
Related
The Email collection function built into the form is in the Text format. We have a lot of employees filling out this form, so it would be more convenient to choose from a drop-down list than to manually enter an email for each employee. The built-in function of collecting emails does not allow using the Dropdown list question type, so I had to disable it and send the response to the email using a script.
In addition, when you select one of the options (Transfer) in the form, you need to insert an additional correction row with data. This is also done by the script.
The script works fine, but unfortunately, its execution time reaches 45 seconds. I think this is abnormally large.
Updated code:
var FORM_ID = '#####';
var SHEET_NAME = 'Operations';
function sendFormToEmail() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
console.time('section10'); // 25579ms
var sheet = ss.getSheetByName(SHEET_NAME);
console.timeEnd('section10');
// Open a form by ID and log the responses to each question.
var form = FormApp.openById(FORM_ID);
var formResponses = form.getResponses();
var i = formResponses.length - 1;
var formResponse = formResponses[i]; // Last item
var itemResponses = formResponse.getItemResponses();
var length = itemResponses.length;
Logger.log("length = " + length);
var emailTo = itemResponses[0].getResponse(); // Returns the email if given
var cp = itemResponses[1].getResponse(); // Counterparty
var subject = "Input form: "+ cp;
var datePay = itemResponses[2].getResponse(); // Date of the operation
var dateAccept = itemResponses[3].getResponse(); // Date of acceptance
var sum = itemResponses[4].getResponse() ; // Amount
var what = itemResponses[5].getResponse(); // Operation type
var comm = "Correction " + itemResponses[length - 1].getResponse(); // Last response
var sum_1 = parseFloat(sum.replace(/,/, '.')) * (-1); // Amount * (-1)
var timestamp = new Date();
var textBody = "Operation: " + timestamp + ";\n";
for (var j = 0; j < itemResponses.length; j++) {
var itemResponse = itemResponses[j];
var resp = itemResponse.getResponse();
textBody += itemResponse.getItem().getTitle() + "=" + resp + ";\n";
}
if (what == 'Transfer') { // If the transfer between your accounts
var lr = sheet.getLastRow();
sheet.insertRowBefore(lr);
var values = [datePay, dateAccept, "", sum_1, "", "", "", "", comm, "", "", "", what, timestamp, "", "", ""];
Logger.log(values);
console.time('section12'); // 19449ms
sheet.getRange(lr, 2, 1, 17).setValues([values]);
console.timeEnd('section12')
}
if(emailTo !== undefined){
GmailApp.sendEmail(emailTo, subject, textBody);
}
}
At first I thought it was the large size of the acceptance sheet (about 13 thousand rows). I created a copy of the table, reduced it to several dozen rows, but the speed did not increase much.
Then I deleted the answers from the form (there were just under 9000 of them) - the same thing, I didn't get much performance gain.
Anyone have any ideas how to change the script algorithm to improve its performance?
===
Conclusions
Thanks to #TheMaster for the help with console.time(). Thanks to this tool I found bottlenecks in the code. More precisely, the code works well, but it's about the structure of the spreadsheets system with which the code interacts. The structure needs to be optimized.
There was also an idea addressed, probably, to Google developers. It would be great if there was a tool that visually (graphically) displays the relationships between spreadsheets and sheets that make up a single system. Perhaps with some kind of numerical characteristics that reflect, for example, the interaction time between its blocks. This would make it possible to quickly eliminate such bottlenecks in the system and improve it.
Investigation:
Pinpointing the issue is done using console.time() and console.timeEnd() of each section of code and calculating the time taken by reachl each section of code.
Issue:
As discussed in the question comment chain, This is due to a bloated spreadsheet with many sheets and import formulas. This caused more time to get the exact sheet and to use setValues:
console.time('section10'); // 25579ms
var sheet = ss.getSheetByName(SHEET_NAME);
console.timeEnd('section10');
//....
console.time('section12'); // 19449ms
sheet.getRange(lr, 2, 1, 17).setValues([values]);
console.timeEnd('section12')
Possible solutions:
Reduce number of sheets
Reduce interconnected spreadsheets (=import* formulas)
Delete empty rows on the bottom and empty columns on the right of each sheet.
I need to transfer ownership of thousands of files I own to someone else with editing access, but I've learned that Google Drive requires you to do this one file at a time. With intermediate but growing JS experience I decided to write a script to change the owner from a list of file IDs in a spreadsheet, however I've run into trouble and I have no idea why. The debugger just runs through the script and everything looks sound for me. I'd greatly appreciate any help.
function changeOwner() {
var ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/********/').getSheetByName('Sheet1');
var range = ss.getRange(1,1,2211);
for (i = 0; i < range.length; i++){
var file = range[i][0].getValue();
var fileid = DriveApp.getFileById(file);
fileid.setOwner('******#gmail.com');
}
}
Tested below code working fine with IDs,
function myFunction() {
var spreadsheet = SpreadsheetApp.openById('ID');
var range = spreadsheet.getDataRange().getValues();
for (i = 0; i < range.length; i++){
var file = range[i][0].toString();
var fileid = DriveApp.getFileById(file);
fileid.setOwner('***#gmail.com');
}
}
Your issue is that the Range class had no length property. Instead, perform a getValues() call on the range to efficiently create a JavaScript array, and iterate on it:
function changeOwner() {
var ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/********/').getSheetByName('Sheet1');
var values = ss.getRange(1, 1, 2211).getValues();
for (i = 0; i < values.length; ++i){
var fileid = value[i][0];
var file = DriveApp.getFileById(fileid);
file.setOwner('******#gmail.com');
}
}
There are other improvements you can make, such as:
dynamic range read (rather than the fixed assumption of 2211 rows of data)
writing to a second array to keep track of which files you have yet to process
checks for if the file exists
checks for if the file is actually owned by you
checks for execution time remaining, to allow serializing any updates/tracking you do that prevents the next execution from repeating what you just did
and so on. I'll let you research those topics, and the methods available in Apps Script documentation for the DriveApp, SpreadsheetApp, Sheet, and Range classes. Note that you also have all features of Javascript 1.6 available, so many of the things you find on a Javascript Developer Reference (like MDN) are also available to you.
I want to implement an afl code to find Daily Loss Limit in intraday trading. I will use the code for backtesting around 200 days.
I have the following code but it is with mistakes.
// identify new day
dn = DateNum();
newDay = dn != Ref( dn,-1);
// Daily Loss Limit
dll = Optimize("dll", 0, 5, 10000, 5 );
EquityCount = 10000;
for( i = 0; i < BarCount; i++ )
{
// signals
Buy = ....;
Sell = ....;
diff = (Equity(1) - Ref(Equity(1), -1));
EquityCount = EquityCount + diff;
// allow only dll
Buy = Buy AND EquityCount > dll;
}
Any help will be appreciated.
Thanks.
First your code is completely wrong.
Secondly Equity() function is single security function. It is obsolete.
Use custom backtest interface of AmiBroker instead. See AmiBroker help.
I'm struggling on how I can put this into code.
int a=500;
By default x = a-100
I am trying to find a way where when one button is clicked, it sets the x-coordinate to x=a-100 , and then when the same button is pressed again, it sets x=0.
How would i logically put this into code?
Thanks a lot!
Somewhere, have a variable keep track of whether or not the button has been previously pressed. Since you haven't indicated what language you're using, I'll have to make this very generic, and assume the typical interface that's used to handle button press events.
var button = (some GUI button object);
var a = 500;
var x = 2;
var buttonHasBeenPressed = false;
button.onPress = function() {
if (buttonHasBeenPressed) {
x = 0;
} else {
x = a - 100;
}
buttonHasBeenPressed = true;
};
Where you store the flag (buttonHasBeenPressed) depends on your skill level, the size of your program and many other factors. This is just a rough example using pseudo-javascript.
Is there an event that describes when Ace Editor has finished syntax highlighting it's contents?
What I'm doing now is timing how long it takes to run this call:
var theBeforeTimes = getTimer();
var aceEditor = ace.edit("myEditor");
//setAllOptionsOn(aceEditor);
//aceEditor.addListener("everythingsDone", doneHandler);
aceEditor.setValue(myCode);
console.log(getTimer()-theBeforeTimes);
I'm trying different options and I want to test the performance in each mode. What I mean is, I want to time how long it takes to render without any extensions running and time how long it takes with ALL extensions running. That way if it is slow I can tell or show the user how long it is with and without their selected extensions.
Rendering is done from requestAnimationFrame callback, it's not affected much by extensions.
Tokenization is separate from rendering and is done from timeout at https://github.com/ajaxorg/ace/blob/v1.2.0/lib/ace/background_tokenizer.js#L64
if you want to measure how fast a mode can tokenize whole document use
function measure(editor) {
var session = editor.session;
// reset cache
session.bgTokenizer.lines.length = session.bgTokenizer.states.length = 0
var l = session.getLength()
var t=performance.now()
for (var i = 0; i < l; i++) session.getTokens(i)
return performance.now()-t
}
measure(editor)