SWTWorkbenchBot not able to find "Console" view - eclipse

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.

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")
}
[...]

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().

Related

How to click on copy button with cypress

So in my app i have a button and when i click on it, it will save some text into my clipboard, then i can past it by ctrl+v somewhere.
And i am trying to write cypress test for this. Problem is, when i click on that button i got cypress error:
I can´t figured out. Element is clearly viewed on page. I tryied to wait few second before clicking and it didn´t help.
Is there a way how to test it?
Thank you for your answers.
Your application has thrown an error, not cypress. To avoid this, you will want to add this either to your test file or /support/index.js. This code was pulled from this example. Remember cy. requires a test or a hook to work, while Cypress. does not.
// inspect the caught error
cy.on('uncaught:exception', (e) => {
if (e.message.includes('Things went bad')) {
// we expected this error, so let's ignore it
// and let the test continue
return false
}
// on any other error message the test fails
})
You can catch exceptions globally by writing this under cypress/support/index.js
Cypress.on('uncaught:exception', (err, runnable) => {
return false
})

PowerShell Forms, Try/Catch Not Stopping Application Properly

Problem
I am working with PowerShell to create an application that uses a GUI created using Forms. While trying to maintain a modular programming style, I have more or less slammed into a wall that I cannot seem to find a way around, and was hoping the community could help.
In my application, I am trying to create custom error catching utilizing try/catch statements, but have found that when I call upon a factory function and that function has an error, the application will display said error as intended, but will continue to process as if it was successful...
I have even tried using exit and break, but end up with an "Unhandled Exception" error that immediately follows my custom error. I have even set $ErrorActionPreference = "Stop" but still get this problem.
Here is a simplified sample of my code so that you can see what is happening:
Button_Click = {
ValidatePathing -BackupPath $BackupPath.Text
If (!(Test-Path $BackupPath.Text)) {
# Attempt to Create it
}
# bunch of code
}
Function ValidatePathing ([string]$BackupPath){
Try {
If (!$BackupPath) {
throw "customError1"
}
If ($BackupPath -match "\|") {
throw "customError2"
}
}
Catch {
If ($_.Exception.Message -eq "customError1") {
[System.Windows.Forms.MessageBox]::Show("some message")
}
ElseIf ($_.Exception.Message -eq "customError2") {
[System.Windows.Forms.MessageBox]::Show("some message")
}
}
}
Unfortunately, when the code hits a section like ValidatePathing and a custom error happens, the error message will display as expected, but the code will then step over/through the section and continues to process the rest of the code, despite the error.
Question
Does anyone know PowerShell well enough to explain how to properly handle a situation like this so that the code stops running after hitting a nested error like this?
To be sure your Try is being handed a terminating error as it's designed to handle, utilize $PSCmdlet.ThrowTerminatingError(). This can take an ErrorRecord object as a constructor, allowing you to catch specific exception types.

Getting the stack trace of the error origin in swift

Consider this code:
func doSomething() throws {
try callThrowingFunction1()
try callThrowingFunction2()
}
func userAction() {
do {
try doSomething()
} catch {
// display and log error
}
}
Say those inner functions can throw the same kind of errors and I would like to know if an error occurred in callThrowingFunction1() or in callThrowingFunction2().
As long as I'm in the debugger I can set a breakpoint for Swift errors on swift_willThrow, but if I would like to log the call stack on a user device, is there a way to do that?
Swift errors have no such thing as stack-trace yet (if will ever), and even Xcode can show stack-trace only if the error is un-handled by our code (and gets caught by Xcode directly instead).
Alternativly, your custom Error's constructor can store the stack-trace for later use, but in most cases errors are not custom, where you can't alter error's constructor (like errors of 3rd-party library).
But we can at least print stack-trace of where error(s) get catched, like:
do {
try ... // something that throws goes here
} catch let error as NSError {
print("Error: \(error)")
println(NSThread.callStackSymbols())
}
Exception breakpoint
If you just want to debug, without need to upload stack-trace to server, then Xcode's "Exception breakpoint" feature can help, like:
First place a normal-breakpoint near the failing logic.
Wait until Xcode pauses App on that line, enable Xcode's feature:
Finally, resume App, and wait untill exception is thrown.
Images are old, nowadays you see "Add Swift Error Breakpoint" or something like that as well (beside "Add Exception Breakpoint" option).

Eclipse Debugging is being executed or not

During debugging an Application ,
Assume taht a line of execution is taking a lot of time , how can we know that Eclipse still in the process of Debugging ??
For example assume that the method client.submitOrder() shown below is taking 5 mins to get executed ??
Is there any Indication shown anywhere that eclipse is still running that method ??
public void test()
{
try
{
ServiceResponse response = client.submitOrder(request);
System.out.println("Doen")
}
catch(Exception e)
{
e.printStackTrace();
}
}
Assuming that you have started the application in Debug mode and if you are in the Debug View, the thread executing the method shows that the method it is in Stepping state.
I don't have a screenshot for this at the moment, but will try to upload one soon.

Inconsistent output to Eclipse Console View

I am invoking a compiler command but the compiler messages are not getting displayed in the Eclipse Console View consistently.
I have my launch() method implemented the same way as first code block of
this question; I have the command-line string setup which I use to call DebugPlugin.exec() method. However, unlike the the author of the question above, my output Eclipse console is very inconsistent. T
There is no activity in the console when I invoke the command and the console continues to display the "No console to display at this time." But after invoking the command numerous time and activating different consoles from the drop-down menu, the console occasionally does become active and message is displayed.
I am confused with how the eclipse is behaving and not sure how to resolve this issue. Any comment and/or recommendation would be appreciated.
Thanks!!
--
EDIT
To add some more info, running the external process using External Tools works fine. I add the compiler process c:\path\myprocess.exe in Locations field and the file to compile in the Arguments field within the External Tools Configuration window. When I run it, all the output is displayed fine. It just won't display when I run it programmatically through LaunchConfigurationDelegate class.
Maybe try bringing the console to front programmatically see if it helps:
* Bring the console to front.
*/
public static void showConsole() {
Display.getDefault().asyncExec(new Runnable() {
#Override
public void run() {
IWorkbenchWindow window = CUIPlugin.getActiveWorkbenchWindow();
if (window != null) {
IWorkbenchPage page = window.getActivePage();
if (page != null) {
IViewPart consoleView =
page.findView(IConsoleConstants.ID_CONSOLE_VIEW);
if (consoleView == null) {
IWorkbenchPart activePart = page.getActivePart();
try {
consoleView =
page.showView(IConsoleConstants.ID_CONSOLE_VIEW);
} catch (PartInitException pie) {
CUIPlugin.log(pie);
}
// restore focus stolen by the creation of the
// console
page.activate(activePart);
} else {
boolean bringToTop = true;
if (bringToTop) {
page.bringToTop(consoleView);
}
}
}
}
}
});
}
Finally got it to work. The main change I've made is having my MyLaunchConfigurationDelegate extend LaunchConfigurationDelegate instead of just implementing ILaunchConfigurationDelegate. When observed through the debugger, the launch() method went through similar code path as external process that was launched via External Tools when MyLaunchConfigurationDelegate extended LaunchConfigurationDelegate.
I guess it was lack of information on my part but I wasn't sure which part of the code was more important to share.
Another piece of code that was removed was:
IProcess dbgProcess = DebugPlugin.newProcess(launch, compilerProcess, "XVR Compiler", processAttributes);
...
launch.removeProcess(dbgProcess);
I've added it while attempting different approach in debugging this issue and it actually caused more issues by removing the debugProcess before it has chance to display output to the console.