-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Allain Magyar <allain.magyar@iohk.io>
- Loading branch information
1 parent
c4484a7
commit 0b39188
Showing
25 changed files
with
1,107 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/main/kotlin/io/iohk/atala/automation/cucumber/common/AnsiEscapes.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package io.iohk.atala.automation.cucumber.common | ||
|
||
class AnsiEscapes private constructor(private val value: String) { | ||
override fun toString(): String { | ||
val sb = java.lang.StringBuilder() | ||
appendTo(sb) | ||
return sb.toString() | ||
} | ||
|
||
fun appendTo(a: java.lang.StringBuilder) { | ||
a.append(ESC).append(BRACKET).append( | ||
value | ||
) | ||
} | ||
|
||
companion object { | ||
val RESET = color(0) | ||
val BLACK = color(30) | ||
val BRIGHT_BLACK = color(90) | ||
|
||
val RED = color(31) | ||
val BRIGHT_RED = color(91) | ||
|
||
val GREEN = color(32) | ||
val BRIGHT_GREEN = color(92) | ||
|
||
val YELLOW = color(33) | ||
val BLUE = color(34) | ||
val MAGENTA = color(35) | ||
val CYAN = color(36) | ||
val WHITE = color(37) | ||
val DEFAULT = color(9) | ||
val GREY = color(90) | ||
|
||
val INTENSITY_BOLD = color(1) | ||
val UNDERLINE = color(4) | ||
private const val ESC = 27.toChar() | ||
private const val BRACKET = '[' | ||
private fun color(code: Int): AnsiEscapes { | ||
return AnsiEscapes(code.toString() + "m") | ||
} | ||
|
||
fun up(count: Int): AnsiEscapes { | ||
return AnsiEscapes(count.toString() + "A") | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/main/kotlin/io/iohk/atala/automation/cucumber/common/Format.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package io.iohk.atala.automation.cucumber.common | ||
|
||
interface Format { | ||
fun text(text: String): String | ||
|
||
class Color internal constructor(private vararg val escapes: AnsiEscapes) : Format { | ||
|
||
override fun text(text: String): String { | ||
val sb = java.lang.StringBuilder() | ||
for (escape in escapes) { | ||
escape.appendTo(sb) | ||
} | ||
sb.append(text) | ||
if (escapes.isNotEmpty()) { | ||
AnsiEscapes.RESET.appendTo(sb) | ||
} | ||
return sb.toString() | ||
} | ||
} | ||
|
||
class Monochrome internal constructor() : Format { | ||
override fun text(text: String): String { | ||
return text | ||
} | ||
} | ||
|
||
companion object { | ||
fun color(vararg escapes: AnsiEscapes): Format { | ||
return Color(*escapes) | ||
} | ||
|
||
fun monochrome(): Format { | ||
return Monochrome() | ||
} | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
src/main/kotlin/io/iohk/atala/automation/cucumber/common/Formats.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package io.iohk.atala.automation.cucumber.common | ||
|
||
|
||
interface Formats { | ||
operator fun get(key: String): Format | ||
fun up(n: Int): String | ||
|
||
companion object { | ||
@JvmStatic | ||
fun monochrome(): Formats { | ||
return Monochrome() | ||
} | ||
|
||
@JvmStatic | ||
fun ansi(): Formats { | ||
return Ansi() | ||
} | ||
} | ||
|
||
class Monochrome internal constructor() : Formats { | ||
override fun get(key: String): Format { | ||
return Format.monochrome() | ||
} | ||
|
||
override fun up(n: Int): String { | ||
return "" | ||
} | ||
} | ||
|
||
class Ansi internal constructor() : Formats { | ||
override fun get(key: String): Format { | ||
val format: Format = formats[key] ?: throw NullPointerException("No format for key $key") | ||
return format | ||
} | ||
|
||
override fun up(n: Int): String { | ||
return AnsiEscapes.up(n).toString() | ||
} | ||
|
||
companion object { | ||
private val formats: Map<String, Format> = object : java.util.HashMap<String, Format>() { | ||
init { | ||
// Never used, but avoids NPE in formatters. | ||
put("undefined", Format.color(AnsiEscapes.YELLOW)) | ||
put("undefined_arg", Format.color(AnsiEscapes.YELLOW, AnsiEscapes.INTENSITY_BOLD)) | ||
put("unused", Format.color(AnsiEscapes.YELLOW)) | ||
put("unused_arg", Format.color(AnsiEscapes.YELLOW, AnsiEscapes.INTENSITY_BOLD)) | ||
put("pending", Format.color(AnsiEscapes.YELLOW)) | ||
put("pending_arg", Format.color(AnsiEscapes.YELLOW, AnsiEscapes.INTENSITY_BOLD)) | ||
put("executing", Format.color(AnsiEscapes.GREY)) | ||
put("executing_arg", Format.color(AnsiEscapes.GREY, AnsiEscapes.INTENSITY_BOLD)) | ||
put("failed", Format.color(AnsiEscapes.RED)) | ||
put("failed_arg", Format.color(AnsiEscapes.RED, AnsiEscapes.INTENSITY_BOLD)) | ||
put("ambiguous", Format.color(AnsiEscapes.RED)) | ||
put("ambiguous_arg", Format.color(AnsiEscapes.RED, AnsiEscapes.INTENSITY_BOLD)) | ||
put("passed", Format.color(AnsiEscapes.GREEN)) | ||
put("passed_arg", Format.color(AnsiEscapes.BRIGHT_GREEN, AnsiEscapes.INTENSITY_BOLD)) | ||
put("outline", Format.color(AnsiEscapes.CYAN)) | ||
put("outline_arg", Format.color(AnsiEscapes.CYAN, AnsiEscapes.INTENSITY_BOLD)) | ||
put("skipped", Format.color(AnsiEscapes.CYAN)) | ||
put("skipped_arg", Format.color(AnsiEscapes.CYAN, AnsiEscapes.INTENSITY_BOLD)) | ||
put("comment", Format.color(AnsiEscapes.GREY)) | ||
put("tag", Format.color(AnsiEscapes.CYAN)) | ||
put("output", Format.color(AnsiEscapes.BLUE)) | ||
} | ||
} | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/kotlin/io/iohk/atala/automation/cucumber/common/UTF8OutputStreamWriter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package io.iohk.atala.automation.cucumber.common | ||
|
||
import java.io.OutputStream | ||
import java.io.OutputStreamWriter | ||
import java.nio.charset.StandardCharsets | ||
|
||
class UTF8OutputStreamWriter(out: OutputStream) : OutputStreamWriter(out, StandardCharsets.UTF_8) |
72 changes: 72 additions & 0 deletions
72
src/main/kotlin/io/iohk/atala/automation/cucumber/common/UTF8PrintWriter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package io.iohk.atala.automation.cucumber.common | ||
|
||
import java.io.Closeable | ||
import java.io.Flushable | ||
import java.io.IOException | ||
import java.io.OutputStream | ||
import java.io.OutputStreamWriter | ||
|
||
/** | ||
* A "good enough" PrintWriter implementation that writes UTF-8 and rethrows all | ||
* exceptions as runtime exceptions. | ||
*/ | ||
class UTF8PrintWriter(out: OutputStream) : Appendable, Closeable, Flushable { | ||
private val out: OutputStreamWriter = UTF8OutputStreamWriter(out) | ||
|
||
fun println() { | ||
try { | ||
out.write(System.lineSeparator()) | ||
} catch (e: IOException) { | ||
throw RuntimeException(e) | ||
} | ||
} | ||
|
||
fun println(s: String) { | ||
try { | ||
out.write(s) | ||
out.write(System.lineSeparator()) | ||
} catch (e: IOException) { | ||
throw RuntimeException(e) | ||
} | ||
} | ||
|
||
override fun flush() { | ||
try { | ||
out.flush() | ||
} catch (e: IOException) { | ||
throw RuntimeException(e) | ||
} | ||
} | ||
|
||
override fun close() { | ||
try { | ||
out.close() | ||
} catch (e: IOException) { | ||
throw RuntimeException(e) | ||
} | ||
} | ||
|
||
override fun append(csq: CharSequence): Appendable { | ||
try { | ||
return out.append(csq) | ||
} catch (e: IOException) { | ||
throw RuntimeException(e) | ||
} | ||
} | ||
|
||
override fun append(csq: CharSequence, start: Int, end: Int): Appendable { | ||
try { | ||
return out.append(csq, start, end) | ||
} catch (e: IOException) { | ||
throw RuntimeException(e) | ||
} | ||
} | ||
|
||
override fun append(c: Char): Appendable { | ||
try { | ||
return out.append(c) | ||
} catch (e: IOException) { | ||
throw RuntimeException(e) | ||
} | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
src/main/kotlin/io/iohk/atala/automation/cucumber/plugins/SerenityStepListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package io.iohk.atala.automation.cucumber.plugins | ||
|
||
import net.thucydides.model.domain.Story | ||
import net.thucydides.model.domain.TestOutcome | ||
import net.thucydides.model.domain.TestResult | ||
import net.thucydides.model.screenshots.ScreenshotAndHtmlSource | ||
import net.thucydides.model.steps.ExecutedStepDescription | ||
import net.thucydides.model.steps.StepFailure | ||
import net.thucydides.model.steps.StepListener | ||
import java.time.ZonedDateTime | ||
|
||
class SerenityStepListener: StepListener { | ||
data class Entry( | ||
val keyword: String, | ||
val stepText: String, | ||
val arguments: List<String>, | ||
val isSubStep: Boolean | ||
) | ||
companion object { | ||
val stepList = mutableListOf<Entry>() | ||
} | ||
|
||
override fun stepStarted(description: ExecutedStepDescription, startTime: ZonedDateTime) { | ||
val split = description.title.split(" ") | ||
val keyword = split[0] + " " | ||
val stepText = split.subList(1, split.size).joinToString(" ") | ||
val isSubStep = description.stepClass != null | ||
val arguments = description.arguments | ||
stepList.add(Entry(keyword, stepText, arguments, isSubStep)) | ||
} | ||
|
||
override fun testSuiteStarted(storyClass: Class<*>?) {} | ||
override fun testSuiteStarted(story: Story) {} | ||
override fun testSuiteFinished() {} | ||
override fun testStarted(description: String) {} | ||
override fun testStarted(description: String, id: String) {} | ||
override fun testStarted(description: String, id: String, startTime: ZonedDateTime) {} | ||
override fun testFinished(result: TestOutcome) {} | ||
override fun testFinished(result: TestOutcome, isInDataDrivenTest: Boolean, finishTime: ZonedDateTime) {} | ||
override fun testRetried() {} | ||
override fun stepStarted(description: ExecutedStepDescription) {} | ||
override fun skippedStepStarted(description: ExecutedStepDescription) {} | ||
override fun stepFailed(failure: StepFailure) {} | ||
override fun stepFailed(failure: StepFailure?, screenshotList: MutableList<ScreenshotAndHtmlSource>?, isInDataDrivenTest: Boolean) {} | ||
override fun stepFailed(failure: StepFailure?, screenshotList: MutableList<ScreenshotAndHtmlSource>?, isInDataDrivenTest: Boolean, zonedDateTime: ZonedDateTime?) {} | ||
|
||
override fun lastStepFailed(failure: StepFailure) {} | ||
override fun stepIgnored() {} | ||
override fun stepPending() {} | ||
override fun stepPending(message: String) {} | ||
override fun stepFinished() {} | ||
override fun stepFinished(screenshotList: List<ScreenshotAndHtmlSource>, time: ZonedDateTime) {} | ||
override fun testFailed(testOutcome: TestOutcome, cause: Throwable) {} | ||
override fun testIgnored() {} | ||
override fun testSkipped() {} | ||
override fun testPending() {} | ||
override fun testIsManual() {} | ||
override fun notifyScreenChange() {} | ||
override fun useExamplesFrom(table: net.thucydides.model.domain.DataTable?) {} | ||
override fun addNewExamplesFrom(table: net.thucydides.model.domain.DataTable?) {} | ||
override fun exampleStarted(data: Map<String, String>) {} | ||
override fun exampleFinished() {} | ||
override fun assumptionViolated(message: String) {} | ||
override fun testRunFinished() {} | ||
override fun takeScreenshots(screenshots: List<ScreenshotAndHtmlSource>) {} | ||
override fun takeScreenshots(testResult: TestResult, screenshots: List<ScreenshotAndHtmlSource>) {} | ||
} | ||
|
Oops, something went wrong.