├── gwen
├── .gitignore
├── build.gradle
└── src
│ └── main
│ └── java
│ └── com
│ └── shazam
│ └── gwen
│ └── Gwen.kt
├── sample
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── ic_launcher_round.png
│ │ │ │ └── ic_launcher_foreground.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── ic_launcher_round.png
│ │ │ │ └── ic_launcher_foreground.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── ic_launcher_round.png
│ │ │ │ └── ic_launcher_foreground.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── ic_launcher_round.png
│ │ │ │ └── ic_launcher_foreground.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── ic_launcher_round.png
│ │ │ │ └── ic_launcher_foreground.png
│ │ │ ├── values
│ │ │ │ ├── colors.xml
│ │ │ │ ├── strings.xml
│ │ │ │ └── styles.xml
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── layout
│ │ │ │ └── activity_main.xml
│ │ │ └── drawable
│ │ │ │ └── ic_launcher_background.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── shazam
│ │ │ └── gwen
│ │ │ └── sample
│ │ │ └── MainActivity.kt
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── shazam
│ │ └── gwen
│ │ └── sample
│ │ ├── actions
│ │ ├── LaunchesActions.kt
│ │ ├── SelectsActions.kt
│ │ └── HasActions.kt
│ │ ├── actors
│ │ └── User.kt
│ │ ├── asserters
│ │ └── SeesAssertions.kt
│ │ ├── LoginTest.kt
│ │ └── RawEspressoLoginTest.kt
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── README.md
├── LICENSE
├── gradle.properties
├── gradlew.bat
└── gradlew
/gwen/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/sample/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':gwen', ':sample'
2 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shazam/GWEN-Kotlin-Demo/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea
5 | .DS_Store
6 | /build
7 | /captures
8 | .externalNativeBuild
9 |
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shazam/GWEN-Kotlin-Demo/HEAD/sample/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shazam/GWEN-Kotlin-Demo/HEAD/sample/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shazam/GWEN-Kotlin-Demo/HEAD/sample/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shazam/GWEN-Kotlin-Demo/HEAD/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shazam/GWEN-Kotlin-Demo/HEAD/sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shazam/GWEN-Kotlin-Demo/HEAD/sample/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shazam/GWEN-Kotlin-Demo/HEAD/sample/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shazam/GWEN-Kotlin-Demo/HEAD/sample/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shazam/GWEN-Kotlin-Demo/HEAD/sample/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shazam/GWEN-Kotlin-Demo/HEAD/sample/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-hdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shazam/GWEN-Kotlin-Demo/HEAD/sample/src/main/res/mipmap-hdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-mdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shazam/GWEN-Kotlin-Demo/HEAD/sample/src/main/res/mipmap-mdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shazam/GWEN-Kotlin-Demo/HEAD/sample/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # A Kotlin DSL for Acceptance Tests
2 |
3 | A sample project to support the blog post: https://blog.shazam.com/a-kotlin-dsl-for-acceptance-tests-8a825388879e
4 |
5 |
6 |
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shazam/GWEN-Kotlin-Demo/HEAD/sample/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shazam/GWEN-Kotlin-Demo/HEAD/sample/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/gwen/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'kotlin'
2 |
3 | dependencies {
4 | compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
5 | }
6 |
7 | sourceCompatibility = "1.7"
8 | targetCompatibility = "1.7"
9 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Sample
3 | Is logged in: %s
4 | Log in
5 | Log out
6 |
7 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue May 01 12:26:42 BST 2018
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
7 |
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright 2019 Apple Inc.
2 |
3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
4 |
5 | You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6 |
7 | 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.
8 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/sample/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/sample/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/gwen/src/main/java/com/shazam/gwen/Gwen.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Shazam Entertainment Limited
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
5 | *
6 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * 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.
9 | */
10 |
11 | package com.shazam.gwen
12 |
13 | import kotlin.annotation.AnnotationTarget.CLASS
14 | import kotlin.annotation.AnnotationTarget.TYPE
15 |
16 | @DslMarker
17 | @Target(CLASS, TYPE)
18 | annotation class GwenMarker
19 |
20 | object Arranger
21 |
22 | object Actor
23 |
24 | object Asserter
25 |
26 | infix fun Any.given(block: (@GwenMarker Arranger).() -> Unit) = block.invoke(Arranger)
27 |
28 | infix fun Any.whenever(block: (@GwenMarker Actor).() -> Unit) = block.invoke(Actor)
29 |
30 | infix fun Any.then(block: (@GwenMarker Asserter).() -> Unit) = block.invoke(Asserter)
31 |
--------------------------------------------------------------------------------
/sample/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'kotlin-android-extensions'
4 | android {
5 | compileSdkVersion 26
6 | buildToolsVersion '27.0.3'
7 |
8 |
9 | defaultConfig {
10 | applicationId "com.shazam.gwen.sample"
11 | minSdkVersion 19
12 | targetSdkVersion 26
13 | versionCode 1
14 | versionName "1.0"
15 |
16 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
17 |
18 | }
19 |
20 | buildTypes {
21 | release {
22 | minifyEnabled false
23 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
24 | }
25 | }
26 |
27 | }
28 |
29 | dependencies {
30 | implementation project(":gwen")
31 | implementation 'com.android.support:appcompat-v7:26.1.0'
32 | implementation 'com.android.support.constraint:constraint-layout:1.0.2'
33 | testImplementation 'junit:junit:4.12'
34 | androidTestImplementation('com.android.support.test.espresso:espresso-core:3.0.1', {
35 | exclude group: 'com.android.support', module: 'support-annotations'
36 | })
37 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
38 | }
39 |
--------------------------------------------------------------------------------
/sample/src/androidTest/java/com/shazam/gwen/sample/actions/LaunchesActions.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Shazam Entertainment Limited
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
5 | *
6 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * 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.
9 | */
10 |
11 | package com.shazam.gwen.sample.actions
12 |
13 | import android.content.Intent
14 | import android.content.Intent.FLAG_ACTIVITY_NEW_TASK
15 | import android.support.test.InstrumentationRegistry.getInstrumentation
16 | import com.shazam.gwen.sample.MainActivity
17 |
18 | object LaunchesActions {
19 |
20 | fun app() {
21 | val instrumentation = getInstrumentation()
22 | val intent = Intent(instrumentation.targetContext, MainActivity::class.java).apply {
23 | addFlags(FLAG_ACTIVITY_NEW_TASK)
24 | }
25 | instrumentation.startActivitySync(intent)
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/sample/src/androidTest/java/com/shazam/gwen/sample/actions/SelectsActions.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Shazam Entertainment Limited
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
5 | *
6 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * 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.
9 | */
10 |
11 | package com.shazam.gwen.sample.actions
12 |
13 | import android.support.test.espresso.Espresso.onView
14 | import android.support.test.espresso.action.ViewActions.click
15 | import android.support.test.espresso.matcher.ViewMatchers.withId
16 | import android.support.test.espresso.matcher.ViewMatchers.withText
17 | import com.shazam.gwen.sample.R
18 | import org.hamcrest.core.AllOf.allOf
19 |
20 | object SelectsActions {
21 |
22 | fun logout() {
23 | onView(allOf(withId(R.id.login_button), withText(R.string.logout))).perform(click())
24 | }
25 |
26 | fun login() {
27 | onView(allOf(withId(R.id.login_button), withText(R.string.login))).perform(click())
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
18 |
19 |
29 |
30 |
--------------------------------------------------------------------------------
/sample/src/androidTest/java/com/shazam/gwen/sample/actions/HasActions.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Shazam Entertainment Limited
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
5 | *
6 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * 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.
9 | */
10 |
11 | package com.shazam.gwen.sample.actions
12 |
13 | import android.preference.PreferenceManager.getDefaultSharedPreferences
14 | import android.support.test.InstrumentationRegistry.getInstrumentation
15 | import com.shazam.gwen.sample.MainActivity.Companion.IS_LOGGED_IN_PREF_KEY
16 |
17 | object HasActions {
18 |
19 | fun loggedIn() {
20 | val instrumentation = getInstrumentation()
21 | getDefaultSharedPreferences(instrumentation.targetContext.applicationContext).edit().apply {
22 | putBoolean(IS_LOGGED_IN_PREF_KEY, true)
23 | commit()
24 | }
25 | }
26 |
27 | fun loggedOut() {
28 | val instrumentation = getInstrumentation()
29 | getDefaultSharedPreferences(instrumentation.targetContext.applicationContext).edit().apply {
30 | putBoolean(IS_LOGGED_IN_PREF_KEY, false)
31 | commit()
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/sample/src/androidTest/java/com/shazam/gwen/sample/actors/User.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Shazam Entertainment Limited
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
5 | *
6 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * 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.
9 | */
10 |
11 | package com.shazam.gwen.sample.actors
12 |
13 | import com.shazam.gwen.Actor
14 | import com.shazam.gwen.Arranger
15 | import com.shazam.gwen.Asserter
16 | import com.shazam.gwen.sample.actions.HasActions
17 | import com.shazam.gwen.sample.actions.LaunchesActions
18 | import com.shazam.gwen.sample.actions.SelectsActions
19 | import com.shazam.gwen.sample.asserters.SeesAssertions
20 |
21 | object User
22 |
23 | val Arranger.user: User
24 | get() = User
25 |
26 | val Actor.user: User
27 | get() = User
28 |
29 | val Asserter.user: User
30 | get() = User
31 |
32 | infix fun User.has(block: HasActions.() -> Unit): User {
33 | block.invoke(HasActions)
34 | return this
35 | }
36 |
37 | infix fun User.launches(block: LaunchesActions.() -> Unit): User {
38 | block.invoke(LaunchesActions)
39 | return this
40 | }
41 |
42 | infix fun User.selects(block: SelectsActions.() -> Unit): User {
43 | block.invoke(SelectsActions)
44 | return this
45 | }
46 |
47 | infix fun User.sees(block: SeesAssertions.() -> Unit): User {
48 | block.invoke(SeesAssertions)
49 | return this
50 | }
51 |
--------------------------------------------------------------------------------
/sample/src/androidTest/java/com/shazam/gwen/sample/asserters/SeesAssertions.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Shazam Entertainment Limited
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
5 | *
6 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * 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.
9 | */
10 |
11 | package com.shazam.gwen.sample.asserters
12 |
13 | import android.support.test.InstrumentationRegistry.getInstrumentation
14 | import android.support.test.espresso.Espresso.onView
15 | import android.support.test.espresso.action.ViewActions
16 | import android.support.test.espresso.matcher.ViewMatchers.withId
17 | import android.support.test.espresso.matcher.ViewMatchers.withText
18 | import com.shazam.gwen.sample.R
19 | import org.hamcrest.core.AllOf
20 |
21 | object SeesAssertions {
22 |
23 | fun loggedOut() {
24 | val instrumentation = getInstrumentation()
25 | val expectedText = instrumentation.targetContext.getString(R.string.is_logged_in, "false")
26 | onView(AllOf.allOf(withId(R.id.label), withText(expectedText))).perform(ViewActions.click())
27 | }
28 |
29 | fun loggedIn() {
30 | val instrumentation = getInstrumentation()
31 | val expectedText = instrumentation.targetContext.getString(R.string.is_logged_in, "true")
32 | onView(AllOf.allOf(withId(R.id.label), withText(expectedText))).perform(ViewActions.click())
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/sample/src/androidTest/java/com/shazam/gwen/sample/LoginTest.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Shazam Entertainment Limited
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
5 | *
6 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * 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.
9 | */
10 |
11 | package com.shazam.gwen.sample
12 |
13 | import android.support.test.runner.AndroidJUnit4
14 | import com.shazam.gwen.given
15 | import com.shazam.gwen.sample.actors.has
16 | import com.shazam.gwen.sample.actors.launches
17 | import com.shazam.gwen.sample.actors.sees
18 | import com.shazam.gwen.sample.actors.selects
19 | import com.shazam.gwen.sample.actors.user
20 | import com.shazam.gwen.then
21 | import com.shazam.gwen.whenever
22 | import org.junit.Test
23 | import org.junit.runner.RunWith
24 |
25 | @RunWith(AndroidJUnit4::class)
26 | class LoginTest {
27 | @Test
28 | fun logsInWhenUserSelectsLogin() {
29 | given {
30 | user has { loggedOut() }
31 | } whenever {
32 | user launches {
33 | app()
34 | }
35 | user selects { login() }
36 | } then {
37 | user sees { loggedIn() }
38 | }
39 | }
40 |
41 | @Test
42 | fun logsOutWhenUserSelectsLogout() {
43 | given {
44 | user has { loggedIn() }
45 | } whenever {
46 | user launches {
47 | app()
48 | } selects {
49 | logout()
50 | }
51 | } then {
52 | user sees { loggedOut() }
53 | }
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/shazam/gwen/sample/MainActivity.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Shazam Entertainment Limited
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
5 | *
6 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * 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.
9 | */
10 |
11 | package com.shazam.gwen.sample
12 |
13 | import android.os.Bundle
14 | import android.preference.PreferenceManager.getDefaultSharedPreferences
15 | import android.support.v7.app.AppCompatActivity
16 | import android.widget.TextView
17 |
18 | class MainActivity : AppCompatActivity() {
19 |
20 | private val preferences by lazy {
21 | getDefaultSharedPreferences(applicationContext)
22 | }
23 |
24 | private var isLoggedIn
25 | get() = preferences.getBoolean(IS_LOGGED_IN_PREF_KEY, false)
26 | set(value) {
27 | preferences.edit().apply {
28 | putBoolean(IS_LOGGED_IN_PREF_KEY, value)
29 | commit()
30 | }
31 | }
32 |
33 | private val button by lazy {
34 | findViewById(R.id.login_button)
35 | }
36 |
37 | private val label by lazy {
38 | findViewById(R.id.label)
39 | }
40 |
41 | override fun onCreate(savedInstanceState: Bundle?) {
42 | super.onCreate(savedInstanceState)
43 | setContentView(R.layout.activity_main)
44 |
45 | button.setOnClickListener {
46 | isLoggedIn = !isLoggedIn
47 | updateUi()
48 | }
49 |
50 | updateUi()
51 | }
52 |
53 | private fun updateUi() {
54 | button.text = if (isLoggedIn) getString(R.string.logout) else getString(R.string.login)
55 | label.text = getString(R.string.is_logged_in, isLoggedIn.toString())
56 | }
57 |
58 | companion object {
59 | const val IS_LOGGED_IN_PREF_KEY = "com.shazam.gwen.sample.IS_LOGGED_IN"
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/sample/src/androidTest/java/com/shazam/gwen/sample/RawEspressoLoginTest.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Shazam Entertainment Limited
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
5 | *
6 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * 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.
9 | */
10 |
11 | package com.shazam.gwen.sample
12 |
13 | import android.content.Intent
14 | import android.preference.PreferenceManager.getDefaultSharedPreferences
15 | import android.support.test.InstrumentationRegistry
16 | import android.support.test.espresso.Espresso.onView
17 | import android.support.test.espresso.action.ViewActions
18 | import android.support.test.espresso.action.ViewActions.click
19 | import android.support.test.espresso.matcher.ViewMatchers.withId
20 | import android.support.test.espresso.matcher.ViewMatchers.withText
21 | import android.support.test.runner.AndroidJUnit4
22 | import com.shazam.gwen.sample.MainActivity.Companion.IS_LOGGED_IN_PREF_KEY
23 | import org.hamcrest.core.AllOf
24 | import org.hamcrest.core.AllOf.allOf
25 | import org.junit.Test
26 | import org.junit.runner.RunWith
27 |
28 | @RunWith(AndroidJUnit4::class)
29 | class RawEspressoLoginTest {
30 |
31 | @Test
32 | fun logsInWhenUserSelectsLogin() {
33 | val instrumentation = InstrumentationRegistry.getInstrumentation()
34 | getDefaultSharedPreferences(instrumentation.targetContext.applicationContext).edit().apply {
35 | putBoolean(IS_LOGGED_IN_PREF_KEY, false)
36 | commit()
37 | }
38 |
39 | val intent = Intent(instrumentation.targetContext, MainActivity::class.java).apply {
40 | addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
41 | }
42 | instrumentation.startActivitySync(intent)
43 |
44 | onView(allOf(withId(R.id.login_button), withText(R.string.login))).perform(click())
45 |
46 | val expectedText = instrumentation.targetContext.getString(R.string.is_logged_in, "true")
47 | onView(AllOf.allOf(withId(R.id.label), withText(expectedText))).perform(ViewActions.click())
48 | }
49 | }
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/sample/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
12 |
17 |
22 |
27 |
32 |
37 |
42 |
47 |
52 |
57 |
62 |
67 |
72 |
77 |
82 |
87 |
92 |
97 |
102 |
107 |
112 |
113 |
114 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------