-
Notifications
You must be signed in to change notification settings - Fork 44
Editors
The main interface to interact with editors in RedDeer is Editor
from org.jboss.reddeer.workbench.api
plugin. Whenever you implement new editor, this is the interface to begin with.
-
DefaultEditor
is the most basic implementation of editors in RedDeer. This class should be used, whenever you need nothing more than basic operations (open, close, save, check whether is editor dirty, content assist, ...) -
TextEditor
is extension ofDefaultEditor
and on top of it provides text operations for searching, selecting and altering text within this editor. This class should in general be used with eclipse editors implementingITextEditor
. -
BrowserEditor
, from pluginorg.jboss.reddeer.eclipse
is extension of AbstractEditor and is used for instances oforg.eclipse.ui.internal.browser.WebBrowserEditor
. It provides standard browser operations as forward, reload, change url, ...
package org.jboss.reddeer.snippet.test;
import org.jboss.reddeer.junit.runner.RedDeerSuite;
import org.jboss.reddeer.workbench.api.Editor;
import org.jboss.reddeer.workbench.impl.editor.DefaultEditor;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(RedDeerSuite.class)
public class EditorTest {
@Test
public void test(){
//Currently active editor will gain focus or the first available
Editor editor = new DefaultEditor();
// some logic here
// This will save&close currently active editor
editor.close(true);
}
}
This is the most basic test scenario. This test focuses currently active editor (editor which is currently visible), execute some desired actions and save&close the editor - close(boolean save)
.
All editors extending AbstractEditor can use QuickFix assistant. QuickFix is always invokend using proper key combination. If none is found, QuickFix assistant will fail.
package org.jboss.reddeer.snippet.test;
import org.jboss.reddeer.jface.text.contentassist.ContentAssistant;
import org.jboss.reddeer.junit.runner.RedDeerSuite;
import org.jboss.reddeer.workbench.impl.editor.TextEditor;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(RedDeerSuite.class)
public class QuickFixTest {
@Test
public void test() {
TextEditor textEditor = new TextEditor();
textEditor.selectText("JavaClass");
ContentAssistant ca = textEditor.openQuickFixContentAssistant();
ca.chooseProposal("Rename in file");
}
}
All editors extending AbstractEditor can use code assistant. Code Assist is always invokend using proper key combination. If none is found, code assist will fail.
package org.jboss.reddeer.snippet.test;
import org.jboss.reddeer.jface.text.contentassist.ContentAssistant;
import org.jboss.reddeer.junit.runner.RedDeerSuite;
import org.jboss.reddeer.workbench.impl.editor.TextEditor;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(RedDeerSuite.class)
public class CodeCompletionTest {
@Test
public void test() {
TextEditor textEditor = new TextEditor();
ContentAssistant ca = textEditor.openContentAssistant();
ca.chooseProposal("enum");
}
}
All editors extending AbstractEditor can use OpenOn assistant. OpenOn is always invokend using proper key combination. If none is found, OpenOn assist will fail.
package org.jboss.reddeer.snippet.test;
import org.jboss.reddeer.jface.text.contentassist.ContentAssistant;
import org.jboss.reddeer.junit.runner.RedDeerSuite;
import org.jboss.reddeer.workbench.impl.editor.TextEditor;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(RedDeerSuite.class)
public class OpenOnTest {
@Test
public void test() {
// lets say that MyClass.java contains basic priltln hello world code
TextEditor textEditor = new TextEditor("MyClass.java");
// select println in editor
textEditor.selectText("println");
// open OpenOn assistant
ContentAssistant ca = textEditor.openOpenOnAssistant();
// choose some proposal
ca.chooseProposal("Open Declaration");
// for selected println, Open Declaration choice opens PrintStream.class class
new TextEditor("PrintStream.class");
}
}
It's also possible to check validation markers. Also As-You-Type markers are supported.
package org.jboss.reddeer.snippet.test;
import static org.junit.Assert.*;
import org.jboss.reddeer.common.wait.AbstractWait;
import org.jboss.reddeer.common.wait.TimePeriod;
import org.jboss.reddeer.junit.runner.RedDeerSuite;
import org.jboss.reddeer.workbench.impl.editor.TextEditor;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(RedDeerSuite.class)
public class MarkersValidationTest {
@Test
public void test() {
// lets say that MyClass.java contains basic priltln hello world code
TextEditor textEditor = new TextEditor("MyClass.java");
// Change System to Systemx - we will artificially create some validation
// marker since Systemx cannot be resolved
textEditor.setText(textEditor.getText().replace("System", "Systemx"));
textEditor.save();
// wait for validation
AbstractWait.sleep(TimePeriod.SHORT);
assertEquals("Systemx cannot be resolved",
textEditor.getMarkers().get(0).getText());
}
}