Skip to content

Commit

Permalink
PIA-634: Create a login and settings helper
Browse files Browse the repository at this point in the history
As there are many steps to take for successful login and going to settings, two function
where created to minimise the repetativeness of it in our SignOuTests.kt
  • Loading branch information
kp-ruth-o committed Oct 9, 2023
1 parent 21537a2 commit 14870b4
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 30 deletions.
24 changes: 24 additions & 0 deletions app/src/androidTest/java/helpers/ActionHelpers.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.privateinternetaccess.android.helpers

import androidx.test.uiautomator.UiObject
import com.privateinternetaccess.android.screens.steps.SideMenuStepObjects
import com.privateinternetaccess.android.screens.steps.SignInStepObjects

object ActionHelpers {

Expand All @@ -15,4 +17,26 @@ object ActionHelpers {
field.click()
field.text = data?.toString() ?: ""
}

fun userLoginSuccess() {
SignInStepObjects().allowNotifications()
SignInStepObjects().reachSignInScreen()
SignInStepObjects().enterCredentials()
SignInStepObjects().clickOnLoginButton()
SignInStepObjects().allowVpnProfileCreation()
}

fun goToSettings(primarySettingsSection : UiObject, secondarySettingsSection : UiObject? = null ) {
SideMenuStepObjects().hamburgerMenu()
SideMenuStepObjects().settings()

if (primarySettingsSection.exists())
{
primarySettingsSection.click()
}
if (secondarySettingsSection != null)
{
secondarySettingsSection.click()
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.privateinternetaccess.android.screens.objects //why do we declare this instead of just screens.object when we start createed the file?
package com.privateinternetaccess.android.screens.objects

import com.privateinternetaccess.android.helpers.LocatorHelper


class SideMenuPageObject {
class SideMenuPageObjects {

val hamburgerMenu = LocatorHelper.findByContentDesc("Open")
val settings = LocatorHelper.findByText("Settings")
Expand Down
7 changes: 2 additions & 5 deletions app/src/androidTest/java/tests/SignInTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ 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 com.privateinternetaccess.android.helpers.ActionHelpers.userLoginSuccess
import org.junit.Test

class SignInTests : BaseUiAutomatorClass() {
Expand All @@ -13,11 +14,7 @@ class SignInTests : BaseUiAutomatorClass() {

@Test
fun successfulLoginWithValidCredentials() {
stepObjects.allowNotifications()
stepObjects.reachSignInScreen()
stepObjects.enterCredentials()
stepObjects.clickOnLoginButton()
stepObjects.allowVpnProfileCreation()
userLoginSuccess()
assert(MainScreenPageObjects().connectButton.exists())
}

Expand Down
30 changes: 7 additions & 23 deletions app/src/androidTest/java/tests/SignOutTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,30 @@ package com.privateinternetaccess.android.tests
import com.privateinternetaccess.android.screens.steps.SideMenuStepObjects
import com.privateinternetaccess.android.core.BaseUiAutomatorClass
import com.privateinternetaccess.android.screens.objects.SideMenuPageObjects
import com.privateinternetaccess.android.screens.steps.SignInStepObjects
import com.privateinternetaccess.android.helpers.ActionHelpers.userLoginSuccess
import com.privateinternetaccess.android.helpers.ActionHelpers.goToSettings
import org.junit.Before
import org.junit.Test

class SignOutTests : BaseUiAutomatorClass() {

private val stepObjects = SignInStepObjects ()
private val sideMenuStepObjects = SideMenuStepObjects()

//pre-requiste
private val sideMenuPageObjects = SideMenuPageObjects()
@Before
fun login () {
stepObjects.allowNotifications()
stepObjects.reachSignInScreen()
stepObjects.enterCredentials()
stepObjects.clickOnLoginButton()
stepObjects.allowVpnProfileCreation()
userLoginSuccess()
}

@Test
fun logout() {
sideMenuStepObjects.hamburgerMenu()
sideMenuStepObjects.settings()
sideMenuStepObjects.general()
goToSettings(sideMenuPageObjects.general)
sideMenuStepObjects.launchOnSystemStartUp()
// goToSettings(sideMenuPageObject.general)
sideMenuStepObjects.back()
sideMenuStepObjects.back()
sideMenuStepObjects.hamburgerMenu()
sideMenuStepObjects.logout()
//login
stepObjects.allowNotifications()
stepObjects.reachSignInScreen()
stepObjects.enterCredentials()
stepObjects.clickOnLoginButton()
stepObjects.allowVpnProfileCreation()
sideMenuStepObjects.hamburgerMenu()
sideMenuStepObjects.settings()
sideMenuStepObjects.general()
// goToSettings(sideMenuPageObject.general)
userLoginSuccess()
goToSettings(sideMenuPageObjects.general)
assert(!SideMenuPageObjects().toggleLaunchOnSystemStartUp.isChecked())
}
}

0 comments on commit 14870b4

Please sign in to comment.