I doubt whether there's a solution to this but thought I'd ask anyway.
java.awt.Robot is very useful for unit testing, to simulate user input/action. The trouble is you can't then do anything else on your comp for the duration of the test, because the Robot keyPresses, etc., will then start happening in the application which has focus at the time, not in the app which you are subjecting to testing...
Even if you precede every such Robot command with requestFocus or some such this is not a solution for the simple reason that between such commands, which must be run in the EDT, and the Robot's command, which must be run in a non-EDT thread, you may happen to do sthg (keyboard or mouse action) which will transfer focus outside the test app.
I think therefore that a Robot which knows it must interact only with the test app is kind of essential. Without that you "lose" your machine for the duration of the tests.
Running the tests in a VM might be one solution - does anyone know of any other?
Related
We have a a Java app that takes a few registers off a database and sends them back and forth to a web service, nothing too complicated. This java app has a GUI that informs the user about what's going on with the operations it performs, as well as providing means for configuring certain aspects of its execution and giving the user the opportunity to deal with errors that may happen.
The thing is, this application needs to run all the time, even if the user isn't logged on. I tried setting a windows task to make it run when the computer starts, but if that happens the program runs on the background and the interface never comes up.
We could break the interface away from the main project and make them run separately, so the service runs on the background quietly and the user is free to open and close the interface to their heart's content, but unfortunately we suffer from coupling problems in our project which makes that road a little more arduous than it should be.
So the question is: Is there a way to set a service up so that it runs even when the user isn't logged in, but once he does, the interface also comes up?
Our only target platform is, for now, Windows.
to your question : "Is there a way to set a service up so that it runs even when the user isn't logged in, but once he does, the interface also comes up?" the response is Yes and called JavaExe.
look its examples in JavaExe.zip, in particular example8 or 23
Only separation of UI is an answer here. Downgrading to XP doesn't make sense. You can also simply build that as a webapp and try to leverage esbeetle.com for interfaceing and doing all the logic.
Right, my title probably made no sense. However I'll explain it now.
I have a program coded in C++ that I wish to allow a keycombo to be pressed to run the program. My program does not run all the time it only runs when clicked then closes when the operation is complete. It simply does it's function then closes itself. Now here is the question.
Would it be simpler to attempt to edit my C++ program to run all the time via a thread in a class that then called the other class to run that did the function then stopped and listened for keypress again.
Or
Create a Java program that runs all the time and listens for a keyEvent and upon doing so runs the other programs exe. Then bundle the exe and jar in to one exe that is installed and run so they have access to each other.
If I did it this way is it even possible as far as I know key events need to have focus to be able to be detected. Meaning that I would need to be running the program as my main window to detect it? Or is that not true.
I'd looked at the java route as my Java is better than my C++. Is this do-able and if so what approach would be the better one?
Hope this is explained well enough let me know otherwise.
I have a program which uses the Robot class in Java to automate a bunch of keypresses and clicks. The problem I am encountering is not being able to set breakpoints on certain methods to debug because the focus would change when I skip to the next expression.
Is there a way I can bypass this by changing the default continue hotkey (F8) in NetBeans to a low-level keyboard hook that will check system wide?
The reason for this is because the macro I am designing runs too fast for me to see each action occurring. If I set breakpoints along the program, I must alt-tab to the IDE and continue to the next breakpoint, which, unfortunately, interferes with the macro.
If you need to interact with the system in a way that interferes with your program, you must separate your debugger from your program.
In other words, run the two on separate machines and do a remote debug from one machine to another.
The easiest way to do so if you don't have or want to use two machines, is to run your program in a virtual machine. A cheap solution is to use vmware player along with a Linux distribution supported by Netbeans.
Whenever i want to connect to internet,i double click a connection icon(i created it earlier where username and password(for broadband) are stored) and click connect.The icon is in the network places(Windows XP)
May i know how to launch this connection from java or any other language? (I am asking this because my Internet Service Provider doesn't charge anything between 2 AM and 8AM :-) )
Creating a system task to run the program. You shouldn't need Java to execute a program on windows.
To use Scheduled Tasks in XP: http://support.microsoft.com/kb/308569
This is going to be unnecessarily difficult with Java, I believe. You'd have to write some native code to do the job for you, at which point you may as well write your whole program in C# or C++ anyway.
But, since you asked for a Java approach, you might want to look at the Robot class. It lets you move the mouse to a specific location on the screen, click, and otherwise automate the manual actions that you are doing. It's a very fragile solution.
Alternatively, if you can figure out what command the network connection shortcut is invoking, you can directly invoke it from Java using Runtime.exec.
(I don't really see why Java is good for this task, though.)
I have a test that exercises a custom Swing component using java.awt.Robot. I'd like to run the test in our build server, but the build servers run on locked windows machines, and Robot.keyPress(char) doesn't work with the screen locked. The keystrokes I'm sending are sometimes things like down arrow and backspace, so sending them directly to the document isn't helpful.
Currently I'm just using junit's Assume to skip the tests if keyboard entry doesn't work on the first try, but I'd like to leave these test enabled. I would assume someone out there is running these kinds of tests against a Swing gui. Any ideas?
A stab in the dark: perhaps a VM (like VirtualBox) could be running in the background, but would for all intents and purposes be "awake and unlocked" as far as the robot knows. The virtual box would run your unit tests.
have you tried using the headless mode of java ?
I guess java.awt.Robot won't work in this case, since it specifically depends upon awt being loaded. in such a case, one should better rely upon gui testing frameworks, like the cool (and running in headless mode) fest-swing.