-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from wealthfront/view-matcher
#19 Use Espresso API to modify views
- Loading branch information
Showing
56 changed files
with
939 additions
and
669 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
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 @@ | ||
/build |
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,39 @@ | ||
plugins { | ||
id(Plugins.androidLibrary) | ||
id(Plugins.kotlinAndroid) | ||
} | ||
|
||
dependencies { | ||
implementation(Dependencies.recyclerView) | ||
implementation(Dependencies.espressoCore) | ||
implementation(Dependencies.espressoContrib) | ||
implementation(Dependencies.appCompat) | ||
} | ||
|
||
android { | ||
this.compileSdk = Versions.compileSdkVersion | ||
|
||
defaultConfig { | ||
this.minSdk = Versions.minSdkVersion | ||
this.targetSdk = Versions.targetSdkVersion | ||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" | ||
} | ||
|
||
compileOptions { | ||
sourceCompatibility(JavaVersion.VERSION_1_8) | ||
targetCompatibility(JavaVersion.VERSION_1_8) | ||
} | ||
kotlinOptions { | ||
jvmTarget = "1.8" | ||
} | ||
|
||
testOptions.apply { | ||
animationsDisabled = true | ||
unitTests.apply { | ||
isIncludeAndroidResources = true | ||
isReturnDefaultValues = true | ||
} | ||
} | ||
|
||
namespace = "com.wealthfront.screencaptor.test" | ||
} |
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,23 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.wealthfront.screencaptor" | ||
> | ||
|
||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> | ||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> | ||
|
||
<application> | ||
<activity | ||
android:name="com.wealthfront.screencaptor.SampleActivity" | ||
android:exported="false" | ||
android:theme="@style/Theme.AppCompat" | ||
> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
28 changes: 28 additions & 0 deletions
28
screencaptor-test/src/main/java/com/wealthfront/screencaptor/MessageAdapter.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,28 @@ | ||
package com.wealthfront.screencaptor | ||
|
||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import android.widget.TextView | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.wealthfront.screencaptor.test.R | ||
|
||
class MessageAdapter(private val messages: Array<String>) : RecyclerView.Adapter<MessageAdapter.MessageViewHolder>() { | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MessageViewHolder { | ||
val view = LayoutInflater.from(parent.context) | ||
.inflate(R.layout.message_row_item, parent, false) as TextView | ||
|
||
return MessageViewHolder(view) | ||
} | ||
|
||
override fun onBindViewHolder(holder: MessageViewHolder, position: Int) { | ||
holder.view.text = messages[position] | ||
} | ||
|
||
override fun getItemCount(): Int = messages.size | ||
|
||
data class MessageViewHolder( | ||
val view: TextView | ||
) : RecyclerView.ViewHolder(view) | ||
} | ||
|
28 changes: 28 additions & 0 deletions
28
screencaptor-test/src/main/java/com/wealthfront/screencaptor/RecyclerViewMatchers.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,28 @@ | ||
package com.wealthfront.screencaptor | ||
|
||
import android.view.View | ||
import androidx.recyclerview.widget.RecyclerView | ||
import androidx.test.espresso.matcher.BoundedMatcher | ||
import androidx.test.espresso.matcher.ViewMatchers | ||
import org.hamcrest.Description | ||
|
||
object RecyclerViewMatchers { | ||
|
||
fun hasItemWithText(text: String) = object : BoundedMatcher<View, View>(View::class.java) { | ||
override fun describeTo(description: Description) { | ||
description.appendText("Searching for item with: $text") | ||
} | ||
|
||
override fun matchesSafely(item: View): Boolean { | ||
if (item is RecyclerView) { | ||
for (i in 0 until item.childCount) { | ||
val childView = item.findViewHolderForAdapterPosition(i)!!.itemView | ||
if (ViewMatchers.withText(text).matches(childView)) { | ||
return true | ||
} | ||
} | ||
} | ||
return false | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
screencaptor-test/src/main/java/com/wealthfront/screencaptor/SampleActivity.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,34 @@ | ||
package com.wealthfront.screencaptor | ||
|
||
import android.app.AlertDialog | ||
import android.os.Bundle | ||
import android.widget.Button | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.recyclerview.widget.DividerItemDecoration | ||
import androidx.recyclerview.widget.LinearLayoutManager | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.wealthfront.screencaptor.test.R | ||
|
||
class SampleActivity : AppCompatActivity() { | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.screenshot_test) | ||
findViewById<Button>(R.id.showDialog).setOnClickListener { | ||
AlertDialog.Builder(this) | ||
.setMessage("I am a Dialog") | ||
.show() | ||
} | ||
|
||
val messageList = findViewById<RecyclerView>(R.id.messageList) | ||
val layoutManager = LinearLayoutManager(this, RecyclerView.VERTICAL, false) | ||
messageList.layoutManager = layoutManager | ||
|
||
val dividerItemDecoration = DividerItemDecoration(this, layoutManager.orientation) | ||
messageList.addItemDecoration(dividerItemDecoration) | ||
|
||
val messages = arrayOf("Bulldog", "Corgi", "Mastiff", "Labrador Retriever", "Border Collie") | ||
messageList.adapter = MessageAdapter(messages) | ||
messageList.adapter!!.notifyDataSetChanged() | ||
} | ||
} |
File renamed without changes
File renamed without changes
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,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<TextView | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
/> |
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 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
|
||
<androidx.core.widget.NestedScrollView | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:id="@+id/scrollView" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:background="#4B0082" | ||
android:scrollbars="vertical" | ||
tools:ignore="HardcodedText" | ||
> | ||
|
||
<LinearLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:orientation="vertical" | ||
> | ||
|
||
<ImageView | ||
android:id="@+id/wealthfrontIcon" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:padding="40dp" | ||
android:src="@drawable/wf_logo" | ||
/> | ||
|
||
<EditText | ||
android:id="@+id/textField" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:gravity="center" | ||
android:hint="Welcome to Wealthfront!!!" | ||
android:inputType="text" | ||
android:textColorHint="#FFFFFF" | ||
tools:ignore="Autofill,LabelFor" | ||
/> | ||
|
||
<TextView | ||
android:id="@+id/textView" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:text="Some sample data which is really long, so long that it wraps to another line and maybe even three lines" | ||
/> | ||
|
||
<Button | ||
android:id="@+id/showDialog" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="Show dialog" | ||
/> | ||
|
||
<ScrollView | ||
android:id="@+id/anotherScrollView" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
/> | ||
|
||
<HorizontalScrollView | ||
android:id="@+id/horizonalScrollView" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
/> | ||
|
||
<androidx.recyclerview.widget.RecyclerView | ||
android:id="@+id/messageList" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
/> | ||
</LinearLayout> | ||
|
||
</androidx.core.widget.NestedScrollView> |
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
Oops, something went wrong.