Forum Discussion

JohnSnikers's avatar
JohnSnikers
Occasional Contributor
6 years ago

Runtime error on different pc while comparing two value

Hello,

 

I have a problem running TestComplete on different machines.

I want to compare two values, if they match.

Here is the code for it: 

var inspectedRate;
inspectedRate = Aliases.myApp.frmDealCheck.frmFX.frmFX1_B.frmFXSold.txtFXO_Amount.wText;
inspectedRate = aqString.Trim(aqConvert.VarToStr(inspectedRate));
var correctValue = 1938665;

if (aqConvert.VarToInt(inspectedRate) == aqConvert.VarToInt(correctValue))
{
      Log.Checkpoint("The value of FXRate is correct.");
}
else Log.Error("The value of FXRate is incorrect.");

If I run the function which contains this code, everything is fine, test runs successfully.

If my colleague runs it, everything is fine, test runs successfully.
BUT if I run it on a virtual machine or my other colleague on a laptop it gets:

"JavaScript runtime error. 
The argument cannot be converted." with error location pointing to the line where the 'if comparison' is.

I assume the problem is the inspectedRate variable, just don't know why and how to fix it.
Can someone please enlighten me how is that possible that the same TestProject runs differently on the same OS with the same Application with the same Resolution?
A detailed solution would be appreciated,

Thanks in advance

 

4 Replies

  • Marsha_R's avatar
    Marsha_R
    Champion Level 3

    Do all the machines have exactly the same version of TestComplete?  What version is it?

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi,

     

    Just to be on the safe side:

    While on the virtual machine, did you set breakpoint on the 'if' line and examined the value of the inspectedRate variable? (While inspecting, pay attention not only to the value of the variable, but also to the length of the value, as the value might contain invisible symbols like 0x0D, 0x0A, etc.)

    The reason for the problem on VM may be because VM is slower that physical PC and, for example, the txtFXO_Amount object may not exist yet when test code tries to get a reference to it.

     

    P.S. Log record like

    Log.Error("The value of FXRate is incorrect.");

    is great, but is it really useful? Why the value was reported as incorrect? What was the actual value and expected one? Why not to include this and other relevant information as a second parameter for the Log.Error() call? (Sometimes) this may give some clue to someone who will be given and will have to read this test log...

     

  • cunderw's avatar
    cunderw
    Community Hero

    My guess is that 

    Aliases.myApp.frmDealCheck.frmFX.frmFX1_B.frmFXSold.txtFXO_Amount

    is not being found properly on the VM. On the VM you find that object in the object browsers AND does you mapped object correlate with it?

  • shankar_r's avatar
    shankar_r
    Community Hero

    I had time hence spent some time on it.

     

    Run the below code then you will find is the issue.

    var inspectedRate;
    var obj = Aliases.myApp.frmDealCheck.frmFX.frmFX1_B.frmFXSold.txtFXO_Amount;
    if (obj.Exists) {
        inspectedRate = aqConvert.VarToStr(obj.wText);
        if (inspectedRate == "") {
            Log.Error("The value of FXRate is empty.");
            return;
        }
        inspectedRate = aqString.Trim(inspectedRate);
        try {
            inspectedRate = aqConvert.VarToInt(inspectedRate)
        } catch (e) {
            Log.Error("Actual FXRate is " + inspectedRate + " - " + e.stack);
            return;
        }
    
        var correctValue = 1938665;
    
        if (inspectedRate == correctValue) {
            Log.Checkpoint("The value of FXRate is correct.");
        } else {
            else Log.Error("The value of FXRate is incorrect.");
        }
    } else Log.Error("Object not found");