Forum Discussion
Finan
13 years agoFrequent Contributor
project properties can be loaded as endpoints, by ${#Project#propertyname}
Enter this as endpoint for a webservice (don't forget to add the property to the project).
Below is a script to use at the "Load Script" on project level, it loads files from projectpath/settings.
Syntax for the propertie filename = environment_tst.properties
Syntax for the properties inside the file: endpoint=http://localhost:8080
Enter this as endpoint for a webservice (don't forget to add the property to the project).
Below is a script to use at the "Load Script" on project level, it loads files from projectpath/settings.
Syntax for the propertie filename = environment_tst.properties
Syntax for the properties inside the file: endpoint=http://localhost:8080
import groovy.io.*;
import groovy.swing.SwingBuilder;
import javax.swing.*;
//determine projectdir by project.getPath, because GroovyUtils.projectpath does not work at startup
path = project.getPath();
log.info("path = " + path);
s= System.getProperty("file.separator");
settingsPath = path+s;
//settingsfiles are stored in projecpath\settings
settingsPath += "settings" + s;
//only works in versions > 4.0 because of SoapUI.isCommandline()
if(com.eviware.soapui.SoapUI.SOAPUI_VERSION.toString().substring(0,1).toInteger() >= 4){
if(com.eviware.soapui.SoapUI.isCommandLine()){
setProperties("environment_default", settingsPath);
}else{
openDialog();
}
}
//Method to set project properties
void setProperties(name, location){
try{
//read properties file
FileInputStream fstream = new FileInputStream(location + name + ".properties");
DataInputStream ins = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(ins));
String strLine;
//set new properties
while ((strLine = br.readLine()) != null) {
attribute = strLine.split("=");
project.setPropertyValue(attribute[0],attribute[1]);
}
ins.close();
}catch(Exception e){
log.info("No project-properties were set, could not find file for name: " + name + " and location: " + location);
}
}
//Opens the swing dialog
void openDialog(){
def swingBuilder = new SwingBuilder();
File[] listOfFiles = new File(settingsPath).listFiles();
int count, count2;
def options = [];
def browser = [];
for (int i = 0; i < listOfFiles.length; i++) {
if(listOfFiles[i].getName().contains("environment_")){
name = listOfFiles[i].getName().replace("environment_","").replace(".properties","");
options[count]=name;
count++
}
if(listOfFiles[i].getName().contains("browser_")){
name = listOfFiles[i].getName().replace("browser_","").replace(".properties","");
browser[count2]=name;
count2++;
}
}
def pane = swingBuilder.optionPane(message:'Environment', selectionValues:options, optionType:JOptionPane.CLOSED_OPTION);
def dialog = pane.createDialog(null, 'Select an environment (' + project.name + ")");
dialog.show();
setProperties("environment_" + pane.getInputValue(), settingsPath);
}
Related Content
- 6 years ago
- 2 years ago
- 2 years ago
Recent Discussions
- 23 days ago