Forum Discussion

Omsaigadge's avatar
Omsaigadge
Occasional Contributor
11 months ago

String comparison

I have a task of comparing 2 strings, one is the text which I am entering in the search bar, and the string which has to be compared with it is the result which I obtain. Is there any way to do it using keyword search? If not, is there a script code available for the task?

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    If you do an Internet search for "testcomplete string compare", you will get results pointing to the exact method required, in the TestComplete Documentation

    • Omsaigadge's avatar
      Omsaigadge
      Occasional Contributor

      I have tried them, but can I compare a search result to the user input? 

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    As an example, in your data driven testing, you should be using a variable to store the value of username i.e. expectedUsername.

    If you get the text from your UI control (Login Name), and store that into a variable, i.e.  actualUsername.

    You can then do something like this,

    function Test()
    {
        var expectedUsername = 'testgdpr2'; // Input
        var actualUsername = 'testgdpr2';   // UI control
        
        aqObject.CompareProperty(expectedUsername, cmpEqual, actualUsername, true);
        
        if (aqString.Compare(expectedUsername, actualUsername, true)) {
            Log.Error("Username is different");
        }
    }

    Using either CompareProperty or Compare methods. You should be able to do the same with keyword testing. Ensure you get the correct property value from your UI control, as it might be wText, contentText etc.

     

    • Omsaigadge's avatar
      Omsaigadge
      Occasional Contributor

      Yes, but this works only for the first iteration, what about the next usernames?
      How should I store the result in the expectedUsername for the second time?

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    I suggest you see Data-Driven Testing, to understand the concepts and to implement it in your existing scripts.

    The code example that I have provided, can be adapted to use data-driven testing.