Forum Discussion

Iso_Yura's avatar
Iso_Yura
Contributor
11 months ago
Solved

Using local variable in Script Routine.

Hello all,

 

In my keyword test I use Run Script Routine. The script should click on the QT button, the value of the button stored in the csv file under "TC_Organism_button" column. I'm trying to parametrize the script routine that when I want to click different button I need to change the value of the button only in csv file not in test.

In script routine I have variable which uses local keyword variable as a value:

 

# Get the CSV file path from the 'test_variable' keyword test variable
csv_path = KeywordTests.CurrentTestItems.Variables['test_variable']

# Call the function to click the button using the object path from the first row of the CSV file
click_organism_from_csv(csv_path)

 

Then in script routine as a parameter I specify the column as a value - "TC_Organism_button".

 

Then when I'm running the script routine I get the error:

 

What does this error mean and how to fix it? 

5 Replies

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    Is this the same issue as https://community.smartbear.com/t5/TestComplete-Questions/Test-execution-fails-after-I-modified-variable-of-a-ClickButton/td-p/251645 ?

     

    You need to use the eval() function to evaluate the JavaScript code represented as a string

     

    In your CSV file, how have you defined the actual button name?

     

    You have defined the following,

    which doesn't match with the code you have written

    and your comment "# Get the CSV file path from the 'test_variable' keyword test variable" doesn't match which what you are trying to do - which is confusing

     

    • Iso_Yura's avatar
      Iso_Yura
      Contributor

      No this is different issue. 

      In the issue from link I wasn't able to click a button. That issue I figured out.

      But I was using hard coded path to csv file, now I want to replace hard coded value to a local variable, which is:

      csv_path = KeywordTests.CurrentTestItems.Variables['test_variable']

       

      After I replaced I got the error. 

      For me it looks like it doesn't recognize 'KeywordTests.CurrentTestItems.Variables['test_variable']' as a keyword test variable, but I can be wrong. 

       

      As I mentioned above on screenshot I use a parameter for my script routine, maybe I did mistake there. 

      This is my first time I'm trying parametrize script routine. 

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    In your code,

     

     

    # Get the CSV file path from the 'test_variable' keyword test variable
    csv_path = KeywordTests.CurrentTestItems.Variables['test_variable']
    
    # Call the function to click the button using the object path from the first row of the CSV file
    click_organism_from_csv(csv_path)

     

     

    Can you tell me what the actual value is, of csv_path?

    Can you tell me what this does, click_organism_from_csv(csv_path)?

    Can you upload your csv file?

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    When you say "hard coded path to csv file", it implies you are doing something like this,

    csv_path = "C:\\Temp\\MyFile.csv"

     

    I don't understand what value this is supposed to be,

    KeywordTests.CurrentTestItems.Variables['test_variable']

     

    I suggest you read Using Variables, and try to understand how to use them in TestComplete.

    • Iso_Yura's avatar
      Iso_Yura
      Contributor

      Yes, hard coded is a path to the file. In my case file path can be different and it will cause an error, so I want to use keyword variable instead of file path.

       

      'KeywordTests.CurrentTestItems.Variables['test_variable']' is a keyword test variable:

       

       Which I'm using as parameter in for my script routine: