Forum Discussion

mdang's avatar
mdang
New Contributor
5 years ago
Solved

Adding external python modules into TestComplete

Hello,

 

I'm trying to add the gnupg module https://gnupg.readthedocs.io/en/latest/ to TestComplete. I have referenced https://support.smartbear.com/testcomplete/docs/scripting/specifics/python.html#importing-packages&_ga=2.149306224.719498295.1614005674-43115802.1595745618

 

I have added the gnupg.py file to C:\Program Files (x86)\SmartBear\TestComplete 14\Bin\Extensions\Python\Python36\Lib

and restarted TestComplete. When I try to import the module (import gnupg), TestComplete says 'no module named gnupg'

 

Is there another step that I am missing?

 

 

Thank you!

  • nmrao's avatar
    nmrao
    5 years ago

    Hellotest wrote:

    I tried first with out datasource as below but getting null pointer error as attached. 

     

    import static com.jayway.jsonpath.JsonPath.parse
    def jsonString = context.expand( '${GetSources#Response}' )
    def sourceId = new groovy.json.JsonSlurper().parseText(jsonString).result.find{it.SourceCode == 'ABC'}
    log.info "source id: ${sourceId.SourceId}"

     


    You almost there, but trivial errors.

     

     

     

    //Get the parsed json of GetSources test step response
    def json = new groovy.json.JsonSlurper().parseText(context('${GetSources#Response}'))
    
    //Closure to the the SourceId for a given SourceCode of the json
    def getSourceIdBySourceCode = { code ->  json.find {it?.SourceCode == code}?.SourceId }
    
    //Check if the value is matching
    assert 'b4035134-ca33-4b33-b3c7-06ea880f1f28' == getSourceIdBySourceCode( 'DEF')
    assert 'bc3cef1e-a9f1-46df-a4f0-c1131357ea57' == getSourceIdBySourceCode( 'ABC')

     

     

     

    You can test it online here

    https://ideone.com/p8X57U