下面列出了org.apache.log4j.varia.NullAppender#org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Initialization
*/
@BeforeClass
public static void beforeClass() {
SWTBotUtils.initialize();
Thread.currentThread().setName("SWTBot Thread"); // for the debugger
/* set up for swtbot */
SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
fLogger.removeAllAppenders();
fLogger.addAppender(new ConsoleAppender(new SimpleLayout()));
fBot = new SWTWorkbenchBot();
/* finish waiting for eclipse to load */
WaitUtils.waitForJobs();
SWTBotUtils.createProject(PROJET_NAME);
}
protected SWTBotShell openWizard() {
bot = new SWTWorkbenchBot();
bot.menu("File").menu("New").menu("Other...").click();
bot.waitUntil(Conditions.shellIsActive("New"));
SWTBotShell shell = bot.shell("New");
shell.activate();
bot.tree().expandNode(".NET Core").select(".NET Core Project");
bot.button("Next >").click();
while (!bot.list(0).itemAt(0).equals("No available templates") && !bot.list(0).isEnabled()) {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
return shell;
}
/**
* Things to setup
*/
@Before
public void beforeClass() {
SWTBotUtils.initialize();
Thread.currentThread().setName("SWTBotTest");
/* set up for swtbot */
SWTBotPreferences.TIMEOUT = 60000; /* 60 second timeout */
SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US";
SWTWorkbenchBot bot = new SWTWorkbenchBot();
SWTBotUtils.closeView("welcome", bot);
/* Prepare the workspace */
prepareWorkspace();
/* Finish waiting for eclipse to load */
WaitUtils.waitForJobs();
/* Create project */
SWTBotUtils.createProject(PROJECT_NAME);
}
/**
* Test Class setup
*
* @throws Exception
* on error
*/
@BeforeClass
public static void init() throws Exception {
TestDirectoryStructureUtil.generateTraceStructure(TEST_TRACES_PATH);
SWTBotUtils.initialize();
/* Set up for SWTBot */
SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US";
fLogger.removeAllAppenders();
fLogger.addAppender(new ConsoleAppender(new SimpleLayout(), ConsoleAppender.SYSTEM_OUT));
fBot = new SWTWorkbenchBot();
/* Finish waiting for eclipse to load */
WaitUtils.waitForJobs();
SWTBotUtils.createProject(TRACE_PROJECT_NAME);
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(TRACE_PROJECT_NAME);
fTracesFolder = new File(Objects.requireNonNull(TmfProjectRegistry.getProject(project, true).getTracesFolder()).getResource().getLocation().toOSString());
createCProject(C_PROJECT_NAME);
setTracingNature(C_PROJECT_NAME);
IProject cProject = ResourcesPlugin.getWorkspace().getRoot().getProject(C_PROJECT_NAME);
fCProjectFolder = cProject.getLocation().toFile();
}
/**
* Test Class setup
*
* @throws IOException
*/
@BeforeClass
public static void init() throws IOException {
TestDirectoryStructureUtil.generateTraceStructure(TEST_TRACES_PATH);
SWTBotUtils.initialize();
/* Set up for swtbot */
SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US";
fLogger.removeAllAppenders();
fLogger.addAppender(new ConsoleAppender(new SimpleLayout(), ConsoleAppender.SYSTEM_OUT));
fBot = new SWTWorkbenchBot();
/* Finish waiting for eclipse to load */
WaitUtils.waitForJobs();
SWTBotUtils.createProject(TRACE_PROJECT_NAME);
importCustomParsers();
}
public static void createUiBinder(final SWTWorkbenchBot bot, String projectName,
String packageName, String name, boolean generateSampleContent, boolean generateComments) {
// Open the list of new project wizards
bot.menu("File").menu("New").menu("Other...").click();
// Select the Web App project wizard
SWTBotTree projectSelectionTree = bot.tree();
SWTBotTreeItem projectSelectionGoogleTreeItem = SwtBotTreeActions
.getUniqueTreeItem(bot, projectSelectionTree, "GWT Classes", "UiBinder").expand();
SwtBotTreeActions.selectTreeItem(bot, projectSelectionGoogleTreeItem, "UiBinder");
bot.button("Next >").click();
// Configure the UiBinder and then create it
String sourceFolder = projectName + "/" + SOURCE_FOLDER;
bot.textWithLabel("Source folder:").setText(sourceFolder);
bot.textWithLabel("Package:").setText(packageName);
bot.textWithLabel("Name:").setText(name);
SwtBotUtils.setCheckBox(bot.checkBox("Generate sample content"),
generateSampleContent);
SwtBotUtils.setCheckBox(bot.checkBox("Generate comments"), generateComments);
SwtBotUtils.clickButtonAndWaitForWindowChange(bot, bot.button("Finish"));
}
/**
* Set up the test context and environment
*/
@BeforeClass
public static void setUp() {
SWTBotUtils.initialize();
/* set up for swtbot */
SWTBotPreferences.TIMEOUT = 10000; /* 10 second timeout */
SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US";
fBot = new SWTWorkbenchBot();
SWTBotUtils.createProject(TRACE_PROJECT_NAME);
WaitUtils.waitForJobs();
final CtfTestTrace cygProfile = CtfTestTrace.CYG_PROFILE;
LttngUstTrace trace = LttngUstTestTraceUtils.getTrace(cygProfile);
fStart = ((CtfTmfTrace) trace).getStartTime().toNanos();
fFullRange = new TmfTimeRange(TmfTimestamp.fromNanos(fStart), TmfTimestamp.fromNanos(fStart + 100l));
final File file = new File(trace.getPath());
LttngUstTestTraceUtils.dispose(cygProfile);
SWTBotUtils.openTrace(TRACE_PROJECT_NAME, file.getAbsolutePath(), UST_ID);
SWTBotUtils.openView(FlameChartView.ID);
fViewBot = fBot.viewByTitle("Flame Chart");
WaitUtils.waitForJobs();
}
/**
* Waits until the node collapses.
*
* @param bot
* bot to work with, must not be {@code null}
* @param node
* node to wait for, must not be {@code null}
*/
public static void safeBlockingCollapse(final SWTWorkbenchBot bot, final SWTBotTreeItem node) {
Assert.isNotNull(bot, ARGUMENT_BOT);
Assert.isNotNull(node, ARGUMENT_NODE);
if (node.isExpanded()) {
node.collapse();
try {
bot.waitUntil(new DefaultCondition() {
@Override
@SuppressWarnings("PMD.JUnit4TestShouldUseTestAnnotation")
public boolean test() {
return !node.isExpanded();
}
@Override
public String getFailureMessage() {
return "Timeout for node to collapse";
}
}, TIMEOUT_FOR_NODE_TO_COLLAPSE_EXPAND);
} catch (TimeoutException e) {
// Try one last time and do not wait anymore
node.collapse();
}
}
}
/**
* Import cpp project into workspace, and setup SWTBot.
*/
@BeforeClass
public static void setup() {
bot = new SWTWorkbenchBot();
Path file = null;
try {
file = Utils.loadFileFromBundle("org.codechecker.eclipse.rcp.it.tests", Utils.RES + CPP_PROJ);
} catch (URISyntaxException | IOException e) {
e.printStackTrace();
}
Utils.copyFolder(file,
Paths.get(ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString() + File.separator));
File project = new File(ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString() + File.separator
+ CPP_PROJ + File.separator + ".project");
try {
ProjectImporter.importProject(project.toPath(), CPP_PROJ);
} catch (CoreException e1) {
e1.printStackTrace();
}
}
/** Test Class setup */
@BeforeClass
public static void init() {
SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US";
SWTBotUtils.initialize();
Thread.currentThread().setName(SWT_BOT_THREAD_NAME); // for the debugger
/* set up for swtbot */
SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
fLogger.removeAllAppenders();
fLogger.addAppender(new ConsoleAppender(new SimpleLayout()));
fBot = new SWTWorkbenchBot();
/* finish waiting for eclipse to load */
WaitUtils.waitForJobs();
}
/**
* Creates an experiment
*
* @param bot
* a given workbench bot
* @param projectName
* the name of the project, creates the project if needed
* @param expName
* the experiment name
*/
public static void createExperiment(SWTWorkbenchBot bot, String projectName, final @NonNull String expName) {
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
TmfProjectElement tmfProject = TmfProjectRegistry.getProject(project, true);
TmfExperimentFolder expFolder = tmfProject.getExperimentsFolder();
assertNotNull(expFolder);
NewExperimentOperation operation = new NewExperimentOperation(expFolder, expName);
operation.run(new NullProgressMonitor());
bot.waitUntil(new DefaultCondition() {
@Override
public boolean test() throws Exception {
TmfExperimentElement experiment = expFolder.getExperiment(expName);
return experiment != null;
}
@Override
public String getFailureMessage() {
return "Experiment (" + expName + ") couldn't be created";
}
});
}
/**
* Create a java project with the specified project name. This function opens up the Java
* Perspective.
*
* @param bot The current SWTWorkbenchBot object
* @param projectName Name of java project to be created
*/
public static void createJavaProject(SWTWorkbenchBot bot, String projectName) {
// Open Java Perspective
bot.perspectiveById("org.eclipse.jdt.ui.JavaPerspective").activate();
// Open the list of new project wizards
bot.menu("File").menu("New").menu("Project...").click();
// Select the Java project
SWTBotTree projectSelectionTree = bot.tree();
SWTBotTreeItem projectSelectionTreeItem =
SwtBotTreeActions.getUniqueTreeItem(bot, projectSelectionTree, "Java", "Java Project");
SwtBotTreeActions.selectTreeItem(bot, projectSelectionTreeItem, "Java Project");
bot.button("Next >").click();
// Configure the project and then create it
bot.textWithLabel("Project name:").setText(projectName);
SwtBotUtils.clickButtonAndWaitForWindowChange(bot, bot.button("Finish"));
}
/**
* Create a GWT project from Maven Archetype.
*
* Archetype: https://github.com/branflake2267/Archetypes/tree/master/archetypes/gwt-basic
*/
public static void createMavenGwtProjectIsCreated2(SWTWorkbenchBot bot, String projectName, String packageName) {
// And create a maven project using an archetype
String groupId = packageName;
String artifactId = projectName;
String archetypeGroupId = "com.github.branflake2267.archetypes";
String archetypeArtifactId = "gwt-basic-archetype";
String archetypeVersion = "2.0-SNAPSHOT";
String archetypeUrl = "https://oss.sonatype.org/content/repositories/snapshots";
SwtBotProjectActions.createMavenProjectFromArchetype(bot, groupId, artifactId, packageName,
archetypeGroupId, archetypeArtifactId, archetypeVersion, archetypeUrl);
// And wait for the project to finish setting up
SwtBotWorkbenchActions.waitForIdle(bot);
}
protected static void fileNew(final SWTWorkbenchBot it, final String newWhat) {
int retries = 3;
ExclusiveRange _doubleDotLessThan = new ExclusiveRange(0, retries, true);
for (final Integer i : _doubleDotLessThan) {
try {
it.menu("File").menu("New").menu(newWhat).click();
return;
} catch (final Throwable _t) {
if (_t instanceof WidgetNotFoundException) {
final WidgetNotFoundException e = (WidgetNotFoundException)_t;
if (((i).intValue() == (retries - 1))) {
throw e;
}
String _message = e.getMessage();
String _plus = ("failed: " + _message);
InputOutput.<String>println(_plus);
InputOutput.<String>println("retrying...");
it.sleep(1000);
} else {
throw Exceptions.sneakyThrow(_t);
}
}
}
}
/**
* Returns the specified project. Throws a WidgetNotFoundException if the 'Package Explorer' or
* 'Project Explorer' view cannot be found or if the specified project cannot be found.
*
* @param bot The SWTWorkbenchBot.
* @param projectName The name of the project to select.
* @return the tree
*/
public static SWTBotTreeItem selectProject(final SWTWorkbenchBot bot, String projectName) {
/*
* Choose either the Package Explorer View or the Project Explorer view. Eclipse 3.3 and 3.4
* start with the Java Perspective, which has the Package Explorer View open by default, whereas
* Eclipse 3.5 starts with the Resource Perspective, which has the Project Explorer View open.
*/
SWTBotView explorer = getPackageExplorer(bot);
for (SWTBotView view : bot.views()) {
if (view.getTitle().equals("Package Explorer")
|| view.getTitle().equals("Project Explorer")) {
explorer = view;
break;
}
}
if (explorer == null) {
throw new WidgetNotFoundException(
"Could not find the 'Package Explorer' or 'Project Explorer' view.");
}
// Select the root of the project tree in the explorer view
Widget explorerWidget = explorer.getWidget();
Tree explorerTree = bot.widget(widgetOfType(Tree.class), explorerWidget);
return new SWTBotTree(explorerTree).getTreeItem(projectName).select();
}
/**
* Opens a latency table
*/
@Before
public void createTree() {
/*
* Open latency view
*/
SWTBotUtils.openView(PRIMARY_VIEW_ID, SECONDARY_VIEW_ID);
SWTWorkbenchBot bot = new SWTWorkbenchBot();
SWTBotView viewBot = bot.viewById(PRIMARY_VIEW_ID);
final IViewReference viewReference = viewBot.getViewReference();
IViewPart viewPart = UIThreadRunnable.syncExec(new Result<IViewPart>() {
@Override
public IViewPart run() {
return viewReference.getView(true);
}
});
assertTrue("Could not instanciate view", viewPart instanceof SegmentStoreStatisticsView);
fTreeBot = viewBot.bot().tree();
assertNotNull(fTreeBot);
}
public static void beforeClass() {
UIThreadRunnable.syncExec(new VoidResult() {
public void run() {
resetWorkbench();
resetToolbox();
// close browser-based welcome screen (if open)
SWTWorkbenchBot bot = new SWTWorkbenchBot();
try {
SWTBotView welcomeView = bot.viewByTitle("Welcome");
welcomeView.close();
} catch (WidgetNotFoundException e) {
return;
}
}
});
}
/**
* Setup for the test
*/
@Before
public void before() {
fBot = new SWTWorkbenchBot();
SWTBotUtils.openView(CALLGRAPHDENSITY_ID);
SWTBotView view = fBot.viewById(CALLGRAPHDENSITY_ID);
assertNotNull(view);
fView = view;
CallGraphDensityView funcDensityView = UIThreadRunnable.syncExec((Result<CallGraphDensityView>) () -> {
IViewPart viewRef = fView.getViewReference().getView(true);
return (viewRef instanceof CallGraphDensityView) ? (CallGraphDensityView) viewRef : null;
});
assertNotNull(funcDensityView);
fTableBot = fView.bot().table();
assertNotNull(fTableBot);
fDensityViewer = funcDensityView.getDensityViewer();
assertNotNull(fDensityViewer);
fLatch = new CountDownLatch(1);
fDensityViewer.removeDataListener(fSyncListener);
fDensityViewer.addDataListener(fSyncListener);
fTableViewer = funcDensityView.getTableViewer();
assertNotNull(fTableViewer);
SWTBotUtils.maximize(funcDensityView);
fFuncDensityView = funcDensityView;
fDensityViewer.setNbPoints(100);
}
/**
* Close all non-main shells that are visible.
*
* @param bot
* the workbench bot
*/
public static void closeSecondaryShells(SWTWorkbenchBot bot) {
SWTBotShell[] shells = bot.shells();
SWTBotShell mainShell = getMainShell(shells);
if (mainShell == null) {
return;
}
// Close all non-main shell but make sure we don't close an invisible
// shell such the special "limbo shell" that Eclipse needs to work
Arrays.stream(shells)
.filter(shell -> shell != mainShell)
.filter(s -> !s.widget.isDisposed())
.filter(SWTBotShell::isVisible)
.peek(shell -> log.debug(MessageFormat.format("Closing lingering shell with title {0}", shell.getText())))
.forEach(SWTBotShell::close);
}
/**
* Select the project in Project Explorer
*
* @param bot
* a given workbench bot
* @param projectName
* the name of the project (it needs to exist or else it would
* time out)
* @return a {@link SWTBotTreeItem} of the project
*/
public static SWTBotTreeItem selectProject(SWTWorkbenchBot bot, String projectName) {
SWTBotView projectExplorerBot = bot.viewByTitle("Project Explorer");
projectExplorerBot.show();
// FIXME: Bug 496519. Sometimes, the tree becomes disabled for a certain
// amount of time. This can happen during a long running operation
// (BusyIndicator.showWhile) which brings up the modal dialog "operation
// in progress" and this disables all shells
projectExplorerBot.bot().waitUntil(Conditions.widgetIsEnabled(projectExplorerBot.bot().tree()));
SWTBotTreeItem treeItem = projectExplorerBot.bot().tree().getTreeItem(projectName);
treeItem.select();
return treeItem;
}
public static void createWebAppProject(final SWTWorkbenchBot bot, String projectName,
String packageName, boolean useGwt, boolean generateSampleCode) {
// Open Java Perspective
bot.perspectiveById("org.eclipse.jdt.ui.JavaPerspective").activate();
// Open the list of new project wizards
bot.menu("File").menu("New").menu("Project...").click();
// Select the Web App project wizard
SWTBotTree projectSelectionTree = bot.tree();
// GWT Application
SWTBotTreeItem projectSelectionTreeItem = SwtBotTreeActions.getUniqueTreeItem(bot,
projectSelectionTree, "GWT Application", "GWT Web Application Project").expand();
SwtBotTreeActions.selectTreeItem(bot, projectSelectionTreeItem,
"GWT Web Application Project");
bot.button("Next >").click();
// Configure the project and then create it
bot.textWithLabel("Project name:").setText(projectName);
bot.textWithLabel("Package: (e.g. com.example.myproject)").setText(packageName);
SwtBotUtils.setCheckBox(bot.checkBox("Use GWT"), useGwt);
SwtBotUtils.setCheckBox(bot.checkBox("Generate project sample code"),
generateSampleCode);
SwtBotUtils.clickButtonAndWaitForWindowChange(bot, bot.button("Finish"));
SwtBotWorkbenchActions.waitForIdle(bot);
}
/**
* Close a view with a title
*
* @param title
* the title, like "welcome"
* @param bot
* the workbench bot
*/
public static void closeView(String title, SWTWorkbenchBot bot) {
final List<SWTBotView> openViews = bot.views();
for (SWTBotView view : openViews) {
if (view.getTitle().equalsIgnoreCase(title)) {
view.close();
bot.waitUntil(ConditionHelpers.viewIsClosed(view));
}
}
}
/**
* Before class, call by all subclassed
*/
@BeforeClass
public static void beforeClass() {
SWTBotUtils.initialize();
Thread.currentThread().setName("SWTBotTest");
/* set up for swtbot */
SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US";
fLogger.removeAllAppenders();
fLogger.addAppender(new ConsoleAppender(new SimpleLayout(), ConsoleAppender.SYSTEM_OUT));
fBot = new SWTWorkbenchBot();
/* Finish waiting for eclipse to load */
WaitUtils.waitForJobs();
}
/**
* Delete the project and de-register the LAMI analyses
*/
@AfterClass
public static void afterClass() {
SWTWorkbenchBot bot = new SWTWorkbenchBot();
bot.closeAllEditors();
SWTBotUtils.deleteProject(PROJECT_NAME, bot);
fLogger.removeAllAppenders();
OnDemandAnalysisManager.getInstance().unregisterAnalysis(LamiAnalyses.MULTIPLE_ROW.getAnalysis());
OnDemandAnalysisManager.getInstance().unregisterAnalysis(LamiAnalyses.MULTIPLE_SIMILAR_ROW.getAnalysis());
}
/**
* Test Class setup
*
* @throws IOException
* on error
*/
@BeforeClass
public static void init() throws IOException {
TestDirectoryStructureUtil.generateTraceStructure(TEST_TRACES_PATH);
SWTBotUtils.initialize();
/*
* FIXME: We can't use Manage Custom Parsers > Import because it uses a native
* dialog. We'll still check that they show up in the dialog
*/
CustomTxtTraceDefinition[] txtDefinitions = CustomTxtTraceDefinition.loadAll(getPath("customParsers/ExampleCustomTxtParser.xml"));
txtDefinitions[0].save();
/* set up test trace */
fTestFile = new File(getPath(new Path("import").append(CUSTOM_TEXT_LOG.getTracePath()).toString()));
assertTrue(fTestFile.exists());
/* Set up for swtbot */
SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US";
fLogger.removeAllAppenders();
fLogger.addAppender(new ConsoleAppender(new SimpleLayout(), ConsoleAppender.SYSTEM_OUT));
fBot = new SWTWorkbenchBot();
/* Finish waiting for eclipse to load */
WaitUtils.waitForJobs();
SWTBotUtils.createProject(TRACE_PROJECT_NAME);
}
/** Test Class setup */
@BeforeClass
public static void init() {
SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US";
SWTBotUtils.initialize();
SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
fLogger.removeAllAppenders();
fLogger.addAppender(new NullAppender());
fBot = new SWTWorkbenchBot();
/* finish waiting for eclipse to load */
WaitUtils.waitForJobs();
}
@Override
public IConsoleView consoleView() throws RemoteException {
SWTWorkbenchBot bot = new SWTWorkbenchBot();
RemoteWorkbenchBot.getInstance().openViewById(VIEW_CONSOLE_ID);
RemoteWorkbenchBot.getInstance().view(VIEW_CONSOLE).show();
bot.viewByTitle(VIEW_CONSOLE).show();
return ConsoleView.getInstance().setView(bot.viewByTitle(VIEW_CONSOLE));
}
/**
* Open a specific Avaloq Prefrences Page.
*
* @param bot
* to work with, must not be {@code null}
* @param section
* the name of the desired page (e.g. 'Database'), must not be {@code null}
*/
public static void openAvaloqPreferencesSection(final SWTWorkbenchBot bot, final String section) {
Assert.isNotNull(bot, ARGUMENT_BOT);
Assert.isNotNull(section, "section");
bot.menu("Window").menu("Preferences").click();
final SWTBotShell shell = bot.shell("Preferences");
shell.activate();
final SWTBotTreeItem item = bot.tree().getTreeItem("Avaloq");
CoreSwtbotTools.waitForItem(bot, item);
CoreSwtbotTools.expandNode(bot.tree(), "Avaloq").select(section);
}
/**
* Choose either the Package Explorer View or the Project Explorer view. Some perspectives have
* the Package Explorer View open by default, whereas others use the Project Explorer View.
*
* @throws WidgetNotFoundException if an explorer is not found
*/
public static SWTBotView getExplorer(SWTWorkbenchBot bot) {
for (SWTBotView view : bot.views()) {
if (view.getTitle().equals("Package Explorer")
|| view.getTitle().equals("Project Explorer")) {
return view;
}
}
throw new WidgetNotFoundException(
"Could not find the 'Package Explorer' or 'Project Explorer' view.");
}
/**
* Open a trace in an editor
*/
@Before
public void beforeTest() {
SWTWorkbenchBot bot = new SWTWorkbenchBot();
SWTBotUtils.createProject(PROJECT_NAME);
SWTBotTreeItem treeItem = SWTBotUtils.selectTracesFolder(bot, PROJECT_NAME);
assertNotNull(treeItem);
SWTBotUtils.openTrace(PROJECT_NAME, fFileLocation.getAbsolutePath(), XMLSTUB_ID);
SWTBotUtils.openView(FilterView.ID);
}