SoapUI Pro Project Solution Collection-Custom project and setup
import java.util.List; import java.util.Map; import org.apache.log4j.Logger; import com.eviware.soapui.SoapUI; import com.eviware.soapui.SoapUIProSettings; import com.eviware.soapui.impl.wsdl.WsdlProjectPro; import com.eviware.soapui.impl.wsdl.support.connections.DatabaseConnection; import com.eviware.soapui.impl.wsdl.support.connections.DefaultDatabaseConnectionContainer; import com.eviware.soapui.model.environment.Environment; import com.eviware.soapui.model.project.Project; import com.eviware.soapui.model.settings.Settings; import com.eviware.soapui.model.testsuite.TestSuite; import com.eviware.soapui.settings.HttpSettings; import com.eviware.soapui.settings.ProxySettings; import com.eviware.soapui.support.GroovyUtils; public class ProjectLevel { public void mypro(Project project,Logger log){ project.getProperties().clear(); project.setPropertyValue("", ""); GroovyUtils.registerJdbcDriver("com.microsoft.sqlserver.jdbc.SQLServerDriver"); // project.getPropertyAt(1).getName(),get the soapui project level from API. if(project instanceof WsdlProjectPro){ //properties for project String name = project.getName(); String description = project.getDescription(); String path = project.getPath(); String resourceRoot = project.getResourceRoot(); ((WsdlProjectPro) project).setComposite(true); project.getShadowPassword(); ((WsdlProjectPro) project).getScriptLibrary(); ((WsdlProjectPro) project).getDefaultScriptLanguage(); ((WsdlProjectPro) project).setCacheDefinitions(true); //custom properties before setup the soapui project //testsuite int testSuiteCount = project.getTestSuiteCount(); TestSuite testSuiteByName = project.getTestSuiteByName(""); List<TestSuite> testSuiteList = project.getTestSuiteList(); Map<String, TestSuite> testSuites = ((WsdlProjectPro) project).getTestSuites(); for(TestSuite suite:testSuiteList){ String name2 = suite.getName(); } for(String key:testSuites.keySet()){ TestSuite value = testSuites.get(key); } //configuration jdbc connections GroovyUtils.registerJdbcDriver("com.microsoft.sqlserver.jdbc.SQLServerDriver"); DefaultDatabaseConnectionContainer databaseConnectionContainer = ((WsdlProjectPro) project).getDatabaseConnectionContainer(); String[] databaseConnectionsNames = databaseConnectionContainer.getDatabaseConnectionsNames(com.eviware.soapui.model.environment.DefaultEnvironment.getInstance()); for(String dbname:databaseConnectionsNames){ databaseConnectionContainer.removeDatabaseConnectionByName(dbname); } DatabaseConnection addDatabaseConnection = databaseConnectionContainer.addDatabaseConnection("com.microsoft.sqlserver.jdbc.SQLServerDriver"); addDatabaseConnection.setDriver("com.microsoft.sqlserver.jdbc.SQLServerDriver"); addDatabaseConnection.setConnectionString("jdbc:sqlserver://"); addDatabaseConnection.setName("testname"); addDatabaseConnection.setPassword(""); int projectCount = project.getWorkspace().getProjectCount(); //environment settings ,we can mark testing with different environments ,refer this url //http://www.soapui.org/Working-with-Projects/environment-handling-in-soapui.html String activeEnvironmentName = ((WsdlProjectPro) project).getActiveEnvironmentName(); ((WsdlProjectPro) project).setActiveEnvironment("staging"); ((WsdlProjectPro) project).getEnvironmentList().clear(); List<Environment> environmentList = ((WsdlProjectPro) project).getEnvironmentList(); for(Environment e:environmentList){ String project2 = e.getProject().getName(); String name2 = e.getName(); e.addNewProperty("propertyname","propertyvlaue"); e.addNewService("testservice", null); } //soapui preference global settings, like the http settings,proxy settings and so on Settings settings = SoapUI.getSettings(); settings.setString(ProxySettings.ENABLE_PROXY, "false"); settings.setString(HttpSettings.HTTP_VERSION, "1.1"); settings.setString(SoapUIProSettings.OUTLINE_EDITOR_LIMIT, "4000000"); settings.setString(SoapUIProSettings.FORM_EDITOR_LIMIT, "200000"); settings.setString(SoapUIProSettings.SCRIPT_LIBRARY, "C:\\TEST\\groovy"); settings.setString(SoapUIProSettings.COMPLETE_MESSAGE_LOGS,"true"); SoapUI.updateProxyButtonAndTooltip(); SoapUI.updateProxyFromSettings(); settings.reloadSettings(); //set the event }
作者:高级测试开发网
博客地址:https://seniortesting.club
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。