-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PIA-633 - Add Sign In tests, screen objects and helpers
- Loading branch information
1 parent
ee43a5f
commit 4494536
Showing
8 changed files
with
175 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.privateinternetaccess.android.core | ||
|
||
import android.content.Context | ||
import android.content.Intent | ||
import androidx.test.platform.app.InstrumentationRegistry | ||
import androidx.test.uiautomator.UiDevice | ||
import org.junit.Before | ||
|
||
open class BaseUiAutomatorClass { | ||
|
||
private lateinit var device: UiDevice | ||
private lateinit var context: Context | ||
|
||
private fun startApp(packageName: String, activityName: String? = null) { | ||
context = InstrumentationRegistry.getInstrumentation().targetContext | ||
val intent = if (activityName == null) { | ||
context.packageManager.getLaunchIntentForPackage(packageName) | ||
} else { | ||
Intent().setClassName(packageName, activityName) | ||
} | ||
intent?.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) | ||
intent?.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK) // Clear out any previous instances | ||
context.startActivity(intent) | ||
} | ||
|
||
@Before | ||
fun setUp() { | ||
device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) | ||
device.pressHome() | ||
startApp("com.privateinternetaccess.android") | ||
} | ||
} |
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,18 @@ | ||
package com.privateinternetaccess.android.helpers | ||
|
||
import androidx.test.uiautomator.UiObject | ||
|
||
object ActionHelpers { | ||
|
||
fun clickIfExists(primaryUiObject : UiObject, secondaryUiObj: UiObject? = null) { | ||
if (primaryUiObject.exists()) { | ||
(secondaryUiObj ?: primaryUiObject).click() | ||
} | ||
} | ||
|
||
fun <T> inputTextInField(field: UiObject, data: T? = null) { | ||
field.clearTextField() | ||
field.click() | ||
field.text = data?.toString() ?: "" | ||
} | ||
} |
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,15 @@ | ||
package com.privateinternetaccess.android.helpers | ||
|
||
import androidx.test.platform.app.InstrumentationRegistry | ||
import androidx.test.uiautomator.UiDevice | ||
import androidx.test.uiautomator.UiObject | ||
import androidx.test.uiautomator.UiSelector | ||
|
||
object LocatorHelper { | ||
|
||
private val device: UiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) | ||
|
||
fun findByResourceId(id: String, instance: Int = 0): UiObject { | ||
return device.findObject(UiSelector().resourceId(id).instance(instance)) | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
app/src/androidTest/java/screens/objects/MainScreenPageObjects.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,9 @@ | ||
package com.privateinternetaccess.android.screens.objects | ||
|
||
import com.privateinternetaccess.android.helpers.LocatorHelper | ||
|
||
class MainScreenPageObjects { | ||
|
||
val connectButton = LocatorHelper.findByResourceId("com.privateinternetaccess.android:id/connection_background") | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
app/src/androidTest/java/screens/objects/SignInPageObjects.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,20 @@ | ||
package com.privateinternetaccess.android.screens.objects | ||
|
||
import com.privateinternetaccess.android.helpers.LocatorHelper | ||
|
||
class SignInPageObjects { | ||
|
||
val notificationPrompt = LocatorHelper.findByResourceId("com.android.permissioncontroller:id/permission_message") | ||
val allowNotifications = LocatorHelper.findByResourceId("com.android.permissioncontroller:id/permission_allow_button") | ||
val denyNotifications = LocatorHelper.findByResourceId("com.android.permissioncontroller:id/permission_deny_button") | ||
val reachLoginScreenButton = LocatorHelper.findByResourceId("com.privateinternetaccess.android:id/login") | ||
val usernameField = LocatorHelper.findByResourceId("com.privateinternetaccess.android:id/piaxEditText") | ||
val passwordField = LocatorHelper.findByResourceId("com.privateinternetaccess.android:id/piaxEditText", instance = 1) | ||
val loginButton = LocatorHelper.findByResourceId("com.privateinternetaccess.android:id/fragment_login_button") | ||
val vpnProfileOkButton = LocatorHelper.findByResourceId("com.privateinternetaccess.android:id/activity_vpn_permissions_button") | ||
val androidOkButton = LocatorHelper.findByResourceId("android:id/button1") | ||
|
||
val loginWithReceipt = LocatorHelper.findByResourceId("com.privateinternetaccess.android:id/fragment_login_receipt") | ||
|
||
val noUsernameOrPasswordError = LocatorHelper.findByResourceId("com.privateinternetaccess.android:id/piaxEditTextError") | ||
} |
35 changes: 35 additions & 0 deletions
35
app/src/androidTest/java/screens/steps/SignInStepObjects.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,35 @@ | ||
package com.privateinternetaccess.android.screens.steps | ||
|
||
import com.privateinternetaccess.android.helpers.ActionHelpers.clickIfExists | ||
import com.privateinternetaccess.android.helpers.ActionHelpers.inputTextInField | ||
import com.privateinternetaccess.android.screens.objects.SignInPageObjects | ||
|
||
class SignInStepObjects { | ||
|
||
private val signInPageObjects = SignInPageObjects() | ||
|
||
fun allowNotifications() { | ||
clickIfExists(signInPageObjects.notificationPrompt, signInPageObjects.allowNotifications) | ||
} | ||
|
||
fun reachSignInScreen() { | ||
signInPageObjects.reachLoginScreenButton.clickAndWaitForNewWindow(5000) | ||
} | ||
|
||
fun enterUsername(username : String?) { | ||
inputTextInField(signInPageObjects.usernameField, username) | ||
} | ||
|
||
fun enterPassword(password : String?) { | ||
inputTextInField(signInPageObjects.passwordField, password) | ||
} | ||
|
||
fun clickOnLoginButton() { | ||
signInPageObjects.loginButton.clickAndWaitForNewWindow(5000) | ||
} | ||
|
||
fun allowVpnProfileCreation() { | ||
clickIfExists(signInPageObjects.vpnProfileOkButton) | ||
clickIfExists(signInPageObjects.androidOkButton) | ||
} | ||
} |
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,42 @@ | ||
package com.privateinternetaccess.android.tests | ||
|
||
import com.privateinternetaccess.android.BuildConfig | ||
import com.privateinternetaccess.android.core.BaseUiAutomatorClass | ||
import com.privateinternetaccess.android.screens.objects.MainScreenPageObjects | ||
import com.privateinternetaccess.android.screens.objects.SignInPageObjects | ||
import com.privateinternetaccess.android.screens.steps.SignInStepObjects | ||
import org.junit.Test | ||
|
||
class SignInTests : BaseUiAutomatorClass() { | ||
|
||
private val stepObjects = SignInStepObjects() | ||
|
||
@Test | ||
fun successfulLoginWithValidCredentials() { | ||
stepObjects.allowNotifications() | ||
stepObjects.reachSignInScreen() | ||
stepObjects.enterUsername(BuildConfig.PIA_VALID_USERNAME) | ||
stepObjects.enterPassword(BuildConfig.PIA_VALID_PASSWORD) | ||
stepObjects.clickOnLoginButton() | ||
stepObjects.allowVpnProfileCreation() | ||
assert(MainScreenPageObjects().connectButton.exists()) | ||
} | ||
|
||
@Test | ||
fun incorrectCredentialsReturnToSplashScreen() { | ||
stepObjects.allowNotifications() | ||
stepObjects.reachSignInScreen() | ||
stepObjects.enterUsername("PLACEHOLDER") | ||
stepObjects.enterPassword("PLACEHOLDER") | ||
stepObjects.clickOnLoginButton() | ||
assert(SignInPageObjects().reachLoginScreenButton.exists()) | ||
} | ||
|
||
@Test | ||
fun errorMessageIfNoCredentialsAreProvided() { | ||
stepObjects.allowNotifications() | ||
stepObjects.reachSignInScreen() | ||
stepObjects.clickOnLoginButton() | ||
assert(SignInPageObjects().noUsernameOrPasswordError.exists()) | ||
} | ||
} |