How to concatenate timestamp in a value

How to concatenate timestamp in a value

Home Forums Ask Expert How to concatenate timestamp in a value

Viewing 15 posts - 1 through 15 (of 16 total)
  • Author
    Posts
  • #32272
    MICHEL BELANGER
    Participant

      if I need to have a different email each time I run the test
      const timestamp = now.getTime();
      ex. “michel.belanger+” + Datatable.Value(timestamp)

      #32276
      Kirill Bulatnikov
      Participant

        Hey 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.

        #32277
        MICHEL BELANGER
        Participant

          I 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 + name

          Sorry for Constant I mean Variable

          #32295
          MICHEL BELANGER
          Participant

            Any advices!?

            #32296
            Valentin ZAP
            Keymaster

              Hello 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 midnight

              FormatDateTime(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:02

              Year(Now) = 2016
              Month(Now) = 2
              Day(Now) = 29
              Hour(Now) = 13
              Minute(Now) = 2
              Second(Now) = 3

              Year(Date) = 2016
              Month(Date) = 2
              Day(Date) = 29

              Hour(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 Team

              #32297
              MICHEL BELANGER
              Participant

                I 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
                Annotation2019-04-29132357.png

                #32298
                MICHEL BELANGER
                Participant

                  how to delete a duplicate reply?

                  #32299
                  Valentin ZAP
                  Keymaster

                    Hello 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 Team

                    #32300
                    MICHEL BELANGER
                    Participant

                      OK 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 parameter

                      Step 3:
                      I need to set a diferente email for each device in the m-run

                      example… 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

                      #32301
                      Valentin ZAP
                      Keymaster

                        Hello 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 Team

                        #32302
                        MICHEL BELANGER
                        Participant

                          So 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.

                          #32303
                          Valentin ZAP
                          Keymaster

                            Hello 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);

                            #32304
                            MICHEL BELANGER
                            Participant

                              I do not think that’s what I need (Iteration)
                              see in screenshot the emails are the same…
                              Annotation2019-04-29154842.png
                              maybe I miss something 🙁

                              Do you have a Zap.DeviceName rather than a Zap.Iteration, because it would work fine in this way.

                              #32305
                              Valentin ZAP
                              Keymaster

                                Hello 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 Team

                                #32306
                                MICHEL BELANGER
                                Participant

                                  it work like a charm, well done, voila, Merci !
                                  I use “device_id”

                                Viewing 15 posts - 1 through 15 (of 16 total)
                                • You must be logged in to reply to this topic.

                                Virtual Expert

                                ZAPTEST

                                ZAPTEST Logo