| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| SWTEclipseBot |
|
| 1.25;1.25 |
| 1 | 0 | /******************************************************************************* |
| 2 | * Copyright (c) 2008-2009 Ketan Padegaonkar and others. | |
| 3 | * All rights reserved. This program and the accompanying materials | |
| 4 | * are made available under the terms of the Eclipse Public License v1.0 | |
| 5 | * which accompanies this distribution, and is available at | |
| 6 | * http://www.eclipse.org/legal/epl-v10.html | |
| 7 | * | |
| 8 | * Contributors: | |
| 9 | * Ketan Padegaonkar - initial API and implementation | |
| 10 | * Ralf Ebert www.ralfebert.de - (bug 271630) SWTBot Improved RCP / Workbench support | |
| 11 | *******************************************************************************/ | |
| 12 | package org.eclipse.swtbot.eclipse.finder; | |
| 13 | ||
| 14 | import static org.eclipse.swtbot.eclipse.finder.matchers.WidgetMatcherFactory.withPartName; | |
| 15 | import static org.eclipse.swtbot.eclipse.finder.waits.Conditions.waitForEditor; | |
| 16 | import static org.eclipse.swtbot.eclipse.finder.waits.Conditions.waitForView; | |
| 17 | import static org.hamcrest.Matchers.allOf; | |
| 18 | import static org.hamcrest.Matchers.instanceOf; | |
| 19 | ||
| 20 | import java.util.ArrayList; | |
| 21 | import java.util.List; | |
| 22 | ||
| 23 | import org.eclipse.swtbot.eclipse.finder.waits.WaitForEditor; | |
| 24 | import org.eclipse.swtbot.eclipse.finder.waits.WaitForView; | |
| 25 | import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEclipseEditor; | |
| 26 | import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView; | |
| 27 | import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException; | |
| 28 | import org.eclipse.ui.IEditorReference; | |
| 29 | import org.eclipse.ui.IViewReference; | |
| 30 | import org.eclipse.ui.IWorkbenchPartReference; | |
| 31 | import org.hamcrest.Matcher; | |
| 32 | ||
| 33 | /** | |
| 34 | * This extends the {@link SWTWorkbenchBot} and adds specific capabilities for writing Eclipse IDE tests. | |
| 35 | * | |
| 36 | * @author Ketan Padegaonkar <KetanPadegaonkar [at] gmail [dot] com> | |
| 37 | * @author Ralf Ebert www.ralfebert.de (bug 271630) | |
| 38 | * @version $Id$ | |
| 39 | * @deprecated use {@link SWTWorkbenchBot}. This will be removed from future releases. | |
| 40 | */ | |
| 41 | public class SWTEclipseBot extends SWTWorkbenchBot { | |
| 42 | ||
| 43 | /** | |
| 44 | * Constructs an eclipse bot. | |
| 45 | * @deprecated use {@link SWTWorkbenchBot#SWTWorkbenchBot()} instead | |
| 46 | */ | |
| 47 | public SWTEclipseBot() { | |
| 48 | 0 | super(); |
| 49 | 0 | } |
| 50 | ||
| 51 | /** | |
| 52 | * Attempts to locate the editor matching the given name. If no match is found an exception will be thrown. The name | |
| 53 | * is the name as displayed on the editor's tab in eclipse. | |
| 54 | * | |
| 55 | * @param fileName the name of the file. | |
| 56 | * @return an editor for the specified fileName. | |
| 57 | * @throws WidgetNotFoundException if the editor is not found. | |
| 58 | * @deprecated use {@link SWTWorkbenchBot#editorByTitle(String)} | |
| 59 | */ | |
| 60 | public SWTBotEclipseEditor editor(String fileName) throws WidgetNotFoundException { | |
| 61 | 0 | return editor(fileName, 0); |
| 62 | } | |
| 63 | ||
| 64 | /** | |
| 65 | * Attempts to locate the editor matching the given name. If no match is found an exception will be thrown. The name | |
| 66 | * is the name as displayed on the editor's tab in eclipse. | |
| 67 | * | |
| 68 | * @param fileName the name of the file. | |
| 69 | * @param index in case of multiple views with the same fileName. | |
| 70 | * @return an editor for the specified fileName. | |
| 71 | * @throws WidgetNotFoundException if the editor is not found. | |
| 72 | * @deprecated use {@link SWTWorkbenchBot#editorByTitle(String)} | |
| 73 | * @since 2.0 | |
| 74 | */ | |
| 75 | @SuppressWarnings("unchecked") | |
| 76 | public SWTBotEclipseEditor editor(String fileName, int index) throws WidgetNotFoundException { | |
| 77 | 0 | Matcher matcher = allOf(instanceOf(IEditorReference.class), withPartName(fileName)); |
| 78 | 0 | WaitForEditor waitForEditor = waitForEditor(matcher); |
| 79 | 0 | waitUntilWidgetAppears(waitForEditor); |
| 80 | 0 | return new SWTBotEclipseEditor(waitForEditor.get(index), this); |
| 81 | } | |
| 82 | ||
| 83 | /** | |
| 84 | * Attempts to find the view matching the given label. If no match is found then an exception will be thrown. The | |
| 85 | * name is the name as displayed on the editor's tab in eclipse. | |
| 86 | * | |
| 87 | * @param label the label of the view. | |
| 88 | * @return a view with the specified label. | |
| 89 | * @throws WidgetNotFoundException if the view is not found. | |
| 90 | * @deprecated use {@link SWTWorkbenchBot#viewByTitle(String)} | |
| 91 | */ | |
| 92 | public SWTBotView view(String label) throws WidgetNotFoundException { | |
| 93 | 0 | return view(label, 0); |
| 94 | } | |
| 95 | ||
| 96 | /** | |
| 97 | * Attempts to find the view matching the given label. If no match is found then an exception will be thrown. The | |
| 98 | * name is the name as displayed on the editor's tab in eclipse. | |
| 99 | * | |
| 100 | * @param label the label of the view. | |
| 101 | * @param index in case of multiple views with the same label. | |
| 102 | * @return a view with the specified label. | |
| 103 | * @throws WidgetNotFoundException if the view is not found. | |
| 104 | * @deprecated use {@link SWTWorkbenchBot#viewByTitle(String)} | |
| 105 | * @since 2.0 | |
| 106 | */ | |
| 107 | @SuppressWarnings("unchecked") | |
| 108 | public SWTBotView view(String label, int index) throws WidgetNotFoundException { | |
| 109 | 0 | Matcher matcher = allOf(instanceOf(IViewReference.class), withPartName(label)); |
| 110 | 0 | WaitForView waitForView = waitForView(matcher); |
| 111 | 0 | waitUntilWidgetAppears(waitForView); |
| 112 | 0 | return new SWTBotView(waitForView.get(index), this); |
| 113 | } | |
| 114 | ||
| 115 | /** | |
| 116 | * Returns the list of all the open editors found in the active workbench. | |
| 117 | * | |
| 118 | * @return all the editors in the workbench. | |
| 119 | * @throws WidgetNotFoundException if there are errors finding editors. | |
| 120 | * @deprecated use {@link SWTWorkbenchBot#editors()} | |
| 121 | */ | |
| 122 | @SuppressWarnings("unchecked") | |
| 123 | public List<SWTBotEclipseEditor> editors() throws WidgetNotFoundException { | |
| 124 | 0 | Matcher matcher = allOf(instanceOf(IEditorReference.class)); |
| 125 | 0 | WaitForEditor waitForEditor = waitForEditor(matcher); |
| 126 | 0 | waitUntilWidgetAppears(waitForEditor); |
| 127 | ||
| 128 | 0 | List<IEditorReference> editors = waitForEditor.getAllMatches(); |
| 129 | 0 | List<SWTBotEclipseEditor> result = new ArrayList<SWTBotEclipseEditor>(editors.size()); |
| 130 | ||
| 131 | 0 | for (IWorkbenchPartReference editor : editors) { |
| 132 | 0 | result.add(new SWTBotEclipseEditor((IEditorReference) editor, this)); |
| 133 | } | |
| 134 | 0 | return result; |
| 135 | } | |
| 136 | ||
| 137 | /** | |
| 138 | * Returns the list of all the open views found in the active workbench. | |
| 139 | * | |
| 140 | * @return all the views in the workbench. | |
| 141 | * @throws WidgetNotFoundException if the views are not found. | |
| 142 | * @deprecated use {@link SWTWorkbenchBot#views()} | |
| 143 | */ | |
| 144 | @SuppressWarnings("unchecked") | |
| 145 | public List<SWTBotView> views() throws WidgetNotFoundException { | |
| 146 | 0 | Matcher matcher = allOf(instanceOf(IViewReference.class)); |
| 147 | 0 | WaitForView waitForView = waitForView(matcher); |
| 148 | 0 | waitUntilWidgetAppears(waitForView); |
| 149 | ||
| 150 | 0 | List<IViewReference> editors = waitForView.getAllMatches(); |
| 151 | 0 | List<SWTBotView> result = new ArrayList<SWTBotView>(editors.size()); |
| 152 | ||
| 153 | 0 | for (IWorkbenchPartReference editor : editors) { |
| 154 | 0 | result.add(new SWTBotView((IViewReference) editor, this)); |
| 155 | } | |
| 156 | 0 | return result; |
| 157 | } | |
| 158 | ||
| 159 | /** | |
| 160 | * Return the active editor. | |
| 161 | * | |
| 162 | * @return the active editor, if any | |
| 163 | * @throws WidgetNotFoundException if there is no active editor. | |
| 164 | * @since 1.1 | |
| 165 | * @deprecated use {@link SWTWorkbenchBot#activeEditor()} | |
| 166 | */ | |
| 167 | public SWTBotEclipseEditor activeEditor() throws WidgetNotFoundException { | |
| 168 | 0 | return super.activeEditor().toTextEditor(); |
| 169 | } | |
| 170 | ||
| 171 | } |