本文整理汇总了Java中org.eclipse.swtbot.swt.finder.SWTBot类的典型用法代码示例。如果您正苦于以下问题:Java SWTBot类的具体用法?Java SWTBot怎么用?Java SWTBot使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SWTBot类属于org.eclipse.swtbot.swt.finder包,在下文中一共展示了SWTBot类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createTreeRowCountCondition
import org.eclipse.swtbot.swt.finder.SWTBot; //导入依赖的package包/类
public ICondition createTreeRowCountCondition (final int count) {
return new ICondition () {
@Override
public boolean test() throws Exception {
return geVisibleRowCount () == count;
}
@Override
public void init(SWTBot bot) {
}
@Override
public String getFailureMessage() {
return "Expected row coutn not found ";
}
};
}
示例2: copy
import org.eclipse.swtbot.swt.finder.SWTBot; //导入依赖的package包/类
public void copy(ICondition condition) {
CopyAction button = new CopyAction();
button.click();
editor.click(50, 50);
if (condition == null) {
condition = new org.eclipse.swtbot.swt.finder.waits.ICondition() {
@Override
public boolean test() throws Exception {
PasteAction button = new PasteAction();
return button.isEnabled();
}
@Override
public void init(SWTBot bot) {
}
@Override
public String getFailureMessage() {
return "Paste button not enabled";
}
};
}
bot.waitUntil(condition);
}
示例3: getUniqueTreeItem
import org.eclipse.swtbot.swt.finder.SWTBot; //导入依赖的package包/类
/**
* Given a tree that contains an entry with <code>itemName</code> and a direct child with a name
* matching <code>subchildName</code>, return its tree item.
*
* This method is useful when there is the possibility of a tree having two similarly-named
* top-level nodes.
*
* @param mainTree the tree
* @param itemName the name of a top-level node in the tree
* @param subchildName the name of a direct child of the top-level node (used to uniquely select
* the appropriate tree item for the given top-level node name)
* @return the tree item corresponding to the top-level node with <code>itemName</code>that has a
* direct child with <code>subchildName</code>. If there are multiple tree items that
* satisfy this criteria, then the first one (in the UI) will be returned
*
* @throws WidgetNotFoundException if no such node can be found
*/
public static SWTBotTreeItem getUniqueTreeItem(final SWTBot bot, final SWTBotTree mainTree,
String itemName, String subchildName) {
for (SWTBotTreeItem item : mainTree.getAllItems()) {
if (itemName.equals(item.getText())) {
try {
item.expand();
waitUntilTreeHasText(bot, item);
if (item.getNode(subchildName) != null) {
return item;
}
} catch (WidgetNotFoundException ex) {
// Ignore
}
}
}
throw new WidgetNotFoundException(
"The " + itemName + " node with a child of " + subchildName + " must exist in the tree.");
}
示例4: waitUntilTreeHasItemImpl
import org.eclipse.swtbot.swt.finder.SWTBot; //导入依赖的package包/类
private static boolean waitUntilTreeHasItemImpl(SWTBot bot, final TreeItem tree,
final String nodeText) {
try {
bot.waitUntil(new DefaultCondition() {
@Override
public String getFailureMessage() {
return "Could not find node with text " + nodeText;
}
@Override
public boolean test() throws Exception {
return getTreeItem(tree, nodeText) != null;
}
});
} catch (TimeoutException ex) {
return false;
}
return true;
}
示例5: waitUntilTreeHasTextImpl
import org.eclipse.swtbot.swt.finder.SWTBot; //导入依赖的package包/类
private static boolean waitUntilTreeHasTextImpl(SWTBot bot, final TreeItem tree) {
try {
bot.waitUntil(new DefaultCondition() {
@Override
public String getFailureMessage() {
return "Not all of the nodes in the tree have text.";
}
@Override
public boolean test() throws Exception {
return treeItemHasText(tree);
}
});
} catch (TimeoutException ex) {
return false;
}
return true;
}
示例6: waitUntilTreeItemHasItem
import org.eclipse.swtbot.swt.finder.SWTBot; //导入依赖的package包/类
/**
* Blocks the caller until the tree item has the given item text.
*
* @param tree the tree item to search
* @param nodeText the item text to look for
* @throws org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException if the item could not
* be found within the timeout period
*/
private static void waitUntilTreeItemHasItem(SWTBot bot, final SWTBotTreeItem tree,
final String nodeText) {
// Attempt #1
if (!waitUntilTreeHasItemImpl(bot, tree.widget, nodeText)) {
// Attempt #2: Something went wrong, try to cautiously reopen it.
bot.sleep(1000);
// There isn't a method to collapse, so double-click instead
tree.doubleClick();
bot.waitUntil(new TreeCollapsedCondition(tree.widget));
bot.sleep(1000);
tree.expand();
bot.waitUntil(new TreeExpandedCondition(tree.widget));
if (!waitUntilTreeHasItemImpl(bot, tree.widget, nodeText)) {
printTree(tree.widget);
throw new TimeoutException(
String.format("Timed out waiting for %s, giving up...", nodeText));
}
}
}
示例7: captureScreenshot
import org.eclipse.swtbot.swt.finder.SWTBot; //导入依赖的package包/类
/**
* Takes a screenshot.
*
* @param bot
* the {@link SWTBot} factory instance to use, must not be {@code null}
* @param prefix
* base name of file, may be {@code null} only if useCaller is {@code true}
* @param useCaller
* if {@code true}, append the name of the calling method to the prefix
*/
public static void captureScreenshot(final SWTBot bot, final String prefix, final boolean useCaller) {
Assert.isNotNull(bot, ARGUMENT_BOT);
if (prefix == null && !useCaller) {
throw new IllegalArgumentException();
}
final StringBuilder sBuilder = new StringBuilder("screenshots/");
if (prefix != null) {
sBuilder.append(prefix);
}
if (useCaller) {
sBuilder.append(Reflect.getCallingMethod());
}
sBuilder.append(".jpeg");
bot.captureScreenshot(sBuilder.toString());
}
示例8: expandNode
import org.eclipse.swtbot.swt.finder.SWTBot; //导入依赖的package包/类
/**
* Attempts to expand all nodes along the path specified by the node array parameter.
* The method is copied from SWTBotTree with an additional check if the node is already expanded.
*
* @param bot
* tree bot, must not be {@code null}
* @param nodes
* node path to expand, must not be {@code null} or empty
* @return the last tree item that was expanded, or {@code null} if no item was found
*/
public static SWTBotTreeItem expandNode(final SWTBotTree bot, final String... nodes) {
Assert.isNotNull(bot, ARGUMENT_BOT);
Assert.isNotNull(nodes, ARGUMENT_NODES);
assertArgumentIsNotEmpty(nodes, ARGUMENT_NODES);
new SWTBot().waitUntil(widgetIsEnabled(bot));
SWTBotTreeItem item = bot.getTreeItem(nodes[0]);
if (!item.isExpanded()) {
item.expand();
}
final List<String> asList = new ArrayList<String>(Arrays.asList(nodes));
asList.remove(0);
if (!asList.isEmpty()) {
item = expandNode(item, asList.toArray(new String[asList.size()]));
}
return item;
}
示例9: beforeAllTests
import org.eclipse.swtbot.swt.finder.SWTBot; //导入依赖的package包/类
@Override
public void beforeAllTests() {
super.beforeAllTests();
final Display display = getDisplay();
// Creating the shell must be done on the UI thread.
display.syncExec(new Runnable() {
@Override
public void run() {
// Create and open the shell.
shell = new Shell(display);
shell.setLayout(new FillLayout());
shell.open();
}
});
// Initialize static or otherwise shared resources here.
// Set up the SWTBot for the shell.
bot = new SWTBot(shell);
return;
}
示例10: terminateAllLaunchConfigs
import org.eclipse.swtbot.swt.finder.SWTBot; //导入依赖的package包/类
public static void terminateAllLaunchConfigs(SWTBot bot) {
SwtBotUtils.print("Terminating Launches");
ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
ILaunch[] launches = manager.getLaunches();
if (launches == null || launches.length == 0) {
SwtBotUtils.print("No Launches to terminate");
}
for (ILaunch launch : launches) {
if (!launch.isTerminated()) {
try {
launch.terminate();
} catch (DebugException e) {
SwtBotUtils.printError("Could not terminate launch." + e.getMessage());
}
}
}
SwtBotWorkbenchActions.waitForIdle(bot);
SwtBotUtils.print("Terminated Launches");
}
示例11: getUniqueTreeItem
import org.eclipse.swtbot.swt.finder.SWTBot; //导入依赖的package包/类
/**
* Given a tree that contains an entry with <code>itemName</code> and a direct child with a name
* matching <code>subchildName</code>, return its tree item.
*
* This method is useful when there is the possibility of a tree having two similarly-named
* top-level nodes.
*
* @param mainTree the tree
* @param itemName the name of a top-level node in the tree
* @param subchildName the name of a direct child of the top-level node (used to uniquely select
* the appropriate tree item for the given top-level node name)
* @return the tree item corresponding to the top-level node with <code>itemName</code>that has a
* direct child with <code>subchildName</code>. If there are multiple tree items that
* satisfy this criteria, then the first one (in the UI) will be returned
*
* @throws IllegalStateException if no such node can be found
*/
public static SWTBotTreeItem getUniqueTreeItem(final SWTBot bot, final SWTBotTree mainTree,
String itemName, String subchildName) {
for (SWTBotTreeItem item : mainTree.getAllItems()) {
if (itemName.equals(item.getText())) {
try {
item.expand();
SwtBotTreeActions.waitUntilTreeHasText(bot, item);
if (item.getNode(subchildName) != null) {
return item;
}
} catch (WidgetNotFoundException e) {
// Ignore
}
}
}
throw new IllegalStateException("The '" + itemName + "' node with a child of '" + subchildName
+ "' must exist in the tree.");
}
示例12: waitUntilTreeHasItemImpl
import org.eclipse.swtbot.swt.finder.SWTBot; //导入依赖的package包/类
private static boolean waitUntilTreeHasItemImpl(SWTBot bot, final TreeItem tree,
final String nodeText) {
try {
bot.waitUntil(new DefaultCondition() {
@Override
public String getFailureMessage() {
return "Could not find node with text " + nodeText;
}
@Override
public boolean test() throws Exception {
return getTreeItem(tree, nodeText) != null;
}
});
} catch (TimeoutException e) {
return false;
}
return true;
}
示例13: waitUntilTreeHasTextImpl
import org.eclipse.swtbot.swt.finder.SWTBot; //导入依赖的package包/类
private static boolean waitUntilTreeHasTextImpl(SWTBot bot, final TreeItem tree) {
try {
bot.waitUntil(new DefaultCondition() {
@Override
public String getFailureMessage() {
return "Not all of the nodes in the tree have text.";
}
@Override
public boolean test() throws Exception {
return doesTreeItemHaveText(tree);
}
});
} catch (TimeoutException e) {
return false;
}
return true;
}
示例14: waitUntilTreeItemHasItem
import org.eclipse.swtbot.swt.finder.SWTBot; //导入依赖的package包/类
/**
* Blocks the caller until the tree item has the given item text.
*
* @param tree the tree item to search
* @param nodeText the item text to look for
* @throws org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException if the item could not
* be found within the timeout period
*/
private static void waitUntilTreeItemHasItem(SWTBot bot, final SWTBotTreeItem tree,
final String nodeText) {
// Attempt #1
if (!waitUntilTreeHasItemImpl(bot, tree.widget, nodeText)) {
// Attempt #2: Something went wrong, try to cautiously reopen it.
bot.sleep(1000);
// There isn't a method to collapse, so double-click instead
tree.doubleClick();
bot.waitUntil(new TreeCollapsedCondition(tree.widget));
bot.sleep(1000);
tree.expand();
bot.waitUntil(new TreeExpandedCondition(tree.widget));
if (!waitUntilTreeHasItemImpl(bot, tree.widget, nodeText)) {
printTree(tree.widget);
throw new TimeoutException(
String.format("Timed out waiting for %s, giving up...", nodeText));
}
}
}
示例15: waitUntilTreeHasText
import org.eclipse.swtbot.swt.finder.SWTBot; //导入依赖的package包/类
/**
* Blocks the caller until all of the direct children of the tree have text. The assumption is
* that the tree does not have any "empty" children.
*
* TODO: Refactor some of this logic; it follows the same general pattern as
* {@link #waitUntilTreeItemHasItem(SWTBot, SWTBotTreeItem, String)}.
*
* @param tree the tree to search
* @throws TimeoutException if all of the direct children of the tree do not have text within the
* timeout period
*/
public static void waitUntilTreeHasText(SWTBot bot, final SWTBotTreeItem tree)
throws TimeoutException {
// Attempt #1
if (!waitUntilTreeHasTextImpl(bot, tree.widget)) {
// Attempt #2: Something went wrong, try to cautiously reopen it.
bot.sleep(1000);
// There isn't a method to collapse, so double-click instead
tree.doubleClick();
bot.waitUntil(new TreeCollapsedCondition(tree.widget));
bot.sleep(1000);
tree.expand();
bot.waitUntil(new TreeExpandedCondition(tree.widget));
if (!waitUntilTreeHasTextImpl(bot, tree.widget)) {
printTree(tree.widget);
throw new TimeoutException(
"Timed out waiting for text of the tree's children, giving up...");
}
}
}