tomovermeers
7 years agoOccasional Contributor
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)