-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
253 additions
and
164 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
53 changes: 53 additions & 0 deletions
53
android/app/src/androidTest/java/network/mysterium/BasicFlowWithRegistrationTest.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,53 @@ | ||
package network.mysterium | ||
|
||
import androidx.test.espresso.action.ViewActions.* | ||
import androidx.test.espresso.assertion.ViewAssertions.matches | ||
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed | ||
import androidx.test.espresso.matcher.ViewMatchers.withText | ||
import androidx.test.filters.LargeTest | ||
import androidx.test.rule.ActivityTestRule | ||
import androidx.test.runner.AndroidJUnit4 | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
@LargeTest | ||
@RunWith(AndroidJUnit4::class) | ||
class BasicFlowWithRegistrationTest { | ||
|
||
@Rule | ||
@JvmField | ||
var mActivityTestRule = ActivityTestRule(MainActivity::class.java) | ||
|
||
// TODO: For some reasons this fails with Failed to grant permissions, see logcat for details error. | ||
// @Rule | ||
// @JvmField | ||
// val grantPermissionRule: GrantPermissionRule = GrantPermissionRule.grant(android.Manifest.permission.BIND_VPN_SERVICE) | ||
|
||
@Test | ||
fun basicFlowWithRegistrationTest() { | ||
Views.acceptTermsButton.perform(click()) | ||
|
||
Views.balanceLabel.perform(click()) | ||
|
||
Views.registrationPleaseWaitLabel.check(matches(withText("Please wait"))) | ||
|
||
Views.topUpButton.check(matches(isDisplayed())) | ||
|
||
Views.navBackButton.perform(click()) | ||
|
||
Views.selectProposalLayout.perform(click()) | ||
|
||
Views.proposalSearchInput.perform(replaceText("0xfbf"), closeSoftKeyboard()) | ||
|
||
Views.selectProposalItem(0) | ||
|
||
Views.connectionButton.perform(click()) | ||
|
||
Views.checkStatusLabel("Connected") | ||
|
||
Views.connectionButton.perform(click()) | ||
|
||
Views.checkStatusLabel("Disconnected") | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
android/app/src/androidTest/java/network/mysterium/Helpers.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,43 @@ | ||
package network.mysterium | ||
|
||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.test.espresso.Espresso | ||
import androidx.test.espresso.NoMatchingViewException | ||
import androidx.test.espresso.ViewInteraction | ||
import androidx.test.espresso.assertion.ViewAssertions | ||
import androidx.test.espresso.matcher.ViewMatchers | ||
import org.hamcrest.Description | ||
import org.hamcrest.Matcher | ||
import org.hamcrest.TypeSafeMatcher | ||
|
||
fun onViewReady(viewMatcher: Matcher<View>, count: Int = 3, sleepMillis: Long = 2000): ViewInteraction { | ||
for (i in 1..count) { | ||
try { | ||
return Espresso.onView(viewMatcher).check(ViewAssertions.matches(ViewMatchers.isDisplayed())) | ||
} catch (e: NoMatchingViewException) { | ||
if (i == count) { | ||
throw e | ||
} | ||
Thread.sleep(sleepMillis) | ||
} | ||
} | ||
throw Throwable("view not found") | ||
} | ||
|
||
fun childAtPosition( | ||
parentMatcher: Matcher<View>, position: Int): Matcher<View> { | ||
|
||
return object : TypeSafeMatcher<View>() { | ||
override fun describeTo(description: Description) { | ||
description.appendText("Child at position $position in parent ") | ||
parentMatcher.describeTo(description) | ||
} | ||
|
||
public override fun matchesSafely(view: View): Boolean { | ||
val parent = view.parent | ||
return parent is ViewGroup && parentMatcher.matches(parent) | ||
&& view == parent.getChildAt(position) | ||
} | ||
} | ||
} |
Oops, something went wrong.