Introduction
This page shows some very basic but sometimes useful operations you can run on any system.
The list of all supported operations is wider than the provided here, use the class java doc to see all possible options.
First make an instance of the SystemOperations class:
SystemOperations systemOps = new SystemOperations( SERVER_IP );
If you want to work locally, use the constructor without any input arguments
Check the type of the operating system
systemOps.getOperatingSystemType();
Working with the system time
// get system time in milliseconds systemOps.getTime( true ); // get system time as string systemOps.getTime( false ); // set system time providing milliseconds systemOps.setTime( "1365753359278", true ); // set system time providing it as string systemOps.setTime( "03/30/13 10:00:00", false );
When get/set time using a formatted string, we expect some particular format. For example "03/30/13 10:00:00" means 10 o'clock on 30th of March 2013
Get a system property
String userHome = systemOps.getSystemProperty("user.home");
Check if some process is listening on some port on some host
The next code tells if there is a process attached at the given port on the given host.
Internally we will try to make a connection to that host and port and we will keep trying for up to the 10 seconds timeout.
systemOps.isListening( SERVER_IP, 8080, 10 );
We can only tell if some process is attached to that port, but we do not know what kind of process it is
Make a screenshot of the display and save it into a local file
systemOps.createScreenshot( "C:\\snapshot.png" );
Check the classpath
Java applications often suffer classpath issues. You may wonder what is in your classpath or whether some jar is present more than once.
The following example might be a good option for fighting classpath issues in your Test Executor or ATS Agents:
// get a list of entries in the classpath String[] classpathEntries = systemOps.getClassPath(); // just log the classpath entries systemOps.logClassPath(); // get a list of jars present more than once in the classpath String[] duplicatedJars = systemOps.getDuplicatedJars(); // just log the jars present more than once in the classpath systemOps.logDuplicatedJars();
Mouse works
Perform a left click at a given position
// having the top left display corner as starting point, // click 1000 pixels to the right and 200 pixels down systemOps.mouse.clickAt( 1000, 200 );
You should use this only in cases when you do not have an alternative.
This kind of operations are easy to break. For example, when the display is resized, the right coordinates will surely become wrong
Keyboard works
Below are given some of the currently provided operations.
systemOps.keyboard.pressEnter(); systemOps.keyboard.pressEsc(); systemOps.keyboard.pressTab(); systemOps.keyboard.pressAltF4(); systemOps.keyboard.type( "it is typing" );
You should use this only in cases when you do not have an alternative.
This kind of operations are easy to break. For example when a not expected system popup comes(the anti-virus program prompts you to update) then you will be sending your keyboard events to a wrong application.
Back to parent page
Go to Table of Contents
