Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save DinisCruz/7110740 to your computer and use it in GitHub Desktop.

Select an option

Save DinisCruz/7110740 to your computer and use it in GitHub Desktop.
23rd Oct 2013: Misc Java STWBot and Groovy scripts
#!/bin/sh
echo "test"
java -Xms256M -Xmx768M -XX:MaxPermSize=512M \
-jar "/Users/zen/Fortify-Plugin/Eclipses/eclipse_x32-3.7_Indigo/plugins/org.eclipse.equinox.launcher_1.2.0.v20110502.jar" \
-application "org.eclipse.swtbot.eclipse.junit4.headless.swtbottestapplication" \
-testApplication "com.yourcompany.application" \
-data "/Users/zen/Fortify-Plugin/Eclipses/workspaces/eclipse_x32-3.7_Indigo" \
-testPluginName "test.maven.swt.bot-1.0.0-SNAPSHOT.jar" \
-className "test.maven.swt.bot" \
-consoleLog -debug
/Users/zen/Fortify-Plugin/Eclipses/eclipse_x32-3.7_Indigo/plugins/org.eclipse.swtbot.eclipse.finder_2.1.1.201307101628.jar
/Users/zen/Fortify-Plugin/Eclipses/eclipse (x64) - 3.7 Indigo /plugins/org.eclipse.swtbot.eclipse.finder_2.1.1.201307101628.jar
def jar = "/Users/zen/Fortify-Plugin/TeamMentor_Eclipse_Plugin_Build/test.maven.swt.bot/target/test.maven.swt.bot-1.0.0-SNAPSHOT.jar";
eclipseAPI.getClass().classLoader.systemClassLoader.addURL(new File(jar).toURL());
def uiTest = eclipseAPI.getClass().classLoader.systemClassLoader.loadClass("test.maven.swt.bot.UITest");
return uiTest.toString();
//return uiTest.newInstance();
//;"org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot");
//return eclipseAPI.getClass().classLoader.systemClassLoader.URLs.collect { "\n" + it}
inspect()
//inspect(eclipseAPI.getClass().classLoader.systemClassLoader.systemClassLoader.parent)
return Class.forName("org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot");
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
def bot = new SWTWorkbenchBot();
def fileMenu = bot.menu("File");
//return fileMenu.widget.menu
return fileMenu.widget.menu.items.collect()
inspect(fileMenu.widget.menu.items);
return fileMenu;
return "ok";
return bot.menu("Eclipse").menu("About Eclipse Platform").click();
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
def project = "/Users/zen/Fortify-Plugin/Eclipses/workspaces/test_proj"
Thread.start
{
def bot = new SWTWorkbenchBot();
def importMenu = bot.menu("File").menu('Import...');
importMenu.click();
def shell = bot.shell("Import");
bot.tree().expandNode("General").select("Existing Projects into Workspace");
bot.button("Next >").click();
bot.radio("Select root directory:").click();
bot.text(0).setText(project );
eclipseAPI.log("inside the thread: " + shell);
};
return "here 12"
//inspect(bot)
//def shell = bot.shell("Import");
return shell;
//bot.textWithLabel("Project name:").setText("SWTBot Test Project");
return fileMenu
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
def project = "/Users/zen/Fortify-Plugin/Eclipses/workspaces/test_proj"
Thread.start
{
def bot = new SWTWorkbenchBot();
def importMenu = bot.menu("File").menu('Import...');
importMenu.click();
def shell = bot.shell("Import");
bot.tree().expandNode("General").select("Existing Projects into Workspace");
bot.button("Next >").click();
bot.radio("Select root directory:").click();
bot.text(0).setText(project);
bot.button("< Back").click();
bot.button("Next >").click();
bot.button("Finish").click();
eclipseAPI.log("inside the thread: " + shell);
};
return "here 12"
//inspect(bot)
//def shell = bot.shell("Import");
return shell;
//bot.textWithLabel("Project name:").setText("SWTBot Test Project");
return fileMenu
def bot = new SWTWorkbenchBot();
return bot.views().collect { "\n" + it.getTitle()}
def bot = eclipseAPI.objects["bot"];
return bot.menu("Help").menu("Welcome").click();
try
{
String baseFolder = "file:////Users/zen/Fortify-Plugin/Eclipses/eclipse (x64) - 3.7 Indigo /plugins/";
List<String> jars = Arrays.asList("org.eclipse.swtbot.eclipse.finder_2.1.1.201307101628.jar",
"org.eclipse.swtbot.swt.finder_2.1.1.201307101628.jar",
"org.apache.log4j_1.2.15.v201012070815.jar");
for(String jar : jars)
{
groovyShell.getClassLoader().addURL(new URL(baseFolder + jar));
}
URL[] urls = groovyShell.getClassLoader().getURLs();
String value = groovyShell.evaluate(text).toString();
result.setText(value);
} catch (CompilationFailedException e)
{
result.setText("COMPILATION ERROR:" + e.getMessage());
}
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
return new SWTWorkbenchBot().menu("File");
def bot = eclipseAPI.objects["bot"];
return bot.class;
//****** refactoring
public class EclipseAPI
{
public static EclipsePartEvents partEvents;
public HashMap<String,Object> objects;
public List<String> extraGroovyJars;
.....
public void compileAndExecuteCode()
{
.....
try
{
for(String jar : eclipseApi.extraGroovyJars)
{
groovyShell.getClassLoader().addURL(new URL("file://"+ jar));
}
String value = groovyShell.evaluate(text).toString();
result.setText(value);
}
......
//****** Groovy script
//step1: run this to set the eclipseAPI.extraGroovyJars
/*
String baseFolder = "/Users/zen/Fortify-Plugin/Eclipses/eclipse (x64) - 3.7 Indigo /plugins/";
eclipseAPI.extraGroovyJars = Arrays.asList(baseFolder + "org.eclipse.swtbot.eclipse.finder_2.1.1.201307101628.jar",
baseFolder + "org.eclipse.swtbot.swt.finder_2.1.1.201307101628.jar",
baseFolder + "org.apache.log4j_1.2.15.v201012070815.jar");
return eclipseAPI.extraGroovyJars;
*/
//step2: run this (which will fail to compile before step1
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
return new SWTWorkbenchBot().menu("File");
public ....(SWTWorkbenchBot _bot) throws PartInitException
{
bot = _bot;
Display.getDefault().syncExec(new Runnable()
{
public void run()
{
try
{
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchWindow activeWorkbench2 = workbench.getActiveWorkbenchWindow();
IWorkbenchWindow activeWorkbench = new WorkbenchContentsFinder().activeWorkbenchWindow();
IWorkbenchPage activePage = activeWorkbench.getActivePage();
IViewPart viewPart = activePage.showView("g2.scripts.views.SimpleEditor");
Field field1 = viewPart.getClass().getField("eclipseApi");
Object eclipseApi = field1.get(viewPart);
Field field2 = eclipseApi.getClass().getField("objects");
Object objects = field2.get(eclipseApi);
HashMap<String,Object> objs = (HashMap<String,Object>)objects;
objs.put("bot",bot);
objs.put("SWTBotHelper",this);
// IPreferenceStore preferences = PlatformUI.getPreferenceStore();
// IEclipsePreferences test = ConfigurationScope.INSTANCE.getNode("TeamMentor.Eclipse.Plugin.Fortify");
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
});
}
//**** contents of: 1 - run first (add STWBot Jars to Groovy ClassLoader).g2
//step1: run this to set the eclipseAPI.extraGroovyJars
String baseFolder = "/Users/zen/Fortify-Plugin/Eclipses/eclipse (x64) - 3.7 Indigo /plugins/";
eclipseAPI.extraGroovyJars = Arrays.asList(baseFolder + "org.eclipse.swtbot.eclipse.finder_2.1.1.201307101628.jar",
baseFolder + "org.eclipse.swtbot.swt.finder_2.1.1.201307101628.jar",
baseFolder + "org.apache.log4j_1.2.15.v201012070815.jar",
baseFolder + "org.hamcrest.library_1.3.0.v201305281000.jar");
return eclipseAPI.extraGroovyJars;
//**** contents of: SWTBot - get list with current open views.g2
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
def bot = new SWTWorkbenchBot();
//bot.views().first().reference.setVisible(true);
//inspect(bot.views().first().reference.getPart(true));
def projectExplorer = bot.views().first().reference.getPart(true); // gets the part of the first part/view (in this case the Project Explorer)
projectExplorer.setPartName("Test title change"); // this changes the title
return bot.views().collect { "\n" + it.getTitle() + "\t\t\t : " + it.toString()}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment