IntelliJ Idea how can I set an audio notification when a breakpoint is reached? - intellij-idea

With the IntelliJ Idea, when setting a breakpoint that doesn't hit frequently (or not at all), I leave my computer. I'll return ~every 10 minutes to check if the breakpoint has been reached. This process would make use of my time more efficient if I could hear when the breakpoint has been reached. Is this possible?
EDIT:
1) The following works as code, but I need to execute an .mp4 file instead of .app. See the second block of code for that attempt, which doesn't work.
2) Though the code works for .app, how would I set the breakpoint to execute that code when it is reached?
This works as code:
try {
Runtime.getRuntime().exec("/usr/bin/open -a iTunes.app");
} catch (IOException e) {
e.printStackTrace();
}
This doesn't
try {
Runtime.getRuntime().exec("MacintoshHD/Users/myusername/Music/iTunes/iTunes Media/Tones -a 01 Zelda Gets Item Alert Tone.m4a");
} catch (IOException e) {
e.printStackTrace();
}
btw, I did try putting quotes around the path items that had spaces. That didn't work either.

Add this to Evaluate and log:
Clip clip = AudioSystem.getClip();
AudioInputStream inputStream = AudioSystem.getAudioInputStream(new File("some.wav"));
clip.open(inputStream);
clip.start();
Thread.sleep(10000);
or execute some application to do it:
try {
Runtime.getRuntime().exec("\"C:\\Program Files (x86)\\Winamp\\winamp.exe\" \"C:\\some.mp4\"");
} catch (IOException e) {
e.printStackTrace();
}

If you are on Windows, you can create a very simple script in powershell, which will making a beeping sound whenever it is ran. (This will run at frequency 500 for 3 seconds).
[console]::beep(500,3000)
Then in the evaluate section of the debugger just add a watch variable that calls the script using powershell:
Runtime.getRuntime().exec("powershell.exe \"C:\\Users\\myusername\\test.ps1\"")

Related

How to skip particular WebElement process when locator is not found?

prinBalAgencyComm.sendKeys(testData.get("agencyCommissionPB"));
prinBalClientRem.sendKeys(Keys.TAB);
prinBalFrom2.sendKeys(testData.get("fromFB2")); //Locator not found
prinBalAgencyCommLast.sendKeys(testData.get("agencyCommissionLastPB")); //how to execute this line without fail
You can handle this by using try catch finally.
try{
//code that can result in an exception
prinBalAgencyComm.sendKeys(testData.get("agencyCommissionPB"));
prinBalClientRem.sendKeys(Keys.TAB);
prinBalFrom2.sendKeys(testData.get("fromFB2"));
}catch(Exception e)
{
//actions you want to take in case your locator isnt found or another exception occurs
System.out.println("Exception occured" + e.getMessage());
}finally
{ //the line to be executed without fail
prinBalAgencyCommLast.sendKeys(testData.get("agencyCommissionLastPB"));
}
you would have to implement a try/catch block
try {
element action
} catch (Exception e) {
//whatever you want to happen when it fails
}`
But I would ask myself why is the test not consistent with every run? Why should this step not pass every time?
One pattern you can use is:
try {}
catch {}
Place your offending code in the try block and any error code in the catch block.
If an exception is raised in the try, the catch block will be called instead of proceeding to the next line in the try

Getting contents of system clipboard on headless linux server for automated testing

I am trying to run some selenium cases on a headless linux system through docker in which the "user" clicks a button that copys text to the system clipboard. When I run this code, I get an error that says "No X11 DISPLAY variable was set, but this program performed an operation which requires it."
I am now running the case using xvfb to account for the lack of X11 Display variable, but the code still does not work. Now, I am getting a nullpointer when trying to access the contents of the system clipboard.
Here is the code that I am running to get the copied text.
String copied = null;
try {
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
Transferable transferable = clipboard.getContents(null);
DataFlavor[] availableFlavors = clipboard.getAvailableDataFlavors();
if ( transferable != null && transferable.isDataFlavorSupported(DataFlavor.stringFlavor) ) {
copied = (String)transferable.getTransferData(DataFlavor.stringFlavor);
} else {
System.out.println("Could not find a suitable flavor.");
if ( transferable.getTransferDataFlavors().length == 0 ) {
System.out.println("no supported flavors");
}
for ( DataFlavor availableFlav : availableFlavors ) {
System.out.println("availableFlav = " + availableFlav);
}
for ( DataFlavor flavaflav : transferable.getTransferDataFlavors() ) {
System.out.println("transferDataFlavor = " + flavaflav);
}
}
// I am not sure what could cause the below exceptions to happen, but we should just fail the case if they occur.
} catch (IOException e) {
e.printStackTrace();
fail("IOException while fetching copied text.");
} catch (UnsupportedFlavorException e) {
e.printStackTrace();
fail("UnsupportedFlavorException while fetching copied text.");
}
return copied;
Running this code with xvfb is resulting in the following output:
Could not find a suitable flavor.
no supported flavors
And then throws the NullPointerException.
Is there a way to fake a system clipboard that actually works in this headless linux server?
What might be causing the system clipboard running in xvfb to have nothing copied?

Primefaces p:fileUpload - do something on beginning and end of upload (multiple files)

Primefaces 4.0 has nice component to upload files, including multiple files at once. By some dark miracle, it actually works.
Code:
<p:fileUpload fileUploadListener="#{someBean.handleSingleFileUpload}"
mode="advanced" multiple="true" auto="true" dragDropSupport="true"
update=":form_info" sizeLimit="100000" allowTypes="/(\.|\/)(xml)$/" />
Problem is that listener someBean.handleSingleFileUpload is called once for each file. I dealt with that nicely, but I cannot see any way to execute some code at beginning and on end of entire upload process. IMO rather large oversight.
For example:
at beginning clear info textarea
now multiple files are uploaded simultaneously...
at end reload something based on data that was just uploaded
Of course, things at beginning and end should be executed only once, regardless of amount of files. Is there any way to do that? In primefaces docs for p:fileUpload there are no other attribute calling bean method than fileUploadListener.
Well, I ended up simply using counter. Obvious in hindsight, eh. Example:
private int eventCounter = 0;
public void handleSingleFileUpload(FileUploadEvent event)
{
beginImport();
try
{
// code to import file, for example parse xml
} catch (Exception ex)
{
ex.printStackTrace(); /// or whatever
} // block catch Exception
finally
{
finishImport();
} // block finally
}
private synchronized void beginImport()
{
if (eventCounter == 0)
{
// insert code to execute before first file is started
} // block if just started
eventCounter++;
}
private synchronized void finishImport()
{
eventCounter--;
if (eventCounter < 0) eventCounter = 0; // Just in case...
if (eventCounter > 0) return; // not really finished yet
// insert code to execute when last file is done
}
It is hackish solution and I fear that in some cases it could call begin-n-finish pair twice (it should not do begin or finish code twice in row) and that could theoretically interfere with ongoing import of n-th file.
It works for me, at least for now. Will see how it holds when xml will have thousands or more of entries instead of dozen. I would prefer something like onStartOfEverything and onEndOfEverything as arguments in p:fileUpload tag, but ah well.

Erroring with PetrelLogger.NewAsyncProgress

I am using the PetrelLogger.NewAsyncProgress which seems to work well. However I can't figure out how to report an error with my task. Once I Dispose of the NewAsyncProgress, it reports 'Success' for my task.
I have tried setting the ProgressStatus = -1, but that didn't make a difference.
Example:
using (_asyncProgress = PetrelLogger.NewAsyncProgress("Doing Job", ProgressType.Default, (AsyncProgressCanceledCallback)AsyncProgressCanceled, this))
{
try
{
//Do Something
_asyncProgress.ProgressStatus = 100;
}
catch (Exception e)
{
//Error happened
_asyncProgress.ProgressStatus = -1;
}
}
So if an exception is thrown, the task manager result is Success 100%. Any ideas?
It's not possible in Ocean at the moment. However, we have such requirement recorded, so it can be implemented in one of future releases

How to handle Selenium timeout effectively?

Selenium.WaitForPageLoad("50000");
Selenium.Click("title");
Most times when it takes more than 50000, I get Timeout error. I do not want to increase the time. Is there a way to give it something like "take as long as you want"?
I don't recommend it, but if you want selenium to wait indefinitely, use a try-catch block and a loop:
while (true)
{
try
{
Selenium.WaitForPageLoad("5000");
break; //executed if page finished loading
}
catch (Exception)
{
//ignore the timeout exception
}
}
Again this is probably a bad idea, timeouts are generally a good thing. Depending on what you are trying to do you might want to consider checking if a particular element has finished loading as opposed to the whole page.
Are you sure you want it to take as long as it takes? It could hang all day...
I generally found if it takes ages to run, it had already failed a long time before.
I have used WatiN before and you can use a .WaitUntil() command to check that a specific element on the page has been loaded. Not sure what the equivalent in Selenium would be.
This link may help, if you're happy creating add-ins:
http://release.seleniumhq.org/selenium-remote-control/0.9.0/doc/java/com/thoughtworks/selenium/Wait.html
Have you tried to reverse the order of these commands?
Selenium.Click("title");
Selenium.WaitForPageToLoad("50000");
Or simply use:
Selenium.ClickAndWait("title");
This works for me
/**
* Put the Thread to Sleep for the specific time
* #param delay
*/
private void sleep(long time) {
try {
Thread.sleep(time);
} catch (InterruptedException e) {
}
}
//Inside my Test Method
//check if the element is loaded
while (!webElement.isLoaded) {
//sleep for a sec
sleep(1000);
}