I have written a helper method for testing if an editor is dirty.
- Code: Select all
public static boolean anyUnsavedChanges() throws Exception {
final boolean dirtyEditors[] = new boolean[]{false};
final String errorMessages[] = new String[]{""};
Display.getDefault().syncExec(new Runnable() {
public void run() {
try {
IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows();
for (int i = 0; i < windows.length; i++) {
IWorkbenchPage[] pages = windows[i].getPages();
for (int j = 0; j < pages.length; j++) {
IEditorReference[] editorRefs = pages[j].getEditorReferences();
for (int k = 0; k < editorRefs.length; k++) {
IEditorReference each = editorRefs[k];
if (each.isDirty()){
dirtyEditors[0] = true;
}
}
}
}
} catch(Exception e){
errorMessages[0] += e.toString() + e.getMessage();
}
}
});
if(errorMessages[0].length() > 0){
throw new Exception(errorMessages[0]);
}
return dirtyEditors[0];
}
Now I have the following test:
- Code: Select all
public void testDirtyAfterTextInput_TC_EX_r04() throws Exception {
IUIContext ui = getUI();
ui.keyClick(WT.CR);
ui.enterText("foobar");
assertTrue(EclipseHelper.anyUnsavedChanges());
}
The test is successful if running in normal mode. If running with a delay the test fails. The test should always fail, because after some input the editor is dirty of course.
That means I have to do some delay after the text is entered giving the editor a chance to signalize its status.
How can I do that? Anyone ideas?
Must be something like this:
- Code: Select all
ui.enterText("foobar");
getUI().wait(ActiveEditorCondition.forName("asmod_eng_inl1_fs.XML"));
assertTrue(EclipseHelper.anyUnsavedChanges());
or
- Code: Select all
ui.enterText("foobar");
getUI().wait(new JobsCompleteCondition());
assertTrue(EclipseHelper.anyUnsavedChanges());
But the editor is active of course and has no jobs running.
Probably I have to implement my own condition. But for what should I wait?
Michael