How to concatenate timestamp in a value
Home › Forums › Ask Expert › How to concatenate timestamp in a value
- This topic has 15 replies, 3 voices, and was last updated 5 years, 10 months ago by
Valentin ZAP.
-
AuthorPosts
-
April 15, 2019 at 2:40 pm #32272
MICHEL BELANGER
Participantif I need to have a different email each time I run the test
const timestamp = now.getTime();
ex. “michel.belanger+” + Datatable.Value(timestamp)April 15, 2019 at 3:20 pm #32276Kirill Bulatnikov
ParticipantHey Michel
I am not clearly understand what you are trying to do.
Do you need to modify date/time that written to the const (or variable)?
What do you mean by “need to have a different email each time I run the test”?Thanks.
Kirill,
ZAPTEST Team.April 15, 2019 at 3:56 pm #32277MICHEL BELANGER
ParticipantI have to create more than one user, but I can not create 2 times the same so I have to have a unique email by creation (each run)
That’s why I need to concatenate time stamp + nameSorry for Constant I mean Variable
April 29, 2019 at 8:49 pm #32295MICHEL BELANGER
ParticipantAny advices!?
April 29, 2019 at 8:56 pm #32296Valentin ZAP
KeymasterHello Michail!
What kind of language do you use? For VBScript you could use the following consts:
Now = 2/29/2016 1:02:03 PM
Date = 2/29/2016
Time = 1:02:03 PM
Timer = 78826.31 ' seconds since midnightFormatDateTime(Now) = 2/29/2016 1:02:03 PM
FormatDateTime(Now, vbGeneralDate) = 2/29/2016 1:02:03 PM
FormatDateTime(Now, vbLongDate) = Monday, February 29, 2016
FormatDateTime(Now, vbShortDate) = 2/29/2016
FormatDateTime(Now, vbLongTime) = 1:02:03 PM
FormatDateTime(Now, vbShortTime) = 13:02Year(Now) = 2016
Month(Now) = 2
Day(Now) = 29
Hour(Now) = 13
Minute(Now) = 2
Second(Now) = 3Year(Date) = 2016
Month(Date) = 2
Day(Date) = 29Hour(Time) = 13
Minute(Time) = 2
Second(Time) = 3
So, you could use in the script in this way:
msgbox Timer
msgbox FormatDateTime(Now, vbShortDate)
Hope, it helps. Let us know if you still have any questions.
Thank you,
ZAPTEST TeamApril 29, 2019 at 9:16 pm #32297MICHEL BELANGER
ParticipantI try do this in Javascript
var timestamp = now.getTime();
Application(“Hop”).View(“View”).Object(“Email”).Type(“michel.belanger+” + Datatable.Value(timestamp));
but I have this error
April 29, 2019 at 9:16 pm #32298MICHEL BELANGER
Participanthow to delete a duplicate reply?
April 29, 2019 at 9:23 pm #32299Valentin ZAP
KeymasterHello Michel!
You have to initialize ‘now’ variable before using:
var now = new Date();
var timestamp = now.getTime();
alert(timestamp);
Keep in mind, that next line refers to the datatable and could be a potential logic error: “Datatable.Value(timestamp)”, because “timestamp” depends on time and you could not have such column.
Let us know if you still have questions.
Thank you,
ZAPTEST TeamApril 29, 2019 at 9:49 pm #32300MICHEL BELANGER
ParticipantOK great for the step 1… (its not like yyyyMMddhhmmss but I can work with that, I juste need a unique identifier for now)
var now = new Date();
var timestamp = now.getTime();
var email = “michel.belanger+” + timestamp+”@optelgroup.com”;
Application(“Hop”).View(“View”).Object(“Email”).Type(email);But now step 2:
I need to use as a parameterStep 3:
I need to set a diferente email for each device in the m-runexample… In my case of sign up a new user, I can create the same email(user) to test same scenario on 2 devices:
so I need something like this:
device A
should sign up with [email protected]
device B
should sign up with [email protected]But I have no idea how to do that
April 29, 2019 at 10:28 pm #32301Valentin ZAP
KeymasterHello Michel!
A JavaScript Date has several methods allowing you to extract its parts:
getFullYear() - Returns the 4-digit year
getMonth() - Returns a zero-based integer (0-11) representing the month of the year.
getDate() - Returns the day of the month (1-31).
getDay() - Returns the day of the week (0-6). 0 is Sunday, 6 is Saturday.
getHours() - Returns the hour of the day (0-23).
getMinutes() - Returns the minute (0-59).
getSeconds() - Returns the second (0-59).
getMilliseconds() - Returns the milliseconds (0-999).
getTimezoneOffset() - Returns the number of minutes between the machine local time and UTC.// Example
var now = new Date();
var date = now.getYear() + "." + now.getMonth();
alert(date); // 2019.3
Probably for random number generation you better could use:
var rand = Math.floor(Math.random() * 100001);
alert(rand);
STEP 2:
What exactly would you like to parametrize? Probably if you parametrize your e-mail you could add “random / timestamp” at the beginning:
var somethingToType = timestamp + Datatable.Value("email");
Having an enterprise edition you could write a function which can insert this timestamp before symbol “@”, in the Free Edition you could split your domain:
var somethingToType = Datatable.Value("email_user") + timestamp + Datatable.Value("email_domain");
STEP 3:
Generating an email, you could assign it to the variable or datatable item (per iteration), which will be the same value per iteration and per device. If you would like to share your e-mail cross instances (cross-devices) you should use pseudorandom logic (to have the same number generation for each device) or global variables which is available only in Enterprise Edition of ZAPTEST.
Let us know if you have any questions.
Thank you,
ZAPTEST TeamApril 29, 2019 at 10:42 pm #32302MICHEL BELANGER
ParticipantSo Great!
For step 3 could you be more specific so that I can succeed by giving me the steps I need to do to have a different email in cross-devices. I think that to get to do that I do not need to have the enterprise version, so let’s start with that … Otherwise I am currently in a trial period with Enterprise.April 29, 2019 at 11:24 pm #32303Valentin ZAP
KeymasterHello Michel!
It could be:
1. Pseudorandom suffix or prefix which depends on iteration/date/time. Problem is when you execute script very often -> it’s had to renew such prefix because it depends on something. As an alternative solution, it could be a clipboard (but it will work only with a single iteration). So this part requires some experiments.
2. “Global Variable” which depends on Iteration.
// ##### This code demonstrates some ideas only #####// Device A
Zap.SetGlobalVar(Zap.Iteration + "_iter_email", "");var name = "zap";
var domain = "domain.com";
var timestamp = "_12345";
var email = name + timestamp + "@" + domain;alert(email);
Zap.SetGlobalVar(Zap.Iteration + "_iter_email", email);
// Device B
// on all other devices we need some sync method, usually we should wait for some extern event (page view updated / etc)wait(5);
var currentEmail = "";
do {
currentEmail = Zap.GetGlobalVar(Zap.Iteration + "_iter_email");
if (currentEmail == "") {
wait(0, 500);
}
} while (currentEmail == "")alert(currentEmail);
April 29, 2019 at 11:57 pm #32304MICHEL BELANGER
ParticipantI do not think that’s what I need (Iteration)
see in screenshot the emails are the same…
maybe I miss something 🙁Do you have a Zap.DeviceName rather than a Zap.Iteration, because it would work fine in this way.
April 30, 2019 at 12:15 am #32305Valentin ZAP
KeymasterHello Michel!
Yes, you could use prepopulated M-RUN local variable (per M-RUN execution) which returns you the name of the conneciton (tab name):
var connectionName = Zap.GetLocalVar("connection_name");
Application("Application").CustomReport(true, "name", connectionName);
Zap.GetLocalVar method is only available in Enterprise Edition and has other variables: “device_id”, “device_platform”, “device_os_version”.
Thank you,
ZAPTEST TeamApril 30, 2019 at 2:00 am #32306MICHEL BELANGER
Participantit work like a charm, well done, voila, Merci !
I use “device_id” -
AuthorPosts
- You must be logged in to reply to this topic.