Skip to content

Commit

Permalink
jemmy output to robot log at debug level. Also SwingLirbary no longer…
Browse files Browse the repository at this point in the history
… extends AnnotationLibrary
  • Loading branch information
jussimalinen committed Jan 13, 2014
1 parent 3d4533b commit 8861c1b
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 10 deletions.
10 changes: 4 additions & 6 deletions src/main/java/org/robotframework/swing/SwingLibrary.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@
import org.netbeans.jemmy.TestOut;
import org.robotframework.javalib.library.AnnotationLibrary;
import org.robotframework.swing.keyword.timeout.TimeoutKeywords;
import org.robotframework.swing.util.StandardOutOutput;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;

public class SwingLibrary extends AnnotationLibrary {
public class SwingLibrary {
public static final String ROBOT_LIBRARY_SCOPE = "GLOBAL";
public static SwingLibrary instance;
private final AnnotationLibrary annotationLibrary = new AnnotationLibrary(
Expand Down Expand Up @@ -101,24 +102,20 @@ private void addKeywordPatterns(Collection<String> keywordPatterns) {
}
}

@Override
public Object runKeyword(String keywordName, Object[] args) {
return annotationLibrary.runKeyword(keywordName, toStrings(args));
}

@Override
public String[] getKeywordArguments(String keywordName) {
return annotationLibrary.getKeywordArguments(keywordName);
}

@Override
public String getKeywordDocumentation(String keywordName) {
if (keywordName.equals("__intro__"))
return LIBRARY_DOCUMENTATION;
return annotationLibrary.getKeywordDocumentation(keywordName);
}

@Override
public String[] getKeywordNames() {
return annotationLibrary.getKeywordNames();
}
Expand All @@ -128,7 +125,8 @@ private void setDefaultTimeouts() {
}

private void disableOutput() {
JemmyProperties.setCurrentOutput(TestOut.getNullOutput());
TestOut out = new StandardOutOutput();
JemmyProperties.setCurrentOutput(out);
}

private Object[] toStrings(Object[] args) {
Expand Down
54 changes: 54 additions & 0 deletions src/main/java/org/robotframework/swing/util/StandardOutOutput.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package org.robotframework.swing.util;

import org.netbeans.jemmy.TestOut;

import java.io.InputStream;
import java.io.PrintWriter;


public class StandardOutOutput extends TestOut {

public final long starterThreadId;


public StandardOutOutput() {
super((InputStream)null, (PrintWriter)null, (PrintWriter)null);
starterThreadId = Thread.currentThread().getId();
}

@Override
public void print(String line) {
log(line);
}

@Override
public void printLine(String line) {
log(line);
}

@Override
public void printTrace(String text) {
log(text);
}

@Override
public void printErrLine(String line) {
log(line);
}

@Override
public void printError(String text) {
log(text);
}

@Override
public void printStackTrace(Throwable e) {
log("Error in Jemmy:");
e.printStackTrace(System.out);
}

private void log(String msg) {
if (Thread.currentThread().getId() == starterThreadId)
System.out.println("*DEBUG:"+System.currentTimeMillis()+"* Jemmy: "+ msg);
}
}
8 changes: 4 additions & 4 deletions src/test/java/org/robotframework/swing/SwingLibrarySpec.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public void doesntContainKeywordsThatDontMatchDefaultPathPattern() {
specify(context.getKeywordNames(), must.not().contain("keywordThatShouldNotBeRegistered"));
}

public void printsNothingToStandardOut() {
public void outputsAreNull() {
specify(JemmyProperties.getCurrentOutput().getOutput(), must.equal(null));
specify(JemmyProperties.getCurrentOutput().getErrput(), must.equal(null));
}
Expand All @@ -33,7 +33,7 @@ public void setsTimeoutsTo5Seconds() {
}
}
}

public class HandlingArguments {
private AnnotationLibrary annotationLibrary;
private String keywordName = "someKeyword";
Expand All @@ -48,12 +48,12 @@ public void convertsArgumentsToString() {
Object[] arrayArgument = new Object[] { };
Object[] actualArguments = new Object[] { new Integer(2), Boolean.TRUE, arrayArgument };
final Object[] expectedArguments = new Object[] { "2", "true", arrayArgument };

checking(new Expectations() {{
one(annotationLibrary).runKeyword(keywordName, expectedArguments);
will(returnValue("something"));
}});

specify(context.runKeyword(keywordName, actualArguments), "something");
}
}
Expand Down

0 comments on commit 8861c1b

Please sign in to comment.