0

I am exploring the usage of SWTWorkbenchBot to use in my automation of an eclipse-based project. However, something seems weird when trying to get the "Console" view.

SWTWorkbenchBot workbenchBot = new SWTWorkbenchBot();
String consoleTitle = "Console";
try {
  workbenchBot.viewByTitle(consoleTitle).show();
  System.out.println("Got the Console view");
} catch (Exception e) {
  for (SWTBotView view : workbenchBot.views()) {
    System.out.println(view.getTitle() + "\t" + v.getTitle().equals(consoleTitle));
  }
}

From the above code, I assume one of the following 2 cases holds:

  • Either the code will exit with "Got the Console view" message printed
  • Or the message "Got the Console view" message NOT printed because the "Console" view was not found and an exception of type WidgetNotFoundException is thrown and the code inside the catch will be executed. The output should NOT contain the title "Console" or at least, next to all view titles, false should be printed.

Surprisingly, this is not happening. The message "Got the Console view" is NOT printed, yet if you look at the list of the view, you see that there exists a line Console true which means that the SWTWorkbenchBot could not get the console view using the method .viewByTitle() but he knows that exists by checking the .views() content.

The above code works fine for any view except for the Console view. Am I doing something wrong here? Thanks in advance.

user3396919
  • 141
  • 1
  • 10

2 Answers2

1

If I look into my running Eclipse the View is called "Console (General)". You really should not rely on any names if you have the possibility to reference the view with an Id, check if the follwing snippet will work

workbenchBot.viewById("org.eclipse.ui.console.ConsoleView").show();

Just a sidenote: You should make ui Test code a bit more robust, UI tests tend to fail caused by timings, ui-states, overlapping windows, so fail early with a clear statement why the test failed.

[...]
SWTBotView view = workbenchBot.viewByTitle(consoleTitle);
assertNotNull("Console was not found", view);
try {
  view.show()
} catch (Exception e) {
  fail("Error occured while opening console")
}
[...]
Tom Seidel
  • 9,525
  • 1
  • 26
  • 38
  • Is there any reference for built-in IDs for views\controls\something? Where did you find "org.eclipse.ui.console.ConsoleView"? – The Godfather May 22 '17 at 15:45
  • 1
    You can use the handy tool called "Plugin-Spy". To get for example the view-id just open the view in your Eclipse IDE and press Shift+Alt+F1. A popup will appear with the desired information. – Tom Seidel May 22 '17 at 20:48
0
new SWTWorkbenchBot().viewByPartName("Console").show(); 

should do the job.

What you see in the UI is the value returned by org.eclipse.ui.IWorkbenchPartReference.getPartName() but not the value returned by org.eclipse.ui.IWorkbenchPartReference.getTitle().

Marteng
  • 1,179
  • 13
  • 31