Forum Discussion

tomovermeers's avatar
tomovermeers
Occasional Contributor
6 years ago
Solved

FTP with dynamic Port values

Hi community,

 

I have a script that loads dynamic values in TestSuite properties. It looks like this:

 

import com.thoughtworks.xstream.mapper.Mapper

log.info("Initialize TestSuite for ProPlannerVehicle")

def testSuiteName = testRunner.testCase.testSuite.name
log.info("testSuiteName: " + testSuiteName)

def env_extracted = testRunner.testCase.testSuite.project.getPropertyValue("arg_environment")
def env_extracted_from_name = testSuiteName.substring(10, testSuiteName.length() )
log.info("env extracted: " + env_extracted)
log.info("env extracted from name: " + env_extracted_from_name)

if(env_extracted == null) {
if(env_extracted_from_name == 'DEFAULT') {
env_extracted = testRunner.testCase.testSuite.getPropertyValue("defaultEnvironment")
} else {
env_extracted = env_extracted_from_name
}
}
log.info("env computed is: " + env_extracted)

//create null Strings for tmpVariables
def host = ''
def env = ''
def port = ''

switch (env_extracted){
case 'TT':
host = 'esb-tt01.dieteren.be'
port = '26'
env = 'TT'
break
case 'CI':
host = 'esbci-dv.dieteren.be'
port = '26'
env = 'CI'
break
case 'DV':
host = 'esb-dv.dieteren.be'
port = '22'
env = 'DV'
break
case 'QA':
host = 'esb-qa.dieteren.be'
port = '24'
env = 'QA'
break
case 'PP':
host = 'esb-pp.dieteren.be'
port = '21'
env = 'PP'
break
case 'TR':
host = 'esb-tr.dieteren.be'
port = '23'
env = 'TR'
break
default:
log.error("ERROR: Target environment '" + env_extracted + "' not handled.")
testRunner.fail("ERROR: Target environment '" + env_extracted + "' not handled.")
break
}
log.info("Host found: '" + host + "'")
log.info("Environment found: '" + env + "'")

testRunner.testCase.testSuite.setPropertyValue( "tmpPort", port)

testRunner.testCase.testSuite.setPropertyValue( "tmpHost", host)
testRunner.testCase.testSuite.setPropertyValue( "tmpEnvironment", env)
testRunner.testCase.testSuite.setPropertyValue( "tmpTestSuiteName", testSuiteName)
testRunner.testCase.testSuite.setPropertyValue( "tmpId", "ESB_SANITY_" + env)

Then I want to use the 'tmpPort' value in my ftp step. It must be an int value but I get a String value if i use ${#TestSuite#ftpPort}. Does somebody have a solution for this?

  • No it just doesn't want to do the ftp. But I found a workaround :

     

    I added this script and it works:

     

    // Get the test step objects
    def tsFTP1 = testRunner.testCase.getTestStepByName("03_FTP_file1")
    def tsFTP2 = testRunner.testCase.getTestStepByName("04_FTP_file2")
    def tsFTP3 = testRunner.testCase.getTestStepByName("05_FTP_file3")
    def tsFTP4 = testRunner.testCase.getTestStepByName("06_FTP_file4")
    def tsFTP5 = testRunner.testCase.getTestStepByName("07_FTP_file5")

    //Get the port number
    def tmpFtpPort = context.expand( '${#TestSuite#tmpFtpPort}' )

    // Set the ports
    tsFTP1.setPort(tmpFtpPort)
    tsFTP2.setPort(tmpFtpPort)
    tsFTP3.setPort(tmpFtpPort)
    tsFTP4.setPort(tmpFtpPort)
    tsFTP5.setPort(tmpFtpPort)

3 Replies

  • Radford's avatar
    Radford
    Super Contributor

    Sorry, I'm on an older version of Ready API that doesn't have the FTP test step, are you saying that when you go into your FTP Test Step and in the "Port" box you type "${#TestSuite#ftpPort}" Ready API immediately reports an error that it is not an integer, thus won't let you configure the FTP Test Step?

     

    If so I would suggest that you put a Property Transfer test step in just before your FTP step and you can use this to copy in the value from your test suite property into the FTP test step at runtime.

    • tomovermeers's avatar
      tomovermeers
      Occasional Contributor

      No it just doesn't want to do the ftp. But I found a workaround :

       

      I added this script and it works:

       

      // Get the test step objects
      def tsFTP1 = testRunner.testCase.getTestStepByName("03_FTP_file1")
      def tsFTP2 = testRunner.testCase.getTestStepByName("04_FTP_file2")
      def tsFTP3 = testRunner.testCase.getTestStepByName("05_FTP_file3")
      def tsFTP4 = testRunner.testCase.getTestStepByName("06_FTP_file4")
      def tsFTP5 = testRunner.testCase.getTestStepByName("07_FTP_file5")

      //Get the port number
      def tmpFtpPort = context.expand( '${#TestSuite#tmpFtpPort}' )

      // Set the ports
      tsFTP1.setPort(tmpFtpPort)
      tsFTP2.setPort(tmpFtpPort)
      tsFTP3.setPort(tmpFtpPort)
      tsFTP4.setPort(tmpFtpPort)
      tsFTP5.setPort(tmpFtpPort)
      • Radford's avatar
        Radford
        Super Contributor

        Thanks for posting your work around of doing the property transfer via a Groovy script, hopefully that will help others.

         

        Though I must admit this feels like a Ready API bug. Rather unhelpfully the FTP Test Step documentation states "Some fields of the editor allow you to use Property Expansions." (my emphasis), but doesn't say which ones!

         

        I would of assumed that if you weren't able to use a property expansion then it would only allow you to enter an integer value via the test step editor. It may be worth raising this as a SmartBear support case:

         

        https://support.smartbear.com/message/?prod=ReadyAPI

         

        Get the official answer on if you should be able to use a property expansion.