-
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-637: Add new tests for DedicatedIP
Created an xpath finder helper called XPathUtil.kt for us to be able to validate toast notification in the app. This function can be used not only for toast but for any elements you need to find that has only xpath available.
- Loading branch information
Showing
9 changed files
with
86 additions
and
13 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,34 @@ | ||
package com.privateinternetaccess.android.helpers | ||
|
||
import androidx.test.uiautomator.UiObject | ||
import androidx.test.uiautomator.UiSelector | ||
import com.privateinternetaccess.android.core.BaseUiAutomatorClass | ||
import java.io.File | ||
import org.dom4j.Document | ||
import org.dom4j.io.SAXReader | ||
|
||
object XPathUtil : BaseUiAutomatorClass() { | ||
|
||
fun findElementByXPath(xPathQuery : String) : UiObject? { | ||
val dumpFile = File.createTempFile("uiDump", ".xml") | ||
device.dumpWindowHierarchy(dumpFile) | ||
//parse - translating info what we are getting to something workable and manageable | ||
val reader = SAXReader() | ||
val document:Document = reader.read(dumpFile) | ||
val node = document.selectSingleNode(xPathQuery) ?: return null | ||
|
||
if(node != null){ | ||
val resourceID = node.valueOf("@resource-id") | ||
val contentDesc = node.valueOf("@content-desc") | ||
val textValue = node.valueOf("@text") | ||
val className = node.valueOf("@class") | ||
val selector = UiSelector() | ||
if(resourceID.isNotEmpty()) selector.resourceId(resourceID) | ||
if(contentDesc.isNotEmpty()) selector.description(contentDesc) | ||
if(textValue.isNotEmpty()) selector.text(textValue) | ||
if(className.isNotEmpty()) selector.className(className) | ||
return device.findObject(selector) | ||
} | ||
return null | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
app/src/androidTest/java/screens/objects/DedicatedIPPageObjects.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 |
---|---|---|
@@ -1,11 +1,13 @@ | ||
package com.privateinternetaccess.android.screens.objects | ||
|
||
import com.privateinternetaccess.android.helpers.LocatorHelper | ||
import com.privateinternetaccess.android.helpers.XPathUtil | ||
|
||
class DedicatedIPPageObjects { | ||
val dedicatedIPField = LocatorHelper.findByResourceId("com.privateinternetaccess.android:id/snippet_dip_entry_field") | ||
val activateButton = LocatorHelper.findByResourceId("com.privateinternetaccess.android:id/snippet_dip_activate_button") | ||
val serverFlag = LocatorHelper.findByResourceId("com.privateinternetaccess.android:id/list_server_flag") | ||
val serverName = LocatorHelper.findByResourceId("com.privateinternetaccess.android:id/list_server_name") | ||
val serverIPAddress = LocatorHelper.findByResourceId("com.privateinternetaccess.android:id/list_server_ping") | ||
val toastErrorMessage = XPathUtil.findElementByXPath("//android.widget.Toast[@text='Your token is invalid. Please make sure you have entered the token correctly.']" ) | ||
} |
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
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,41 @@ | ||
package com.privateinternetaccess.android.tests | ||
|
||
import com.privateinternetaccess.android.core.BaseUiAutomatorClass | ||
import com.privateinternetaccess.android.helpers.ActionHelpers.successfulLogin | ||
import com.privateinternetaccess.android.helpers.ActionHelpers.goToSideMenu | ||
import com.privateinternetaccess.android.screens.objects.DedicatedIPPageObjects | ||
import com.privateinternetaccess.android.screens.objects.SideMenuPageObjects | ||
import com.privateinternetaccess.android.screens.steps.DedicatedIPStepObjects | ||
import com.privateinternetaccess.android.BuildConfig | ||
import org.junit.Test | ||
import org.junit.Assert | ||
|
||
class DedicatedIPTests : BaseUiAutomatorClass() { | ||
|
||
private val dedicatedIPStepObjects = DedicatedIPStepObjects() | ||
private val sideMenuPageObjects = SideMenuPageObjects() | ||
|
||
@Test | ||
fun oneDIPTokenAccepted() { | ||
successfulLogin() | ||
goToSideMenu(sideMenuPageObjects.dedicatedIP) | ||
dedicatedIPStepObjects.enterDedicatedIPToken(BuildConfig.PIA_VALID_DIP_TOKEN ) | ||
val conditions = listOf( | ||
{ !DedicatedIPPageObjects().dedicatedIPField.exists() }, | ||
{ DedicatedIPPageObjects().serverFlag.exists() }, | ||
{ DedicatedIPPageObjects().serverName.exists() }, | ||
{ DedicatedIPPageObjects().serverIPAddress.exists() } | ||
) | ||
for (condition in conditions) { | ||
Assert.assertTrue(condition()) | ||
} | ||
} | ||
|
||
@Test | ||
fun invalidDIPTokenValidation() { | ||
successfulLogin() | ||
goToSideMenu(sideMenuPageObjects.dedicatedIP) | ||
dedicatedIPStepObjects.enterDedicatedIPToken("invalidToken") | ||
DedicatedIPPageObjects().toastErrorMessage?.let { assert(it.exists()) } | ||
} | ||
} |
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