Skip to content

Commit

Permalink
Merge branch 'master' of github.com:QAutomatron/kopi
Browse files Browse the repository at this point in the history
# Conflicts:
#	build.gradle
  • Loading branch information
QAutomatron committed Aug 26, 2019
2 parents df935ef + 791a8fb commit 166fb4c
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 9 deletions.
10 changes: 6 additions & 4 deletions library/src/main/java/com/qautomatron/kopi/library/Utils.kt
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package com.qautomatron.kopi.library

import android.app.Instrumentation
import android.content.Context
import androidx.test.platform.app.InstrumentationRegistry

val instrumentation: Instrumentation
get() = InstrumentationRegistry.getInstrumentation()

val appContext: Context
get() = InstrumentationRegistry.getInstrumentation().targetContext
get() = instrumentation.targetContext

/**
* Return string from resources
*/
fun resourceToString(resource: Int, vararg a: Any): String {
return appContext.getString(resource, *a)
}
fun resourceToString(resource: Int, vararg a: Any): String = appContext.getString(resource, *a)
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.qautomatron.kopi.library.rule

import androidx.test.uiautomator.UiDevice
import com.qautomatron.kopi.library.instrumentation
import org.junit.rules.TestWatcher
import org.junit.runner.Description


class DisableAnimationsRule : TestWatcher() {

override fun starting(description: Description) = disableAnimations()

override fun finished(description: Description) = enableAnimations()

private fun disableAnimations() {
UiDevice.getInstance(instrumentation)
.executeShellCommand("settings put global transition_animation_scale 0")
UiDevice.getInstance(instrumentation)
.executeShellCommand("settings put global window_animation_scale 0")
UiDevice.getInstance(instrumentation)
.executeShellCommand("settings put global animator_duration_scale 0")
}

private fun enableAnimations() {
UiDevice.getInstance(instrumentation)
.executeShellCommand("settings put global transition_animation_scale 1")
UiDevice.getInstance(instrumentation)
.executeShellCommand("settings put global window_animation_scale 1")
UiDevice.getInstance(instrumentation)
.executeShellCommand("settings put global animator_duration_scale 1")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package com.qautomatron.kopi.library.steps
import androidx.test.espresso.Espresso
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.matcher.ViewMatchers.isRoot
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.By
import androidx.test.uiautomator.UiDevice
import androidx.test.uiautomator.Until
import com.azimolabs.conditionwatcher.ConditionWatcher
import com.qautomatron.kopi.library.element.action.SleepAction
import com.qautomatron.kopi.library.instrumentation
import com.qautomatron.kopi.library.wait.WaitForActivity
import org.junit.Assert.assertTrue

Expand All @@ -26,7 +26,7 @@ object DeviceSteps {
* Will use UI Automator to wait for package with name to be active
*/
fun packageShouldBeOpened(packageTitle: String, timeoutInSec: Int = 5) {
val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
val mDevice = UiDevice.getInstance(instrumentation)

assertTrue(
"Package <$packageTitle> should be present on screen",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.qautomatron.kopi.library.wait

import android.app.Activity
import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
import androidx.test.runner.lifecycle.ActivityLifecycleMonitorRegistry
import androidx.test.runner.lifecycle.Stage
import com.azimolabs.conditionwatcher.Instruction
import com.qautomatron.kopi.library.instrumentation

/**
* Base instruction to provide activity to watchers
Expand All @@ -15,7 +15,7 @@ abstract class BaseInstruction : Instruction() {

internal val activityInstance: Activity?
get() {
getInstrumentation().runOnMainSync {
instrumentation.runOnMainSync {
val resumedActivities = ActivityLifecycleMonitorRegistry.getInstance().getActivitiesInStage(Stage.RESUMED)
if (resumedActivities.iterator().hasNext()) {
currentActivity = resumedActivities.iterator().next()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import org.junit.Test;

import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;

/**
* Example local unit test, which will execute on the development machine (host).
Expand Down

0 comments on commit 166fb4c

Please sign in to comment.