Configure the viSer app through the suite deployment
Use the SmartViser suite deployment to configure the viSer app.
The credentials are input in the viSer app as soon as it is
installed, allowing the app to be accessible right away.
The viSer app settings are now loaded through a settings file
(dumped from the app manually) instead of going through hoops via
the UI.
Issue: INFRA-226
Change-Id: I8d1e602dc4928c2f3770720c74db3f219fde6e88
diff --git a/deploy.py b/deploy.py
index b49967b..cd53258 100755
--- a/deploy.py
+++ b/deploy.py
@@ -14,8 +14,6 @@
_LOG = logging.getLogger(__name__)
-VWS_CREDENTIALS = {"user": "fairphonetesting@gmail.com", "password": "aish3echi:uwaiSh"}
-
ADB_DEVICES_PATTERN = re.compile(r"^([a-z0-9-]+)\s+device$", flags=re.M)
@@ -145,48 +143,6 @@
disable_privacy_impact_checkbox.click()
-# Grant the permissions through the UI
-def configure_perms(device):
- # Input the credentials
- device.ui(resourceId="android:id/content").child(text="Username").child(
- className="android.widget.EditText"
- ).set_text(VWS_CREDENTIALS["user"])
- device.ui(resourceId="android:id/content").child(text="Password").child(
- className="android.widget.EditText"
- ).set_text(VWS_CREDENTIALS["password"])
-
- # Sign in
- signin_label = "SIGN IN" if device.sdk >= 24 else "Sign in"
- device.ui(resourceId="android:id/content").child(
- text=signin_label, className="android.widget.Button"
- ).click()
-
-
-def configure_settings(device):
- # Set the e-mail account
- device.ui(text="Settings", className="android.widget.TextView").click()
- device.ui(resourceId="android:id/list").child_by_text(
- "User settings", className="android.widget.LinearLayout"
- ).click()
- device.ui(resourceId="android:id/list").child_by_text(
- "Email account", className="android.widget.LinearLayout"
- ).click()
- prompt = device.ui(resourceId="android:id/content").child_by_text(
- "Email account", className="android.widget.LinearLayout"
- )
- prompt.child(resourceId="android:id/edit").set_text("fairphone.viser@gmail.com")
- prompt.child(text="OK", className="android.widget.Button").click()
- device.ui(resourceId="android:id/list").child_by_text(
- "Email password", className="android.widget.LinearLayout"
- ).click()
- device.ui(text="Password :").child(className="android.widget.EditText").set_text(
- "fairphoneviser2017"
- )
- device.ui(description="OK", className="android.widget.TextView").click()
- device.ui.press.back()
- device.ui.press.back()
-
-
class DeviceUnderTest:
"""An Android device under test."""
@@ -439,6 +395,14 @@
@dataclasses.dataclass(frozen=True)
+class Credentials:
+ """Credentials to access a service."""
+
+ username: str
+ password: str
+
+
+@dataclasses.dataclass(frozen=True)
class ViserSuite:
"""A SmartViser viSer app suite.
@@ -459,9 +423,11 @@
AndroidApp("com.lunarlabs.panda", "com.lunarlabs.panda-latest.apk"),
]
+ credentials: Credentials
prebuilts_path: pathlib.Path
scenarios_path: pathlib.Path
scenarios_data_path: pathlib.Path
+ settings_file: pathlib.Path
target_path: pathlib.Path = pathlib.Path("/sdcard/Viser")
@property
@@ -472,6 +438,10 @@
def target_scenarios_data_path(self) -> pathlib.Path:
return self.target_path / "Data"
+ @property
+ def target_settings_file(self) -> pathlib.Path:
+ return self.target_path / "Settings" / self.settings_file.name
+
def resolve_apps(self, device: DeviceUnderTest) -> Sequence[AndroidApp]:
"""Resolve the apps based on the target device properties.
@@ -489,8 +459,8 @@
def deploy(self, device: DeviceUnderTest) -> None:
"""Deploy the suite on a device.
- Copy the test scenarios and their data, and install the
- different apps composing the suite.
+ Copy the test scenarios and their data, install the
+ different apps composing the suite, and configure the suite.
The previous configuration and data (i.e. reports) tied to the
app suite, if any, is deleted before hand.
@@ -500,6 +470,7 @@
self.cleanup_previous_deployment(device)
self.copy_scenarios(device)
self.install_suite(device)
+ self.configure_suite(device)
def cleanup_previous_deployment(self, device: DeviceUnderTest) -> None:
"""Clean-up a previous deployment of the suite on a device.
@@ -534,19 +505,64 @@
def install_suite(self, device: DeviceUnderTest) -> None:
"""Install the suite apps on a device.
+ Input the credentials in the viSer app to authenticate the
+ device.
+
:param device: The device to install the suite apps on.
"""
for app in self.resolve_apps(device):
_LOG.info("Install %s", app)
device.install(self.prebuilts_path / app.apk)
+ with device.launch("com.lunarlabs.panda"):
+ # Input the credentials
+ device.ui(resourceId="android:id/content").child(text="Username").child(
+ className="android.widget.EditText"
+ ).set_text(self.credentials.username)
+ device.ui(resourceId="android:id/content").child(text="Password").child(
+ className="android.widget.EditText"
+ ).set_text(self.credentials.password)
+
+ # Sign in
+ signin_label = "SIGN IN" if device.sdk >= 24 else "Sign in"
+ device.ui(resourceId="android:id/content").child(
+ text=signin_label, className="android.widget.Button"
+ ).click()
+
+ def configure_suite(self, device: DeviceUnderTest) -> None:
+ """Configure the suite on a device.
+
+ :param device: The device to configure the suite on.
+ """
+ _LOG.info(
+ "Copy settings: %s → %s", self.settings_file, self.target_settings_file
+ )
+ device.push(self.settings_file, self.target_settings_file)
+
+ with device.launch("com.lunarlabs.panda"):
+ device.ui(text="Settings", className="android.widget.TextView").click()
+ device.ui(resourceId="android:id/list").child_by_text(
+ "Settings management", className="android.widget.LinearLayout"
+ ).click()
+ device.ui(resourceId="android:id/list").child_by_text(
+ "Load settings", className="android.widget.LinearLayout"
+ ).click()
+ device.ui(resourceId="android:id/list").child_by_text(
+ self.settings_file.name, className="android.widget.TextView"
+ ).click()
+ device.ui(
+ textMatches="(?i)Select", className="android.widget.Button"
+ ).click()
+
def deploy():
serials = []
suite = ViserSuite(
+ Credentials("fairphonetesting@gmail.com", "aish3echi:uwaiSh"),
pathlib.Path("../../vendor/smartviser/viser/prebuilts/apk"),
pathlib.Path("../scenarios"),
pathlib.Path("../scenarios-data"),
+ pathlib.Path("settings/fairphone-bot_settings"),
)
if len(sys.argv) > 1:
@@ -569,10 +585,6 @@
# Push the scenarios, their data, and install the apps
suite.deploy(device)
-
- with device.launch("com.lunarlabs.panda"):
- configure_perms(device)
- configure_settings(device)
except (HostCommandError, DeviceCommandError, uiautomator.JsonRPCError):
_LOG.error("Failed to execute deployment", exc_info=True)
finally: