API call in test | aqHttp | Request Library | Test Complete | External Python Libraries
I want to make a http request but the Test Complete module aqHttp does not provide the features I need. Certain feature I am looking for are allow_redirect, verify_certificate, and so on. The python libary requests does have all these feature. I imported this libary in the manner suggestion by the community while double checking I have the same python version install globally as Test Complete (Python 3.6).
sys.path.insert(0, 'C:\\Python36\\Lib\\site-packages') import requests
def Testing123():
response = requests.get("https://www.example.com", verify=False)
if(response.status_code == 200):
Log.Message("All is good!")
The libary loads and all seems good but when I run the the function a second time all if Test Complete crashes. This kind of unpredictable behavior is constant when using these 3rd party libaries which are nessessary some of the more complicated tests. Does anyone have an tips?
I found a work around although it is not desirable. It seems that the subprocess libary work in Test Complete. This will allow you to run program from cmd. This means that you can run python scripts with regular Python not test complete Python and capture the output of these programs. Code will be displayed below.
testcompletescript.py:
import sys sys.path.insert(0, 'C:\Python36\Lib\site-packages') import subprocess def testing123(): testing = subprocess.getoutput("path\\to\\external\\script\\externalscript.py") Log.Message("output", str(testing))
externalscript.py:
import requests def testing123(): response = requests.get("https://www.google.com") print(response.content) testing123()