I'm trying to get the current date and time in Selenium IDE (latest version 3.7.4) in a format like this 2019-05-21 12:35:23 that is YYYY-MM-DD hh:mm:ss
I'm new to javascript and what I found so far is that in Javascript the current date is obtained from system using new Date();
So I've set the following commands in Selenium IDE
1)
Command: execute script
Target: new Date();
Value: currentdate
2)
Command: echo
Target: $(currentdate)
Value:
But it seems Date(); is not working and is not stored in variable currentdate. This is the output
executeScript on new Date(); with value currentdate OK
echo: undefined
'Untitled' completed successfully
What I'm doing wrong? Thanks for help in advance.
I stumbled across your question while looking for a way to do this myself. I found the answer elsewhere, so I thought I'd share it here in hopes of helping others.
You need to begin your JavaScript line with "return", like this:
return new Date();
This should place a verbose Date() value in your currentDate variable, which you can echo or use elsewhere. You'll probably want to format it using the toLocaleString() method, though, like this:
return new Date().toLocaleString();
That should return the date/time more closely formatted to your needs.
Related
I'm using the newrelic synthetics scripted browser to check some user transaction flows for reliability and performance.
However the tracked duration is only about 8-10s which matches initial page load time, but not the async lazy loading of a large dataset (which is approx. 40s).
How can I make new relic synthetics scripted browser tests to show actual test execution duration and not only the duration of inital request?
How can I track actual synthetics scripted browser test execution time and plot on a diagram with new relic?
The following I already tried and seems not to fix the issue:
Using a custom insight
See new relic docs for custom insights.
In script use:
var timeStart = Date.now();
var timeEnd = Date.now();
$util.insights.set('testDuration', (timeEnd - timeStart) );
with NRQL:
FROM SyntheticCheck SELECT numeric(custom.testDurration) WHERE numeric(custom.testDurration) > 0 SINCE 1 day ago
However in newrelic browser this data is shown as strings and thus cannot be plot on a chart as measurement.
What do I need to do to be able to make this a numeric measurement to be drawable as chart?
Timetracking with $har
New relic docs recommend using $har
const testTimer = $har.addResource('Test Timer');
testTimer.startTimer();
await sleep(100);
testTimer.endTimer();
However $har is resulting in error: Check failed with reference error. $har is not defined;
How do I use $har correctly?
** Checking KeySet, the custom properties show us stings**
As proposed on new relic forum I checked the field type and it appears to be registered as string
NRQL FROM SyntheticCheck SELECT keyset() returns
[
{
"results": [
{
"stringKeys": [
"custom.duration"
"custom.testDuration",
Any other ideas how to achieve this?
Thx in advance, I really appreciate your expertise!
You can log values with
$util.insights.set('testDuration', (timeEnd - timeStart) )
And when convert them within the query with
SELECT average(numeric(custom.testDuration)) FROM SyntheticCheck WHERE monitorName ='myMonitor' SINCE 7 days AGO TIMESERIES AUTO
However you cannot report this within the synthetics monitor and always need the query builder or a custom dashboard for analysis.
Would rather prefer a solution which properly reports within the synthetics monitor.
The below code in returning 5 hours ago, when i just create a record
formatDate(date) {
return moment(date).fromNow();
},
I've faced a similar issue, but in my case, it was -3 because of my time zone.
If your trying to parse a DB datetime, try with below code, it worked for me
formatDate(date) {
return moment.utc(date)
}
It should return the datetime as it is in your DB
You can also return a formatted datetime
formatDate(date) {
return moment.utc(date).format('DD/MM/YYYY')
}
It is probably a problem with default timezone setting which may have been set to an undesired value in a different module or your app.
If you are on Node.js or in a browser, overwrite the default timezone by specifying it directly in the moment call: moment(date).tz("America/Los_Angeles").fromNow(); Make sure that you are using moment-timezone library (see here).
If you are on Node.js, you can try setting default timezone of Node.js (see here).
I have tried to get the property value, where I have saved in the project-properties.
This is the code which I have tried out.log.info wasn't working fine ,but when I run the code separately(that means only first line..), It shows the valid answer in a popup.
def ProjectProp = testRunner.testCase.testSuite.project.getPropertyValue("Name")
log.info {"Project Property = "+ProjectProp}
I am new to SoapUI.I would be really grateful, If you will be able to help me out to find a solution for the error which i received as follows,
INFO:Script13$_run_closure1#1d32637
Your problem is unrelated to SoapUI. You obviously have difficulty with basic Groovy syntax. Seek some tutorial on Groovy.
Your specific case, should read:
def projectProp = testRunner.testCase.testSuite.project.getPropertyValue("Name")
log.info("Project Property = " + $projectProp)
I'm trying to run this query at MongoLab but get the error as shown in the attached image:
var lastWeek = new Date();
lastWeek.setDate(lastWeek.getDate() -7);
db.messages.find({ "rep_header.share_date_2.$date": {$gte: lastWeek}});
What I'm missing here? Where those quotes goes to?
The MongoLab UI only accepts strict JSON queries (no scripting, in other words). If you need to dynamically generate the value for lastWeek, you'll need to run that script in the mongo shell.
1) Earlier this week I was able to create defects and testcases using the Create method, which took 2 arguments at the time (a string and the DynamicJsonObject). However now, it needs three. I understand that one of these is now the workspace reference. How do I go about getting the workspace reference? For creating defects and testcases, I am using an empty string, and this seems to be working correctly for me. Is this to be expected?
2) For creating test case results, I am having a bit of trouble.
DynamicJsonObject newTCResult = new DynamicJsonObject();
newTCResult["Date"] = DateTime.Now.ToString("yyyyMMdd");
newTCResult["TestCase"] = "/testcase/11271454106";
newTCResult["Notes"] = "test";
newTCResult["Build"] = "13.1.0.90";
newTCResult["Verdict"] = "Pass";
CreateResult cr = restApi.Create(" ", "TestCaseResult", newTCResult);
As of right now, absolutely nothing is happening when I run this. I was able to do this successfully earlier this week (when I was able to use the Create method with two arguments). I feel that the problem is because I don't have a valid workspace reference. I followed the suggestion of another user in a similar question prior to this which worked for earlier, however now I am having this problem.
I was finally able to resolve this. It appears that the date field needs to be converted to UTC, so my code now looks something like this
newTCResult["Date"] = DateTime.UtcNow.ToString("o");
After making that small change results were working correctly.
It's somewhat surprising that Creates on Stories or Defects work with an empty string for a Workspace ref, although I suspect that on the server-side, the Webservices API is just using Default Workspace for the User of concern.
Either way, here's how you can get a ref to the Workspace of interest:
String myWorkspaceName = "My Workspace";
// Get a Reference to Target Workspace
Request workspaceRequest = new Request("workspace");
workspaceRequest.Fetch = new List<string>()
{
"Name",
"ObjectID"
};
workspaceRequest.Query = new Query("Name", Query.Operator.Equals, myWorkspaceName);
QueryResult workspaceQueryResults = restApi.Query(workspaceRequest);
var targetWorkspace = workspaceQueryResults.Results.First();
Console.WriteLine("Found Target Workspace: " + targetWorkspace["Name"]);
String workspaceRef = targetWorkspace["_ref"];
You can then use workspaceRef in your call to restApi.Create().