Skip to content

Commit

Permalink
[rdbms]
Browse files Browse the repository at this point in the history
- [`saveResults(db,sqls,outputDir)`]: code fix to ensure all output are listed in execution output (Excel) and uploaded to the cloud when `nexial.outputToCloud` is set to `true`.
- [`saveResult(db,sqls,outputDir)`]: code fix to ensure all output are listed in execution output (Excel) and uploaded to the cloud when `nexial.outputToCloud` is set to `true`.

[web]
- code fix to ensure browser metrics report is uploaded to cloud when `nexial.outputToCloud` to set to `true`.

Signed-off-by: automike <[email protected]>
  • Loading branch information
mikeliucc committed Dec 15, 2019
1 parent 8b73871 commit 7b358e9
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 35 deletions.
13 changes: 12 additions & 1 deletion src/main/java/org/nexial/core/ExecutionThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.nexial.commons.logging.LogbackUtils;
import org.nexial.commons.utils.FileUtil;
import org.nexial.commons.utils.ResourceUtils;
import org.nexial.core.aws.NexialS3Helper;
import org.nexial.core.excel.Excel;
import org.nexial.core.model.*;
import org.nexial.core.plugins.web.CloudWebTestingPlatform;
Expand Down Expand Up @@ -479,8 +480,18 @@ private void handleBrowserMetrics(ExecutionContext context) {
String html = StringUtils.replace(ResourceUtils.loadResource(WEB_METRICS_HTML_LOC + WEB_METRICS_HTML),
WEB_METRICS_TOKEN,
json);
FileUtils.writeStringToFile(new File(outputBase + WEB_METRICS_HTML), html, DEF_FILE_ENCODING);
File webMetricFile = new File(outputBase + WEB_METRICS_HTML);
FileUtils.writeStringToFile(webMetricFile, html, DEF_FILE_ENCODING);
System.setProperty(WEB_METRICS_GENERATED, "true");

if (context.isOutputToCloud()) {
NexialS3Helper otc = context.getOtc();
if (otc != null && otc.isReadyForUse() && FileUtil.isFileReadable(webMetricFile, 1024)) {
// upload HTML report to cloud
String url = otc.importToS3(webMetricFile, otc.resolveOutputDir(), true);
ConsoleUtils.log("Web Performance Metric exported to " + url);
}
}
} catch (IOException e) {
// unable to read JSON, read HTML or write HTML to output
ConsoleUtils.error("Unable to generate browser metrics HTML: " + e.getMessage());
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/nexial/core/Nexial.java
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@ protected void onExecutionComplete(String runId, ExecutionSummary summary) {
// upload HTML report to cloud
if (FileUtil.isFileReadable(htmlReport, 1024)) {
String url = otc.importToS3(htmlReport, outputDir, true);
ConsoleUtils.log("HTML output for this execution export to " + url);
ConsoleUtils.log("HTML output for this execution exported to " + url);
System.setProperty(EXEC_OUTPUT_PATH, url);
if (StringUtils.isNotBlank(url)) { ExecutionReporter.openExecutionSummaryReport(url); }
}
Expand All @@ -953,7 +953,7 @@ protected void onExecutionComplete(String runId, ExecutionSummary summary) {
// upload junit xml
if (FileUtil.isFileReadable(junitReport, 100)) {
String url = otc.importToS3(junitReport, outputDir, true);
ConsoleUtils.log("JUnit XML output for this execution export to " + url);
ConsoleUtils.log("JUnit XML output for this execution exported to " + url);
System.setProperty(JUNIT_XML_LOCATION, url);
}
} catch (IOException e) {
Expand Down
5 changes: 1 addition & 4 deletions src/main/java/org/nexial/core/excel/Excel.java
Original file line number Diff line number Diff line change
Expand Up @@ -333,18 +333,15 @@ public void setRowValues(ExcelAddress addr, List<String> values, String styleNam
public void setLinkCell(ExcelAddress addr, String link, String text, String styleName, float rowHeight) {
assert addr != null;
assert text != null;
// assert styleConfig != null;

workbook.setMissingCellPolicy(CREATE_NULL_AS_BLANK);
// XSSFCellStyle cellStyle = StyleDecorator.decorate(newCellStyle(), createFont(), styleConfig);
XSSFCellStyle cellStyle = commonStyles.get(styleName);

int startRow = addr.getRowStartIndex();
if (sheet.getRow(startRow) == null) { sheet.createRow(startRow); }
XSSFRow row = sheet.getRow(startRow);

XSSFCell cell = row.getCell(addr.getColumnStartIndex());
cell.setCellStyle(cellStyle);
cell.setCellStyle(commonStyles.get(styleName));
row.setHeightInPoints(rowHeight);

if (StringUtils.isNotBlank(link)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ protected static int handleNestedMessages(Worksheet worksheet, ExecutionSummary
int messageCount = nestedMessages.size();
for (int i = 0; i < messageCount; i++) {
NestedMessage nestedMessage = nestedMessages.get(i);

// nested screen capture will add to new row (after test step)
// step output will output to same row as test step

if (nestedMessage instanceof StepOutput) {
addScreenshotLink(excelSheet.getRow(step.getRowIndex()), linkStyle, (StepOutput) nestedMessage);
} else {
Expand Down
39 changes: 30 additions & 9 deletions src/main/kotlin/org/nexial/core/plugins/db/RdbmsCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import org.apache.commons.lang3.StringUtils
import org.nexial.commons.utils.FileUtil
import org.nexial.commons.utils.TextUtils
import org.nexial.core.NexialConst.*
import org.nexial.core.NexialConst.Rdbms.*
import org.nexial.core.NexialConst.Rdbms.CSV_ROW_SEP
import org.nexial.core.NexialConst.Rdbms.DAO_PREFIX
import org.nexial.core.model.ExecutionContext
import org.nexial.core.model.StepResult
import org.nexial.core.plugins.base.BaseCommand
Expand Down Expand Up @@ -61,7 +62,7 @@ class RdbmsCommand : BaseCommand() {
// requires(dataAccess.validSQL(query), "invalid sql", sql);

val result = dataAccess.execute(query, resolveDao(db)) ?: return StepResult.fail(
"FAILED TO EXECUTE SQL '$sql': no result found")
"FAILED TO EXECUTE SQL '$sql': no result found")
context.setData(`var`, result)

log("executed query in ${result.elapsedTime} ms with " +
Expand Down Expand Up @@ -202,6 +203,7 @@ class RdbmsCommand : BaseCommand() {
if (!db.startsWith(NAMESPACE)) log("found $qualifiedSqlCount qualified query(s) to execute")

msgPrefix = "executed $qualifiedSqlCount SQL(s);"
val testStep = context.currentTestStep

for (sqlComponent in qualifiedSqlList) {
val sql = context.replaceTokens(StringUtils.trim(sqlComponent.sql))
Expand All @@ -221,12 +223,19 @@ class RdbmsCommand : BaseCommand() {

if (result.hasError()) log("ERROR found while executing $printableSql: ${result.error}")

if (FileUtil.isFileReadable(output, 3)) addLinkRef(null, outFile, targetFile.absolutePath)
if (FileUtil.isFileReadable(output, 3)) {
addLinkRef("result saved as $outFile", outFile, targetFile.absolutePath)
}

log("executed $printableSql in ${result.elapsedTime} ms with " +
if (result.hasError()) "ERROR ${result.error}" else "${result.rowCount} row(s)")

resultToJson(result, StringUtils.substringBeforeLast(output, ".") + ".json")
val jsonOutput = resultToJson(result, StringUtils.substringBeforeLast(output, ".") + ".json")
if (FileUtil.isFileReadable(jsonOutput, 3)) {
addLinkRef("result metadata saved as ${jsonOutput.name}",
jsonOutput.name,
jsonOutput.absolutePath)
}
} else {
// not saving result anywhere since this SQL is not mapped to any variable
log("executing $printableSql without saving its result")
Expand All @@ -246,6 +255,7 @@ class RdbmsCommand : BaseCommand() {
requiresNotBlank(output, "invalid output", output)

val outputFile = if (!StringUtils.endsWithIgnoreCase(output, ".csv")) "$output.csv" else output
val targetFile = File(outputFile)

val dao = resolveDao(db)

Expand All @@ -255,13 +265,22 @@ class RdbmsCommand : BaseCommand() {
// so for that reason, we are no longer insisting on the use of standard ANSI sql
// requires(dataAccess.validSQL(query), "invalid sql", sql);

val result = dataAccess.execute(query, dao, File(outputFile)) ?: return StepResult.fail(
"FAILED TO EXECUTE SQL '$sql': no result found")
val result = dataAccess.execute(query, dao, targetFile) ?: return StepResult.fail(
"FAILED TO EXECUTE SQL '$sql': no result")

log("executed query in ${result.elapsedTime} ms with " +
if (result.hasError()) "ERROR ${result.error}" else "${result.rowCount} row(s)")

resultToJson(result, StringUtils.substringBeforeLast(outputFile, ".") + ".json")
if (FileUtil.isFileReadable(targetFile, 3)) {
addLinkRef("result saved as $outputFile", targetFile.name, targetFile.absolutePath)
}

val jsonOutput = resultToJson(result, StringUtils.substringBeforeLast(outputFile, ".") + ".json")
if (FileUtil.isFileReadable(jsonOutput, 3)) {
addLinkRef("result metadata saved as ${jsonOutput.name}",
jsonOutput.name,
jsonOutput.absolutePath)
}
return StepResult.success("executed SQL '$sql'; stored result to '$outputFile'")
} catch (e: IOException) {
return StepResult.fail("Error when executing '$sql': ${e.message}")
Expand Down Expand Up @@ -315,7 +334,9 @@ class RdbmsCommand : BaseCommand() {
}

@Throws(IOException::class)
private fun resultToJson(result: JdbcResult, output: String) {
FileUtils.writeStringToFile(File(output), GSON.toJson(result), DEF_FILE_ENCODING)
private fun resultToJson(result: JdbcResult, output: String): File {
val file = File(output)
FileUtils.writeStringToFile(file, GSON.toJson(result), DEF_FILE_ENCODING)
return file
}
}
18 changes: 9 additions & 9 deletions src/main/resources/org/nexial/core/reports/browser-metrics.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@
}
</script>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css" onerror="externalResourceNotFound()"/>
<link rel="stylesheet" href="http://nexiality.github.io/documentation/assets/project/datatables.min.css" onerror="externalResourceNotFound()"/>
<link rel="stylesheet" href="http://nexiality.github.io/documentation/assets/project/w2ui-1.5.rc1.min.css" onerror="externalResourceNotFound()"/>
<link rel="stylesheet" href="http://nexiality.github.io/documentation/assets/report/execution_summary.css" onerror="externalResourceNotFound()"/>
<link rel="stylesheet" href="http://nexiality.github.io/documentation/assets/metrics/browser-metric.glossygreen.css" onerror="externalResourceNotFound()"/>
<link rel="stylesheet" href="https://nexiality.github.io/documentation/assets/project/datatables.min.css" onerror="externalResourceNotFound()"/>
<link rel="stylesheet" href="https://nexiality.github.io/documentation/assets/project/w2ui-1.5.rc1.min.css" onerror="externalResourceNotFound()"/>
<link rel="stylesheet" href="https://nexiality.github.io/documentation/assets/report/execution_summary.css" onerror="externalResourceNotFound()"/>
<link rel="stylesheet" href="https://nexiality.github.io/documentation/assets/metrics/browser-metric.glossygreen.css" onerror="externalResourceNotFound()"/>

<script src="http://nexiality.github.io/documentation/assets/project/datatables.min.js" onerror="externalResourceNotFound()"></script>
<script src="http://nexiality.github.io/documentation/assets/project/w2ui-1.5.rc1.min.js" onerror="externalResourceNotFound()"></script>
<script src="http://nexiality.github.io/documentation/assets/project/Chart.bundle.min.js" onerror="externalResourceNotFound()"></script>
<script src="http://nexiality.github.io/documentation/assets/report/execution_summary.js" onerror="externalResourceNotFound()"></script>
<script src="http://nexiality.github.io/documentation/assets/metrics/browser-metrics.js" onerror="externalResourceNotFound()"></script>
<script src="https://nexiality.github.io/documentation/assets/project/datatables.min.js" onerror="externalResourceNotFound()"></script>
<script src="https://nexiality.github.io/documentation/assets/project/w2ui-1.5.rc1.min.js" onerror="externalResourceNotFound()"></script>
<script src="https://nexiality.github.io/documentation/assets/project/Chart.bundle.min.js" onerror="externalResourceNotFound()"></script>
<script src="https://nexiality.github.io/documentation/assets/report/execution_summary.js" onerror="externalResourceNotFound()"></script>
<script src="https://nexiality.github.io/documentation/assets/metrics/browser-metrics.js" onerror="externalResourceNotFound()"></script>
<title>Browser Performance Metrics</title>
</head>
<body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html xmlns="http://www.w3.org/1999/html" lang="en">
<head>
<meta charset="UTF-8">
<link rel="shortcut icon" type="image/png" href="http://nexiality.github.io/documentation/favicon.ico">
<link rel="shortcut icon" type="image/png" href="https://nexiality.github.io/documentation/favicon.ico">
<script>
let loadErrorFound = false;
function externalResourceNotFound() {
Expand All @@ -16,17 +16,17 @@
}
</script>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.1/css/all.css" onerror="externalResourceNotFound()"/>
<link rel="stylesheet" href="http://nexiality.github.io/documentation/assets/project/datatables.min.css" onerror="externalResourceNotFound()"/>
<link rel="stylesheet" href="http://nexiality.github.io/documentation/assets/project/w2ui-1.5.rc1.min.css" onerror="externalResourceNotFound()"/>
<link rel="stylesheet" href="http://nexiality.github.io/documentation/assets/report/execution_summary.css" onerror="externalResourceNotFound()"/>
<link rel="stylesheet" href="http://nexiality.github.io/documentation/assets/project/project-iceblue.css" onerror="externalResourceNotFound()"/>
<link rel="stylesheet" href="https://nexiality.github.io/documentation/assets/project/datatables.min.css" onerror="externalResourceNotFound()"/>
<link rel="stylesheet" href="https://nexiality.github.io/documentation/assets/project/w2ui-1.5.rc1.min.css" onerror="externalResourceNotFound()"/>
<link rel="stylesheet" href="https://nexiality.github.io/documentation/assets/report/execution_summary.css" onerror="externalResourceNotFound()"/>
<link rel="stylesheet" href="https://nexiality.github.io/documentation/assets/project/project-iceblue.css" onerror="externalResourceNotFound()"/>

<script type="text/javascript" src="project-inspector.js"></script>
<script src="http://nexiality.github.io/documentation/assets/project/clipboard.min.js" onerror="externalResourceNotFound()"></script>
<script src="http://nexiality.github.io/documentation/assets/project/datatables.min.js" onerror="externalResourceNotFound()"></script>
<script src="http://nexiality.github.io/documentation/assets/project/w2ui-1.5.rc1.min.js" onerror="externalResourceNotFound()"></script>
<script src="http://nexiality.github.io/documentation/assets/report/execution_summary.js" onerror="externalResourceNotFound()"></script>
<script src="http://nexiality.github.io/documentation/assets/project/project.js" onerror="externalResourceNotFound()"></script>
<script src="https://nexiality.github.io/documentation/assets/project/clipboard.min.js" onerror="externalResourceNotFound()"></script>
<script src="https://nexiality.github.io/documentation/assets/project/datatables.min.js" onerror="externalResourceNotFound()"></script>
<script src="https://nexiality.github.io/documentation/assets/project/w2ui-1.5.rc1.min.js" onerror="externalResourceNotFound()"></script>
<script src="https://nexiality.github.io/documentation/assets/report/execution_summary.js" onerror="externalResourceNotFound()"></script>
<script src="https://nexiality.github.io/documentation/assets/project/project.js" onerror="externalResourceNotFound()"></script>
<title></title>
<style id="nexial-project"></style>
</head>
Expand Down
Binary file modified template/nexial-macro.xlsx
Binary file not shown.
Binary file modified template/nexial-script.xlsx
Binary file not shown.

0 comments on commit 7b358e9

Please sign in to comment.