Forum Discussion

troyyerJP's avatar
troyyerJP
Contributor
5 months ago

importing of python module for simple-salesforce

Just documenting some painful process that TestComplete makes you do and hopefully others can learn from my mistakes. 

Tl;dr: importing complex python module into TestComplete is unfortunately a waste of your time and you would be advised to use another product if you require to use packaged modules more easier without assistance

i have tried to import a python module for simple-salesforce which unfortunately for us has loads of other mandatory modules. 

lets go thru some mistakes..

first mistake was to use whatever Python was present on the machine.

I had installed Python quite some time back and didnt make note of it and performed a install on the python simple-salesforce package. this was a mistake as I got errors with the module lxml where etree was failing   

Python runtime error. ImportError: cannot import name 'etree' from 'lxml' (C:\Program Files (x86)\SmartBear\TestComplete 15\x64\Bin\Extensions\Python\Python311\Lib\lxml\__init__.py)

this was highly likely due to being on Python 3.12, so i downgraded my Python version.

next mistake was thinking i could copy the module folders one by one...nope dont do that. that is just a painstaking waste of your day. dont do me and copy one by one…go to  your Python site-packages location, and copy everything except for any of the .dist-info folders into the Local TestComplete location

when i was trying to copy copy the modules one my one, it would initially say what module was missing so would copy them after each error, but I was them stuck with the following error occuring and not knowing what to do

Python runtime error.

TypeError: NoneType takes no arguments

hence why i just copied all the modules across

1 Reply

  • (Continued as the Community post Editor kept failing to publish my word dump)

    Another of my mistake was downgrading to the wrong version of Python 3.11

    i had just done an install using Chocolatey for 3.11 however that has installed v3.11.6. and TestComplete currently only supports 3.11.5...great. so as as 09/01/2024, use 3.11.5 as per current documentation, for TestComplete v15.59 i have put my verson of python to 3.11.5

    https://support.smartbear.com/testcomplete/docs/scripting/specifics/python.html?

    after installing the right compatible version of python for TestComplete i then installed the package using pip

    copied all the folders across from the packages in python to TestComplete

    so i FINALLY got the module to work in my code. it ran nicely for the first time i ran the TestComplete program with the script

    def SfLogin():
      username = Project.Variables.sfusername
      password = Project.Variables.sfpassword
      token = Project.Variables.sftoken
      sf = simple_salesforce.Salesforce(username=username, password=password, security_token=token, domain='test')
      session_id, instance = simple_salesforce.SalesforceLogin(
          username=username,
          password=password,
          security_token=token,
          domain='test')
      Browsers.Item[btEdge].Navigate(f"{instance}/secur/frontdoor.jsp?sid={session_id}")
      Browsers.Item[btEdge].Navigate(f"{instance}/lightning/r/Contact/003Bo00000GPAFtIAP/view")
      Delay(7000)

    all dandy.. I felt powerful.. I can now trial out more fancy function, HOWEVER, on trying to run it a second time, i get the following error 

    Python runtime error.

    SystemError: initialization of md__mypyc did not return an extension module

    only after closing and reopening TestComplete, does it work again. And only for the first run. the second run onwards will fail...soooo I dont know what to do now. TestComplete doesn't seem to be able to run the Test as expected on subsequent run and I have run out of days on my TestComplete trial to spend any more effort to figure out any ways to fix this up. 

    please also note that i have also trialed and downloaded and installed the testcomplete salesforce extension, 

    https://github.com/SmartBear/testcomplete-salesforce-extension

    however this a very basic salesforce api implementation and has not been updated for over 3 years and hence i would prefer to use a more current module