How to use context method of io.kotest.core.spec.style.scopes.DescribeSpecContainerScope class

Best Kotest code snippet using io.kotest.core.spec.style.scopes.DescribeSpecContainerScope.context

ActionExecutorExtension.kt

Source:ActionExecutorExtension.kt Github

copy

Full Screen

...10import fi.epicbot.toster.report.model.ReportCollage11import fi.epicbot.toster.report.model.ReportDevice12import fi.epicbot.toster.report.model.ReportScreen13import io.kotest.core.spec.style.scopes.DescribeSpecContainerScope14context(DescribeSpecContainerScope)15internal suspend fun ActionExecutor.runBeforeScreens(16 config: Config,17 apk: Apk,18): ReportScreen {19 val beforeScreen = ReportScreen(name = "Before")20 Action.RestartAdbService.runAction(21 this,22 beforeScreen,23 executeCondition = config.restartAdbServiceBeforeEachDevice,24 )25 prepareEnvironment()26 config.globalLogcatBufferSize?.let { logcatBufferSize ->27 Action.SetLogcatBufferSize(logcatBufferSize).runAction(this, beforeScreen)28 }29 config.shellsBeforeAllScreens.forEach { shellBeforeAllScreens ->30 Action.ShellBeforeAllScreens(shellBeforeAllScreens).runAction(31 this,32 beforeScreen,33 executeCondition = shellBeforeAllScreens.isNotBlank(),34 )35 }36 config.globalScreenDensity.apply(this, beforeScreen)37 config.globalScreenSize?.let { screenSize ->38 Action.SetScreenSize(screenSize).runAction(this, beforeScreen)39 }40 if (config.deleteAndInstallApk) {41 listOf(42 Action.ClearAppData,43 Action.DeleteApk,44 Action.InstallApk(apk.url)45 ).forEach { action ->46 action.runAction(this, beforeScreen)47 }48 }49 Action.HideDemoMode.runAction(this, beforeScreen)50 if (config.useDemoMode) {51 Action.SetDemoModeEnable.runAction(this, beforeScreen)52 Action.ShowDemoMode(config.demoModeTime).runAction(this, beforeScreen)53 }54 Action.HideGpuOverdraw.runAction(this, beforeScreen)55 return beforeScreen56}57context(DescribeSpecContainerScope)58internal suspend fun ActionExecutor.runAfterScreens(59 config: Config,60): ReportScreen {61 val afterScreen = ReportScreen("After")62 if (config.useDemoMode) {63 Action.HideDemoMode.runAction(this, afterScreen)64 }65 config.shellsAfterAllScreens.forEach { shellAfterAllScreens ->66 Action.ShellAfterAllScreens(shellAfterAllScreens).runAction(67 this,68 afterScreen,69 executeCondition = shellAfterAllScreens.isNotBlank(),70 )71 }72 resetScreenSizeAndDensity(config, afterScreen)73 finishEnvironment()74 return afterScreen75}76context(DescribeSpecContainerScope)77internal suspend fun ActionExecutor.runScreens(78 config: Config,79 apk: Apk,80 screens: List<Screen>,81 reportDevices: MutableList<ReportDevice>,82) {83 val actionExecutor = this84 describe(this.executor().toString()) {85 val reportScreens: MutableList<ReportScreen> = mutableListOf()86 val beforeScreenReport = runBeforeScreens(config, apk)87 screens.forEach { screen ->88 val reportScreen = ReportScreen(name = screen.name)89 actionExecutor.imagePrefix = "normal"90 runScreen(config, screen, reportScreen)91 if (config.checkOverdraw.check) {92 actionExecutor.imagePrefix = "overdraw"93 Action.ShowGpuOverdraw.runAction(actionExecutor, reportScreen)94 runScreen(config, screen, reportScreen)95 Action.HideGpuOverdraw.runAction(actionExecutor, reportScreen)96 // TODO run tests for getting overdraw info97 }98 // TODO compare screenshots99 reportScreens.add(reportScreen)100 }101 val afterScreenReport = runAfterScreens(config)102 reportDevices.add(103 ReportDevice(104 device = actionExecutor.executor(),105 reportScreens = listOf(beforeScreenReport) + reportScreens + listOf(106 afterScreenReport107 ),108 collage = ReportCollage(),109 )110 )111 }112}113context(DescribeSpecContainerScope)114@Suppress("LongMethod")115internal suspend fun ActionExecutor.runScreen(116 config: Config,117 screen: Screen,118 reportScreen: ReportScreen,119) {120 val actionExecutor = this121 describe("Screen: ${screen.name}; $imagePrefix") {122 screen.shellsBefore.forEach { shellBefore ->123 Action.ShellBeforeScreen(shellBefore).runAction(124 actionExecutor,125 reportScreen,126 shellBefore.isNotBlank(),127 )128 }129 Action.ClearLogcat.runAction(130 actionExecutor,131 reportScreen,132 executeCondition = screen.clearLogcatBefore133 )134 setScreenSizeAndDensity(screen, reportScreen)135 if (config.clearDataBeforeEachRun || screen.clearDataBeforeRun) {136 Action.ClearAppData.runAction(actionExecutor, reportScreen)137 }138 (config.permissions.granted + screen.permissions.granted).forEach {139 Action.GrantPermission(it).runAction(actionExecutor, reportScreen)140 }141 screen.permissions.revoked.forEach {142 Action.RevokePermission(it).runAction(actionExecutor, reportScreen)143 }144 val fontScale = if (screen.fontScale != null && screen.fontScale != FontScale.DEFAULT) {145 screen.fontScale146 } else {147 config.fontScale148 }149 fontScale?.let { fontScale ->150 Action.SetFontScale(fontScale).runAction(actionExecutor, reportScreen)151 }152 Action.CloseAppsInTray.runAction(153 actionExecutor,154 reportScreen,155 screen.closeAppsInTrayBeforeStart,156 )157 Action.ResetGfxInfo.runAction(158 actionExecutor,159 reportScreen,160 screen.resetGfxInfoBeforeStart,161 )162 val activityParamsAsString = screen.activityParams.toStringParams()163 Action.OpenScreen(screen, activityParamsAsString).runAction(164 actionExecutor,165 reportScreen,166 )167 screen.actions.forEach { action ->168 action.runAction(actionExecutor, reportScreen)169 }170 if (screen.screenshotAsLastAction && screen.actions.count { it is Action.TakeScreenshot } == 0) {171 Action.TakeScreenshot("").runAction(actionExecutor, reportScreen)172 }173 fontScale?.let {174 Action.SetFontScale(FontScale.DEFAULT).runAction(actionExecutor, reportScreen)175 }176 Action.CloseApp.runAction(actionExecutor, reportScreen)177 resetScreenSizeAndDensity(config, screen, reportScreen)178 screen.shellsAfter.forEach { shellAfter ->179 Action.ShellAfterScreen(shellAfter).runAction(180 actionExecutor,181 reportScreen,182 shellAfter.isNotBlank(),183 )184 }185 }186}187context(DescribeSpecContainerScope)188internal suspend fun ActionExecutor.resetScreenSizeAndDensity(189 config: Config,190 afterScreen: ReportScreen,191) {192 config.globalScreenSize.reset(this, afterScreen)193 config.globalScreenDensity.reset(this, afterScreen)194}195context(DescribeSpecContainerScope)196internal suspend fun ActionExecutor.setScreenSizeAndDensity(197 screen: Screen,198 reportScreen: ReportScreen,199) {200 screen.screenDensity.apply(201 this,202 reportScreen,203 )204 screen.screenSize.apply(205 this,206 reportScreen,207 )208}209context(DescribeSpecContainerScope)210internal suspend fun ActionExecutor.resetScreenSizeAndDensity(211 config: Config,212 screen: Screen,213 reportScreen: ReportScreen,214) {215 screen.screenSize.reset(this, reportScreen)216 screen.screenDensity.reset(this, reportScreen)217 config.globalScreenDensity.apply(218 this,219 reportScreen,220 screen.screenDensity != null,221 )222 config.globalScreenSize.apply(223 this,...

Full Screen

Full Screen

Action.kt

Source:Action.kt Github

copy

Full Screen

...108 is Action.TrimMemory -> "Send trim memory <${trimMemoryLevel.level}>"109 is Action.TypeText -> "Type text <$text>"110 }111}112context(DescribeSpecContainerScope)113internal suspend fun Action.runAction(114 actionExecutor: ActionExecutor,115 reportScreen: ReportScreen,116 executeCondition: Boolean = true,117) {118 if (executeCondition) {119 val action = this120 it(action.title()) {121 when (val reportAction = actionExecutor.execute(action)) {122 is Common -> reportScreen.common.add(reportAction)123 is Memory -> reportScreen.memory.add(reportAction)124 is GfxInfo -> reportScreen.gfxInfo.add(reportAction)125 is CpuUsage -> reportScreen.cpuUsage.add(reportAction)126 is Screenshot -> reportScreen.screenshots.add(...

Full Screen

Full Screen

DescribeSpecContainerScope.kt

Source:DescribeSpecContainerScope.kt Github

copy

Full Screen

...30) : AbstractContainerScope(testScope) {31 /**32 * Registers a container test.33 */34 suspend fun context(name: String, test: suspend DescribeSpecContainerScope.() -> Unit) {35 registerContainer(TestName("Context: ", name, false), false, null) { DescribeSpecContainerScope(this).test() }36 }37 @ExperimentalKotest38 fun context(name: String): ContainerWithConfigBuilder<DescribeSpecContainerScope> =39 ContainerWithConfigBuilder(TestName(name), this, false) { DescribeSpecContainerScope(it) }40 /**41 * Registers a disabled container test.42 */43 suspend fun xcontext(name: String, test: suspend DescribeSpecContainerScope.() -> Unit) {44 registerContainer(TestName("Context: ", name, false), true, null) { DescribeSpecContainerScope(this).test() }45 }46 @ExperimentalKotest47 fun xcontext(name: String): ContainerWithConfigBuilder<DescribeSpecContainerScope> =48 ContainerWithConfigBuilder(TestName("Context: ", name, false), this, true) { DescribeSpecContainerScope(it) }49 /**50 * Registers a container test.51 */52 suspend fun describe(name: String, test: suspend DescribeSpecContainerScope.() -> Unit) {53 registerContainer(TestName("Describe: ", name, false), false, null) { DescribeSpecContainerScope(this).test() }54 }55 /**56 * Registers a container test.57 */58 suspend fun xdescribe(name: String, test: suspend DescribeSpecContainerScope.() -> Unit) {59 registerContainer(TestName("Describe: ", name, false), true, null) { DescribeSpecContainerScope(this).test() }60 }61 @ExperimentalKotest...

Full Screen

Full Screen

DescribeSpecRootScope.kt

Source:DescribeSpecRootScope.kt Github

copy

Full Screen

...4import io.kotest.core.test.TestScope5@Deprecated("Renamed to DescribeSpecRootScope. Deprecated since 5.0")6typealias DescribeSpecRootContext = DescribeSpecRootScope7/**8 * A context that allows root tests to be registered using the syntax:9 *10 * describe("some test")11 *12 * or13 *14 * xdescribe("some disabled test")15 */16interface DescribeSpecRootScope : RootScope {17 fun context(name: String, test: suspend DescribeSpecContainerScope.() -> Unit) {18 addContainer(TestName("Context: ", name, false), false, null) { DescribeSpecContainerScope(this).test() }19 }20 fun xcontext(name: String, test: suspend DescribeSpecContainerScope.() -> Unit) {21 addContainer(TestName("Context: ", name, false), true, null) { DescribeSpecContainerScope(this).test() }22 }23 @ExperimentalKotest24 fun context(name: String): RootContainerWithConfigBuilder<DescribeSpecContainerScope> =25 RootContainerWithConfigBuilder(TestName(name), xdisabled = false, this) { DescribeSpecContainerScope(it) }26 @ExperimentalKotest27 fun xcontext(name: String): RootContainerWithConfigBuilder<DescribeSpecContainerScope> =28 RootContainerWithConfigBuilder(TestName(name), xdisabled = true, this) { DescribeSpecContainerScope(it) }29 fun describe(name: String, test: suspend DescribeSpecContainerScope.() -> Unit) {30 addContainer(31 TestName("Describe: ", name, false),32 disabled = false,33 null34 ) { DescribeSpecContainerScope(this).test() }35 }36 fun xdescribe(name: String, test: suspend DescribeSpecContainerScope.() -> Unit) {37 addContainer(38 TestName("Describe: ", name, false),39 disabled = true,40 null41 ) { DescribeSpecContainerScope(this).test() }...

Full Screen

Full Screen

StringExtension.kt

Source:StringExtension.kt Github

copy

Full Screen

...25}26internal fun String.safeForPath(): String {27 return this.trim().replace("[.,;!@#$%^&*()+=>< ]".toRegex(), "_")28}29context(DescribeSpecContainerScope)30internal suspend fun String.runShellAction(31 timeProvider: TimeProvider,32 shellExecutor: ShellExecutor,33 reportScreen: ReportScreen,34 executeCondition: Boolean = true,35) {36 if (executeCondition) {37 val command = this38 it("Run command <$command>") {39 val startTime = timeProvider.getTimeMillis()40 shellExecutor.runShellCommand(command, fromRootFolder = true)41 val endTime = timeProvider.getTimeMillis()42 reportScreen.common.add(Common(-1, "Run command <$command>", startTime, endTime))43 }...

Full Screen

Full Screen

ScreenDensityExtension.kt

Source:ScreenDensityExtension.kt Github

copy

Full Screen

...4import fi.epicbot.toster.model.Density5import fi.epicbot.toster.model.runAction6import fi.epicbot.toster.report.model.ReportScreen7import io.kotest.core.spec.style.scopes.DescribeSpecContainerScope8context (DescribeSpecContainerScope)9internal suspend fun Density?.apply(10 actionExecutor: ActionExecutor,11 reportScreen: ReportScreen,12 executeCondition: Boolean = true,13) {14 this?.let { screenDensity ->15 Action.SetScreenDensity(screenDensity)16 .runAction(actionExecutor, reportScreen, executeCondition)17 }18}19context (DescribeSpecContainerScope)20internal suspend fun Density?.reset(21 actionExecutor: ActionExecutor,22 reportScreen: ReportScreen,23) {24 Action.ResetScreenDensity.runAction(25 actionExecutor,26 reportScreen,27 executeCondition = this != null28 )29}

Full Screen

Full Screen

ScreenSizeExtension.kt

Source:ScreenSizeExtension.kt Github

copy

Full Screen

...4import fi.epicbot.toster.model.ScreenSize5import fi.epicbot.toster.model.runAction6import fi.epicbot.toster.report.model.ReportScreen7import io.kotest.core.spec.style.scopes.DescribeSpecContainerScope8context (DescribeSpecContainerScope)9internal suspend fun ScreenSize?.apply(10 actionExecutor: ActionExecutor,11 reportScreen: ReportScreen,12 executeCondition: Boolean = true,13) {14 this?.let { screenSize ->15 Action.SetScreenSize(screenSize)16 .runAction(actionExecutor, reportScreen, executeCondition)17 }18}19context (DescribeSpecContainerScope)20internal suspend fun ScreenSize?.reset(21 actionExecutor: ActionExecutor,22 reportScreen: ReportScreen,23) {24 Action.ResetScreenSize.runAction(25 actionExecutor,26 reportScreen,27 executeCondition = this != null28 )29}

Full Screen

Full Screen

ShellExtension.kt

Source:ShellExtension.kt Github

copy

Full Screen

...3import fi.epicbot.toster.model.Apk4import fi.epicbot.toster.report.model.ReportScreen5import fi.epicbot.toster.time.TimeProvider6import io.kotest.core.spec.style.scopes.DescribeSpecContainerScope7context(DescribeSpecContainerScope)8internal suspend fun ShellExecutor.runShellsForApk(9 timeProvider: TimeProvider,10 apk: Apk,11): ReportScreen {12 val apkReport = ReportScreen(name = "Before")13 apk.shellsBefore.forEach { shell ->14 shell.runShellAction(15 timeProvider,16 this,17 apkReport,18 executeCondition = shell.isNotBlank(),19 )20 }21 return apkReport...

Full Screen

Full Screen

context

Using AI Code Generation

copy

Full Screen

1fun DescribeSpecContainerScope.xcontext(name: String, test: suspend DescribeSpecContainerScope.() -> Unit): Unit2fun DescribeSpecContainerScope.xcontext(name: String): Unit3fun DescribeSpecContainerScope.xit(name: String, test: suspend TestContext.() -> Unit): Unit4fun DescribeSpecContainerScope.xit(name: String): Unit5fun DescribeSpecContainerScope.xspec(body: DescribeSpec.() -> Unit): Unit6fun DescribeSpecContainerScope.xspec(name: String, body: DescribeSpec.() -> Unit): Unit7fun DescribeSpecContainerScope.xspec(name: String): Unit8fun DescribeSpecContainerScope.xspec(): Unit

Full Screen

Full Screen

context

Using AI Code Generation

copy

Full Screen

1fun main() {2val context = DescribeSpec({3describe("DescribeSpec") {4context("with some context") {5it("should have some test") {6}7}8}9})10context.execute()11}12fun main() {13val context = FunSpec({14context("with some context") {15it("should have some test") {16}17}18})19context.execute()20}21fun main() {22val context = FreeSpec({23context("with some context") {24it("should have some test") {25}26}27})28context.execute()29}30fun main() {31val context = ShouldSpec({32context("with some context") {33it("should have some test") {34}35}36})37context.execute()38}39fun main() {40val context = StringSpec({41context("with some context") {42it("should have some test") {43}44}45})46context.execute()47}48fun main() {49val context = WordSpec({50context("with some context") {51it("should have some test") {52}53}54})55context.execute()56}57fun main() {58val context = ExpectSpec({59context("with some context") {60it("should have some test") {61}62}63})64context.execute()65}66fun main() {67val context = FeatureSpec({68context("with some context") {69it("should have some test") {70}71}72})73context.execute()74}75fun main() {76val context = BehaviorSpec({77context("with some context") {78it("should have some test")

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Kotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in DescribeSpecContainerScope

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful