Forum Discussion

simhadrx's avatar
simhadrx
New Contributor
2 years ago

Python Arrays

In TestComplete, I am using JavaClasses to access some of the java methods from a generic library for our tests. Parameters for one of the java method is to pass a string array. May I know how could I declare a string array in python? I see we can achieve it by numPy but may I know the process of how to install numpy, and the version that supports python smartbear.Please find the code below:
a = ["one', "two", "three", "four"]
Log.Message(str(a))
When I pass this Str(a) to the JavaClasses as a string array, It is throwing an error "COMException: Type mismatch"

Is there any other way to declare a string array in python test complete version 14.90 and pass it to java classes?

6 Replies

  • MarkHays's avatar
    MarkHays
    Occasional Contributor

    Not sure if this is causing any of the issues or not, but the string you provided

    a = ["one', "two", "three", "four"]

    contains a single quote after one instead of a double quote.

  • I use similar cases but for .NET methods. First of all Python str(["one", "two", "three"]) returns a string but not string array. Unfortunately TestComplete does not support installing and using 3rd party packages and that is their bad. The only solution I found to make sure such the cases will be working is to create own adapter between Python in TestComplete and generic/custom libraries so your pass simple string to the adapter and it convert it to whatever you need and pass to generic/library. 

     

    You can post what numPy produces for your case (or code that produce it) and maybe it is feasible in TestComplete  

  • simhadrx's avatar
    simhadrx
    New Contributor

    Thank you all for the response.

     

    Could you please suggest a way to convert a list into python array so when we pass the variable to the java classes the variable is considered as a string array.

    I imported numpy libraries in the site packages folder of test complete and added the below code.

     

    Our Code:

    sys.path.insert(0, "C:\\Program Files (x86)\\SmartBear\\TestComplete 14\\x64\\Bin\\Extensions\\Python\\Python38\\Lib\\site-packages")
    import numpy as np

    a = ["one', "two", "three", "four"]

    arr = np.array(a)
    Log.Message(arr)

     

    Log.Message(arr) is not printing anything in the logs and also when I pass it to the java classes it is throwing an error below which is pointing to the line import numpy.

     

    Error Msg: 

    Access violation at address 00007FFC0C763CF9 in module '_multiarray_umath.cp38-win_amd64.pyd'. 

    • Bonibom's avatar
      Bonibom
      Contributor

      Try 

      np.array2string

      to get output in Log.Message

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    I suggest doing an internet search for this, as there could be additional modules you might have to import such as jep and java.lang to convert a Python list into Java string array