Skip to content

Commit

Permalink
#274 - New JSON file output forwarder introduced
Browse files Browse the repository at this point in the history
  • Loading branch information
Georgi Todorov committed Sep 27, 2017
1 parent 669f271 commit 30aecab
Show file tree
Hide file tree
Showing 23 changed files with 885 additions and 7 deletions.
7 changes: 4 additions & 3 deletions example_test_suites/example_macos/case1/sakuli_demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,18 @@ try {

testCase.endOfStep("Test Sahi landing page",30);
appCalc.open();
screen.waitForImage("calculator.png", 10);
// screen.waitForImage("calculator.png", 10);

env.sleep(4);
env.type("525");
env.sleep(2);
screen.find("plus.png").click().type("100");
screen.find("result.png").click();
screen.waitForImage("625", 5);
// screen.waitForImage("625", 5);
testCase.endOfStep("Calculation",30);

appGedit.open();
screen.waitForImage("gedit.png", 10);
// screen.waitForImage("gedit.png", 5);
env.paste("Initial test passed. Sakuli, Sahi and Sikuli seem to work fine. Exiting...");
testCase.endOfStep("Editor",30);
env.sleep(4);
Expand Down
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,11 @@
<artifactId>jtwig-spaceless-extension</artifactId>
<version>1.44</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.1</version>
</dependency>
</dependencies>
</dependencyManagement>
<repositories>
Expand Down
2 changes: 2 additions & 0 deletions src/common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@
<filtering>false</filtering>
<excludes>
<exclude>**/version.txt</exclude>
<exclude>**/sakuli-default.properties</exclude>
</excludes>
</resource>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/version.txt</include>
<include>**/sakuli-default.properties</include>
</includes>
</resource>
</resources>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,21 @@ function set_sakuli_root {
fi
}

function remove_sakuli_root {
echo "remove 'SAKULI_HOME' from '.bashrc'"
[ -r ~/.bashrc ] && sed -i '/export SAKULI_HOME/d' ~/.bashrc
}

function set_sakuli_root {
if [ -d "$1" ]; then
echo "set 'SAKULI_ROOT' in '.bashrc' to: $1"
echo "export SAKULI_ROOT=\"$1\"" >> ~/.bashrc
else
echo "new 'SAKULI_ROOT' path '$1' does not exists!"
exit 1
fi
}

function set_path {
echo "$PATH"
if grep -q SAKULI_HOME/bin: ~/.bashrc 2>/dev/null; then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,16 @@ sakuli.forwarder.check_mk.spoolfile_prefix=sakuli_suite_
# optional service description forwarded to the output check result, when not set, testsuite.id is used
sakuli.forwarder.check_mk.service_description=${testsuite.id}


##### JSON - FORWARDER
# Save results into a json file. The JSON forwarder is enabled per default.

# DEFAULT: true
sakuli.forwarder.json.enabled=true
## database host
sakuli.forwarder.json.dir=${sakuli.log.folder}/_json


###############################
# LOGGING & ERROR-SCREENSHOT PROPERTIES
# Common logging settings for Sakuli.
Expand Down Expand Up @@ -434,3 +444,10 @@ java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter
java.util.logging.FileHandler.limit=102400
java.util.logging.FileHandler.count=10
java.util.logging.FileHandler.pattern=%t/sahi%g.log

#TODO ${project.version}
sakuli.version=1.0.2

###URLs for documentation links
sahi.doc.url=http://sahipro.com/docs/sahi-apis/action-apis.html
sakuli.doc.base.url=http://consol.github.io/sakuli/v${sakuli.version}/index.html#
5 changes: 5 additions & 0 deletions src/core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,11 @@
<groupId>org.jtwig</groupId>
<artifactId>jtwig-spaceless-extension</artifactId>
</dependency>

<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
</dependencies>

</project>
40 changes: 39 additions & 1 deletion src/core/src/main/java/org/sakuli/aop/RhinoAspect.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,19 @@
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.sakuli.actions.logging.LogToResult;
import org.sakuli.datamodel.TestAction;
import org.sakuli.datamodel.TestCaseStep;
import org.sakuli.datamodel.actions.LogResult;
import org.sakuli.loader.*;
import org.sakuli.loader.BaseActionLoader;
import org.sakuli.loader.BaseActionLoaderImpl;
import org.sakuli.loader.BeanLoader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

import static org.apache.commons.lang.StringUtils.isNotEmpty;
import static org.apache.commons.lang.StringUtils.removeEnd;
import static org.apache.commons.lang3.StringUtils.removeStart;
Expand Down Expand Up @@ -118,6 +125,8 @@ protected void addActionLog(JoinPoint joinPoint, LogToResult logToResult) {
if (logToResult != null) {
StringBuilder message = createLoggingString(joinPoint, logToResult);

addActionsToCurrentStep(extractTestAction(joinPoint, logToResult));

//log the action to log file and print
switch (logToResult.level()) {
case ERROR:
Expand Down Expand Up @@ -147,6 +156,34 @@ protected void addActionLog(JoinPoint joinPoint, LogToResult logToResult) {
}
}

//TODO evtl. move the test action creation to a new service
private List<TestAction> cachedTestActions = new ArrayList<>();

protected void addActionsToCurrentStep(TestAction currentTestAction) {
if (currentTestAction != null) {
cachedTestActions.add(currentTestAction);
}
TestCaseStep currentTestCaseStep = BeanLoader.loadBaseActionLoader().getCurrentTestCaseStep();
if (currentTestCaseStep != null) {
currentTestCaseStep.addActions(cachedTestActions);
//reset the list of actions, since those actions have already been added to the current test step.
cachedTestActions = new ArrayList<>();
}
}

protected TestAction extractTestAction(JoinPoint joinPoint, LogToResult logToResult) {
if (logToResult.logArgsOnly()) {
return null;
}
return TestAction.createSakuliTestAction(
joinPoint.getSignature().getDeclaringType().getSimpleName(),
joinPoint.getSignature().getName(),
joinPoint.getArgs(),
logToResult.message(),
BeanLoader.loadBaseActionLoader().getSakuliProperties().getSakuliDocBaseUrl()
);
}

/**
* @return based on the different arguments of the {@link LogToResult} annotation an different output {@link String}
*/
Expand Down Expand Up @@ -213,6 +250,7 @@ public void doHandleRhinoException(JoinPoint joinPoint) {
else if (logResult.getDebugInfo() == null
|| !logResult.getDebugInfo().startsWith("org.sakuli.actions.")) {
logger.info(logResult.getMessage());
addActionsToCurrentStep(TestAction.createSahiTestAction(logResult.getMessage(), BeanLoader.loadBaseActionLoader().getSakuliProperties().getSahiDocUrl()));
}
}

Expand Down
72 changes: 72 additions & 0 deletions src/core/src/main/java/org/sakuli/datamodel/TestAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Sakuli - Testing and Monitoring-Tool for Websites and common UIs.
*
* Copyright 2013 - 2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.sakuli.datamodel;

/**
* Created by georgi on 21/09/17.
*/
public class TestAction {
private String object;
private String method;
private Object[] args;
private String message;
private String documentationURL;

private TestAction(String object, String method, Object[] args, String message, String documentationURL) {
this.object = object;
this.method = method;
this.args = args;
this.message = message;
this.documentationURL = documentationURL;
}

public static TestAction createSakuliTestAction(String object, String method, Object[] args, String message, String documentationURL) {
return new TestAction(object, method, args, message,
createDocumentationURL(documentationURL, object, method));
}

public static TestAction createSahiTestAction(String method, String documentationURL) {
return new TestAction(method, method, null, null, documentationURL);
}

private static String createDocumentationURL(String baseUrl, String clazz, String method) {
return baseUrl + clazz + "." + method;
}

public String getMessage() {
return message;
}

public Object[] getArgs() {
return args;
}

public String getMethod() {
return method;
}

public Object getObject() {
return object;
}

public String getDocumentationURL() {
return documentationURL;
}

}
11 changes: 10 additions & 1 deletion src/core/src/main/java/org/sakuli/datamodel/TestCaseStep.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
package org.sakuli.datamodel;

import org.apache.commons.lang.StringUtils;
import org.sakuli.datamodel.properties.SakuliProperties;
import org.sakuli.datamodel.state.TestCaseStepState;
import org.sakuli.exceptions.SakuliException;

import java.util.ArrayList;
import java.util.List;

/**
* test case step based Exceptions and critical times will be currently not supported in {@link
* org.sakuli.actions.TestCaseAction}.
Expand All @@ -31,6 +33,8 @@
*/
public class TestCaseStep extends AbstractTestDataEntity<SakuliException, TestCaseStepState> {

private List<TestAction> testActions = new ArrayList<>();

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -85,4 +89,9 @@ public void setName(String name) {
public void setId(String id) {
this.setName(id);
}

public void addActions(List<TestAction> testActions) {
this.testActions.addAll(testActions);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ public class ForwarderProperties extends AbstractProperties {
public static final String GEARMAN_ENABLED = "sakuli.forwarder.gearman.enabled";
public static final String ICINGA_ENABLED = "sakuli.forwarder.icinga2.enabled";
public static final String CHECK_MK_ENABLED = "sakuli.forwarder.check_mk.enabled";
public static final String JSON_ENABLED = "sakuli.forwarder.json.enabled";
protected static final boolean DATABASE_ENABLED_DEFAULT = false;
protected static final boolean GEARMAN_ENABLED_DEFAULT = false;
protected static final boolean ICINGA_ENABLED_DEFAULT = false;
protected static final boolean CHECK_MK_ENABLED_DEFAULT = false;
protected static final boolean JSON_ENABLED_DEFAULT = true;

@Value("${" + DATABASE_ENABLED + ":" + DATABASE_ENABLED_DEFAULT + "}")
private boolean databaseEnabled;
Expand All @@ -45,6 +47,9 @@ public class ForwarderProperties extends AbstractProperties {
@Value("${" + CHECK_MK_ENABLED + ":" + CHECK_MK_ENABLED_DEFAULT + "}")
private boolean checkMKEnabled;

@Value("${" + JSON_ENABLED + ":" + JSON_ENABLED_DEFAULT + "}")
private boolean jsonEnabled;

public boolean isDatabaseEnabled() {
return databaseEnabled;
}
Expand Down Expand Up @@ -73,4 +78,12 @@ public boolean isCheckMKEnabled() {
return checkMKEnabled;
}

public void setJsonEnabled(boolean jsonEnabled) {
this.jsonEnabled = jsonEnabled;
}

public boolean isJsonEnabled() {
return jsonEnabled;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@ public class SakuliProperties extends AbstractProperties {
public static final String LOG_LEVEL_SPRING = "log.level.spring";
public static final String LOG_LEVEL_ROOT = "log.level.root";
public static final String FORWARDER_TEMPLATE_FOLDER = "sakuli.forwarder.template.folder";
public static final String SAHI_DOC_URL = "sahi.doc.url";
public static final String SAKULI_DOC_BASE_URL = "sakuli.doc.base.url";
public static final String CONFIG_FOLDER_APPEDER = File.separator + "config";
public static final String LIBS_FOLDER_APPEDER = File.separator + "libs";
public static final String JS_LIB_FOLDER_APPEDER = LIBS_FOLDER_APPEDER + File.separator + "js";
// have to be the common/libs older, so that {@link TextRecognizer} can add "tessdata" to the path!
// have to be the common/libs folder, so that {@link TextRecognizer} can add "tessdata" to the path!
public static final String TESSDATA_LIB_FOLDER_APPEDER = LIBS_FOLDER_APPEDER;
private static final boolean SUPPRESS_RESUMED_EXCEPTIONS_DEFAULT = false;
private static final boolean JAVASCRIPT_ENGINE_DEFAULT = true;
Expand Down Expand Up @@ -84,6 +86,11 @@ public class SakuliProperties extends AbstractProperties {
private String logLevelRoot;
@Value("${" + FORWARDER_TEMPLATE_FOLDER + ":}")
private String forwarderTemplateFolder;
@Value("${" + SAHI_DOC_URL + "}")
private String sahiDocumentationUrl;
@Value("${" + SAKULI_DOC_BASE_URL + "}")
private String sakuliDocumentationBaseUrl;

private Path configFolder;
private Path jsLibFolder;
private Path tessDataLibFolder;
Expand Down Expand Up @@ -241,4 +248,12 @@ public String getForwarderTemplateFolder() {
return forwarderTemplateFolder;
}

public String getSahiDocUrl() {
return sahiDocumentationUrl;
}

public String getSakuliDocBaseUrl() {
return sakuliDocumentationBaseUrl;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
* @author tschneck
* Date: 2/24/16
*/
public abstract class AbstractOutputBuilder {
public abstract class AbstractOutputBuilder {
public final static SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.YY HH:mm:ss");
protected Logger LOGGER = LoggerFactory.getLogger(getClass());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.sakuli.services.forwarder.gearman.ProfileGearman;
import org.sakuli.services.forwarder.gearman.model.ScreenshotDiv;
import org.sakuli.services.forwarder.icinga2.ProfileIcinga2;
import org.sakuli.services.forwarder.json.ProfileJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import sun.misc.BASE64Encoder;
Expand All @@ -41,6 +42,7 @@
@ProfileGearman
@ProfileIcinga2
@ProfileCheckMK
@ProfileJson
@Component
public class ScreenshotDivConverter {

Expand Down
Loading

0 comments on commit 30aecab

Please sign in to comment.