Forum Discussion

joscva's avatar
joscva
Contributor
24 days ago
Solved

Desktop app keyword test, extract alphanum, edit and convert to number for later use?

I'm currently evaluating TestComplete and am trying to do a few relatively simple-seeming things, but I'm stuck on this one.  I'm not a developer so coding this from scratch is a non-starter at this stage, I need to be able to use the GUI functionality of TestComplete to accomplish this task.

I'm going to need to extract a number from our Desktop app, to use in a later step of the app.  However, the value I need is a monetary value and also contains a currency label (USD, in this case).

I can get the object in question, but have not been able to figure out how to trim off the currency label.  The value is in the format "##,###.## USD" (no quotes, of course).

I can't find any string manipulation functions within the GUI of TestComplete.  Is what I need to do even possible, or is there no option but to get a developer to do this?  Part of the reason I'm looking at TestComplete in the first place, is because developer resources are limited and I was hoping that we in QA could create these tests on our own.

Again in case it's not already clear, here are the steps I need to accomplish:

  • Identify object on screen
  • Extract alphanumeric value
  • Trim off the alpha portion
  • Store this result as a number that I can use to perform simple math calculations on later

 

  • It is common for new user and advanced user to have severe miss understanding discussing technicalities. Does it mean your problem is solved and this can be marked as solution?

    The following project includes a script with two samples for you to run and inspect the how to accomplish, expand the log to see the run details. It uses most of your provided details and catered to different variations and also the max currency length upper limits, extract and open the "ConvertStringToNumber.mds" file. 

  • JDR2500's avatar
    JDR2500
    Frequent Contributor

    You should be able to accomplish what you're describing in a Keyword test without having to create a script by using the "Run Code Snippet" action with the aqConvert and aqString methods.

    Assuming you already have a variable with the string containing the currency label that would look something like this:

    In the above example aqString.Replace replaces the " USD" with "".  That leaves only the number portion.  At that point aqConvert.StrToInt converts the string to an integer.  Obviously, you'll need to substitute your variables in the right places above.

    Relecant help topics:
    aqConvert.StrToInt Method | TestComplete Documentation
    aqString.Replace Method | TestComplete Documentation

    Caution:  I haven't done any keyword testing in years.  I also haven't tested the above approach.  However, I think it should get you close to what you want.

  • Anonymous's avatar
    Anonymous

    EDITED 

    See my second post sent later in the day. In that post there is a video showing you how to create the exact test you are trying to create

    -----

    This is the way I would do this: 

    Firstly, when searching/googling for how to do steps 1 and 2, you would type the following (these are actually 1 step) 'testcomplete, how to extract text from app'. 

    1. google 'testComplete, how to extract text from app'. This will lead you to the following page:
      usually test complete is great when it comes to documentation. You can easily find what you need by typing 'TestComplete <your question here>'. However, i had trouble this time finding the video. I did eventually find it. The following video shows how to grab text from your app and then store it in a variable (this works the same for desktop and web apps).
      https://www.youtube.com/watch?v=l3F52-Z9DOE 

    2. Then you will want to do as rraghvani said and create a javascript function to extract the number from the text. ChatGPT will be your go to for writing javascript functions. You don't need to know much about programming to create a javascript function when you use ChatGPT and ChatGPT will help you learn basics about programming as you use it because it also explains in detail the code that it returns. 
      I typed into chatGPT:
      "Hi Chat, I need a javascript function that will take in an alphanumeric string and pass back the numeric part of the string." OR better ...
      "Hi Chat, I need a javascript function that will take in an alphanumeric string and pass back the numeric part of the string as a number (a float/double).  The value is in the format "##,###.## USD" (no quotes, of course)".
      Copy the answer (the javascript function) ChatGPT gives you into a script file in TestComplete. I put the code below. It is a good idea to start learning how to use ChatGPT.


    3. Add the javascript object you created in step 2 to your keyword test you started in step 1. Watch the following video (not ideal video but good enough):
      https://www.youtube.com/watch?v=z0VuGO4mVBw

     

    function extractFloatValue(inputString) {
        // Use a regular expression to match the numeric part of the string
        const match = inputString.match(/[\d,]+\.\d+/);
        if (match) {
            // Remove commas and convert the matched numeric part to a floating-point number
            return parseFloat(match[0].replace(/,/g, ''));
        }
        // Return null if no numeric part is found
        return null;
    }

     

    • joscva's avatar
      joscva
      Contributor

      Thanks for the video, I did tons of googling and scouring of the docs and forums, but never found this particular video.  I'll have a look at it.  As for using Javascript to do the string manipulation, I guess if that's the only way then that's what I'll have to do... I was just really hoping to keep this all GUI/Nocode.  But I suppose the occasional helper function like this is acceptable.  This is about my skill level with coding and a you rightly pointed out, we have LLMs now to handle this and much more as needed (I've found Claude to be superior for coding tasks btw, though I haven't tried ChatGPT for any in the last couple of months).

      Thanks again!

      • joscva's avatar
        joscva
        Contributor

        So I went through the video, and it really just gave me an additional way to do what I had already managed to do, and I'm in exactly the same spot.  I have no way to tell that the value I captured has in fact been captured and can be used.  This is not a web app, it has no fields I can insert the value into as shown in the video.  I've been trying to just use Push Indicator Text to display the value from the variable, but it always appears to be empty.  I don't know what I'm missing here.

        What are some quick and reliable ways to validate the content of a variable?  I was hoping there was just a page within TC that would show in realtime as things are happening, what data is in what location, but if there is such a place I haven't managed to find it.

  • Anonymous's avatar
    Anonymous

    During initial reply, I didn't have time to make a video and TC is usually pretty good about having videos showing how to do whatever you want to learn. However, surprised to see they didn't have a video for this. Not sure why.

    Here is a detailed video showing how to do exactly what you are trying to do using TestComplete. As far as I know these are the only options available in TestComplete.  
    https://youtu.be/UU4UCJOlRGk 

    • joscva's avatar
      joscva
      Contributor

      I've already done essentially what's in that video (just not with a string in notepad), but in my case the name mapping doesn't work properly.  I have a strong suspicion this is due to our application doing something with the identity of the object in question, that TC isn't handling.  At this stage I'm going to need to talk to the developers and see if they can explain what's going on internally that is causing problems.

      • Anonymous's avatar
        Anonymous

        Okay, go talk to a developer. No one who has offered you help and support on this page works for SmartBear. We are users of TestComplete who support our community on our own free time. 

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    joscva how familiar are you with TestComplete?

    Without knowing the basics, it's going to be difficult to use TestComplete. I suggest you go through the appropriate tutorials shown in https://support.smartbear.com/testcomplete/docs/index.html to get a better understanding. Then decide whether you want to use JavaScript of Keyword Testing, but if you don't have any coding skills, then I suggest to use Keyword Testing - refer to the documentation on how to use this.

  • Hassan_Ballan's avatar
    Hassan_Ballan
    Regular Contributor

    To handle automation some basic coding experience helps you go further and for sure you have learning curve.

    To summarize all the feed back you can do it in the following easy steps:

    1. create two persistent variables of type string and integer on the project level

    2. add to your keywordtests script the operations "set variable" and the value is the object contenttext, and "run code snippet" with below code

    3. customize the code to your environment
    Project.Variables.VarInteger = aqConvert.StrToInt(aqString.Replace(Project.Variables.VarString, "Posts", ""))

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    Here's a simple example using Keyword Test, which extracts the contentText value of "$12.50 USD" and stores this into a string variable called StrValue. The first Log.Message outputs the string value of StrValue, and the next Log.Message, using regular expression against StrValue, outputs the actual value.

    You can apply the same principles with your application.

    Just to emphasise, it's vital that you learn the basics of TestComplete, otherwise it's going to be tricky to understand all responses, from the group forum that are helping you.