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://GDCQA4-SQL01;databaseName=QA4;user=qa_automation;password=Gr33nDot!"); 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 }
时间: 2024-10-17 02:31:03