QA-engineers, mobile application testers, automators.
During the testing of applications for Android (not only, but then we will discuss only this platform), we have to install many assemblies of the tested product / products. This process takes time and effort, which is more efficient to spend on finding bugs.
In this article we will look at the existing solution, write our own in Python and compare them.
Perhaps the most popular solution to this problem at the moment is provided by the Crashlytics service, which includes the Beta installer.
Consider the typical process of installing an application using Crashlytics Beta:
So, to install and run a single application build using Crashlytics Beta, you need to complete a total of at least nine actions. We will focus on these indicators and will try to create an installer that requires fewer actions to solve similar problems.
As a programming language, we will choose Python, since it is suitable for our task and is very popular, including among QA engineers.
To interact with Android, we will use adb, included in the standard Android SDK.
For downloading files - wget.
In our case, the builds are carried out in TeamCity.
We now turn to writing code.
First of all we import the subprocess module into the project, it is necessary for the execution of wget and adb commands.
import subprocess
Add the necessary settings for Wget.
settings = {'user': '—user=__teamcity', 'password': '—password=__teamcity', 'way': '____'}
We will install applications according to the build number, so we will teach the script to ask this parameter.
number = input(' № : ')
Suppose we need to install two assemblies at once: test and combat. We will download them from TeamCity. To do this, find out the full path to the files by opening the service page and finding the assembly in the artifacts. The URL to the builds will look something like this:
https://teamcity.mysite.com/repository/app/_/_/myapp-_-_.apk
In the address instead of the build number you can see the id, for example, / 1234: id /. Here we will specify not the id, but the build number.
Let's write the function for downloading the given assemblies.
def download(type_b): url = 'http://teamcity.mysite.com/repository/app/{0}/{1}/myapp-{0}-{1}.apk'.format(number, type_b) # — , , — , # — subprocess.check_output(['wget', '-N', '--cache=off', '--progress=bar', settings['user'], settings['password'], '-P', settings['way'], url])
Write a function to install and run applications. First, remove the previously installed assembly. Do not forget that if at least one application is not on the device - the script will end with an error. To avoid this, we will ignore errors.
In this imaginary example, two packages:
Starting activities:
Your package and activity names will be different.
def install(type_b): try: # , package name subprocess.check_output(['adb', 'uninstall', 'com.myapp.{0}'.format(type_b)]) except: # — . pass finally: # subprocess.check_output(['adb', 'install', '{0}/myapp-{1}-{2}.apk'.format(settings['way'], number, type_b)]) # , activity name subprocess.check_output(['adb', 'shell', 'am', 'start', 'com.myapp.{0}/com.myapp.StartActivity'.format(type_b)]) print('(^_^) ({0}-{1}) .'.format(number, type_b))
All necessary functions are written. Now they can be applied.
Additionally, add a handler for the case when the specified assembly is not in TeamCity.
while True: try: # , download('prod') # , download('test') except Exception: # — number = input('¯\_(ツ)_/¯ .\n №: ') else: print(' …') # install('prod') # install('test') # — print('! (_8(|)\n') break
The script is ready. Save it, for example, under the name installer.py
Add an alias, for example, alias inst = 'python ~ / scripts / installer.py'
So, to install a single assembly using Crashlytics Beta, you need to perform 9 actions. For comparison, we measure this indicator in the script.
Beta (1 build) - 9 actions (not including removal of old builds).
Your script (as many as you like) - 2 actions.
An added bonus of a custom solution is that it scales (adding installations of several products to a number of devices, etc.), and also easily adapts to the tasks of automatic testing.
Source: https://habr.com/ru/post/426149/
All Articles