Forum Discussion

nastester's avatar
nastester
Regular Contributor
8 months ago
Solved

Keyword test not working as Script test

I have Keyword tests which compare Excel workbook values to the frontend web application using the Excel Read Value and Compare Property operations. 

These Keyword tests work fine but when converting them to a script they do not and I get this error. Does anyone have any insight as to why?

 

Example script: 

//USEUNIT HelperScripts
function FR_Rollup()
{
  var Var1, LastResult, LastResult1;
  Var1 = "";
  
  changeDashboardLanguage("French");
  Browsers.CurrentBrowser.Navigate(ProjectSuite.Variables.url);
  
  Delay(500);
  
  LastResult = Excel.Open(ProjectSuite.Path + "Dashboard_translations_COMPLETE.xlsx").SheetByTitle["fr_FR"].CellByName["C37"].Value;
  Var1 = LastResult;
  aqObject.CompareProperty(Aliases.browser.pageDashboard.panelAllDispatchesStatusText.contentText, 0, Var1, true, 3);
  
  LastResult1 = Excel.Open(ProjectSuite.Path + "Dashboard_translations_COMPLETE.xlsx").SheetByTitle["fr_FR"].CellByName["C38"].Value;
  Var1 = LastResult;
  aqObject.CompareProperty(Aliases.browser.pageDashboard.panelUploadPendingStatusText.contentText, 0, Var1, true, 3);

}

 

  • Replace the square brackets with round brackets in your code, and it will work.

6 Replies

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    Here's code written in Python that works,

    You are trying to run your code in JavaScript, but your coding is actually in Python.

     

    If you look at the code examples in Excel.Open Method, Python uses square brackets, whereas JavaScript uses round brackets. This was a bug a while back, I wonder if it has been reintroduced!?

     

    • nastester's avatar
      nastester
      Regular Contributor

      Thanks for the insight.  Seems like a bug because my project is Javascript, not Python. 

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    Replace the square brackets with round brackets in your code, and it will work.

  • Marsha_R's avatar
    Marsha_R
    Champion Level 3

    "of undefined" in the error message is telling you that the function was unable to get your Excel sheet so it has no reference for the CellByName call.

     

    Did you use the Convert To Script function to get this code or did you write it separately? If you didn't use Convert To Script function, then I suggest trying that and seeing what code TestComplete gives you.

     

    If you did use that convert function, be sure and run this script in the spot in your test where it has access to all the variables that it needs. Running it stand alone may not work. 

    • nastester's avatar
      nastester
      Regular Contributor

      I did use convert to script.  The excel path is ProjectSuite.Path + *sheet name*.   I don't know why it would be accessible within the project via Keyword tests but not by Script tests. 

      • Marsha_R's avatar
        Marsha_R
        Champion Level 3
        Try putting the exact path in that line just to see if it's actually accessible.