Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Tiede2015-06-01 07:49:08 +0000
committerMarkus Tiede2015-06-01 07:49:08 +0000
commitf04fd34ee697d69564a9d4ec76f18735ca251e6b (patch)
tree14da7513fcc4240dce1e097ff23b4568114c6921 /org.eclipse.jubula.client.api
parentd682bdc32fd63068cbded818501df5e6f925d402 (diff)
downloadorg.eclipse.jubula.core-f04fd34ee697d69564a9d4ec76f18735ca251e6b.tar.gz
org.eclipse.jubula.core-f04fd34ee697d69564a9d4ec76f18735ca251e6b.tar.xz
org.eclipse.jubula.core-f04fd34ee697d69564a9d4ec76f18735ca251e6b.zip
Sprint task - allow screenshots to be taken (e.g. on errors) via the API
Diffstat (limited to 'org.eclipse.jubula.client.api')
-rw-r--r--org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/AUT.java10
-rw-r--r--org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/internal/impl/AUTImpl.java46
2 files changed, 56 insertions, 0 deletions
diff --git a/org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/AUT.java b/org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/AUT.java
index 5a6cb51a9..607b6fe55 100644
--- a/org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/AUT.java
+++ b/org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/AUT.java
@@ -10,6 +10,8 @@
*******************************************************************************/
package org.eclipse.jubula.client;
+import java.awt.image.BufferedImage;
+
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.jubula.client.exceptions.CommunicationException;
import org.eclipse.jubula.client.exceptions.ExecutionException;
@@ -55,4 +57,12 @@ public interface AUT extends Remote {
* the exception handler for this AUT; may be <code>null</code>.
*/
void setHandler(@Nullable ExecutionExceptionHandler handler);
+
+ /**
+ * @return a screenshot of the AUTs primary display.
+ *
+ * @throws IllegalStateException
+ * in case of e.g. being called when not connected to an AUT
+ */
+ @Nullable BufferedImage getScreenshot() throws IllegalStateException;
} \ No newline at end of file
diff --git a/org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/internal/impl/AUTImpl.java b/org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/internal/impl/AUTImpl.java
index 7cc919fb7..3b3febac2 100644
--- a/org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/internal/impl/AUTImpl.java
+++ b/org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/internal/impl/AUTImpl.java
@@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.jubula.client.internal.impl;
+import java.awt.image.BufferedImage;
import java.net.ConnectException;
import java.util.Map;
@@ -32,7 +33,10 @@ import org.eclipse.jubula.client.internal.exceptions.ConnectionException;
import org.eclipse.jubula.communication.CAP;
import org.eclipse.jubula.communication.internal.message.CAPTestMessage;
import org.eclipse.jubula.communication.internal.message.CAPTestResponseMessage;
+import org.eclipse.jubula.communication.internal.message.Message;
import org.eclipse.jubula.communication.internal.message.MessageCap;
+import org.eclipse.jubula.communication.internal.message.TakeScreenshotMessage;
+import org.eclipse.jubula.communication.internal.message.TakeScreenshotResponseMessage;
import org.eclipse.jubula.communication.internal.message.UnknownMessageException;
import org.eclipse.jubula.toolkit.ToolkitInfo;
import org.eclipse.jubula.toolkit.internal.AbstractToolkitInfo;
@@ -40,6 +44,7 @@ import org.eclipse.jubula.tools.AUTIdentifier;
import org.eclipse.jubula.tools.internal.i18n.I18n;
import org.eclipse.jubula.tools.internal.objects.event.TestErrorEvent;
import org.eclipse.jubula.tools.internal.registration.AutIdentifier;
+import org.eclipse.jubula.tools.internal.serialisation.SerializedImage;
import org.eclipse.jubula.tools.internal.xml.businessmodell.ComponentClass;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -227,4 +232,45 @@ public class AUTImpl implements AUT {
@Nullable ExecutionExceptionHandler handler) {
m_handler = handler;
}
+
+ /** {@inheritDoc} */
+ public BufferedImage getScreenshot() throws IllegalStateException {
+ if (isConnected()) {
+ Message message = new TakeScreenshotMessage();
+ try {
+ m_instance.send(message);
+
+ Object exchange = Synchronizer.instance().exchange(null);
+ if (exchange instanceof TakeScreenshotResponseMessage) {
+ TakeScreenshotResponseMessage response =
+ (TakeScreenshotResponseMessage) exchange;
+
+ return SerializedImage.computeImage(
+ response.getScreenshot());
+ }
+ log.error("Unexpected response received: " //$NON-NLS-1$
+ + String.valueOf(exchange));
+ } catch (NotConnectedException nce) {
+ if (log.isErrorEnabled()) {
+ log.error(nce.getLocalizedMessage(), nce);
+ }
+ } catch (IllegalArgumentException e) {
+ if (log.isErrorEnabled()) {
+ log.error(e.getLocalizedMessage(), e);
+ }
+ } catch (org.eclipse.jubula.tools.internal.
+ exception.CommunicationException e) {
+ if (log.isErrorEnabled()) {
+ log.error(e.getLocalizedMessage(), e);
+ }
+ } catch (InterruptedException e) {
+ if (log.isErrorEnabled()) {
+ log.error(e.getLocalizedMessage(), e);
+ }
+ }
+ } else {
+ throw new IllegalStateException("No AUT connection!"); //$NON-NLS-1$
+ }
+ return null;
+ }
} \ No newline at end of file

Back to the top