Batch character input of Python_adb in selfie 49

Android terminal product system or App test, involving input box boundary value test,
For example, set the name of wifi hotspot, or search the input box,
You need to verify that the text input box can enter up to 256 characters,
How to input 256 characters quickly?


Preparation stage
  1. Manually click the wifi hotspot name text input box to make sure the cursor is in the edit box
  2. Using adb shell input text + 256 characters, you can input 256 strings
  3. String.ascii'letters can contain uppercase and lowercase English letters
  4. string.digits can contain numbers 1-10
  5. random.sample can be randomly sampled from an array "pool"

Python batch script form
# coding=utf-8

import os
import string
import random

chars_num = 256  # chars num characters

random_list = random.sample((string.ascii_letters + string.digits) * 5, chars_num - 8)
random_str = ''.join(random_list)
random_str = "START" + random_str + "END"
print(random_str)
os.system("adb shell input text %s" % random_str)
print("Inputed %s chars, please check the \"START\" and \"END\" keyword" % chars_num)
os.system("pause")

random.sample needs to ensure that there is enough data in the array "pool", so you need to:
(string.ascii_letters + string.digits) * 5


Python procedure oriented function form
# coding=utf-8

import os
import string
import random

def input_text(chars_num):
    if chars_num > 8:
        random_list = random.sample((string.ascii_letters + string.digits) * 5, chars_num - 8)
        random_str = ''.join(random_list)
        random_str = "START" + random_str + "END"
        print(random_str)
        os.system("adb shell input text %s" % random_str)
        print("Inputed %s chars, please check the \"START\" and \"END\" keyword" % chars_num)
    else:
        print("chars num too short...")

input_text(256)
os.system("pause")

Python object oriented class form
# coding=utf-8

import os
import string
import random


class TextInputer():
    def __init__(self):
        pass

    def input_text(self, chars_num):
        if chars_num > 8:
            random_list = random.sample((string.ascii_letters + string.digits) * 5, chars_num - 8)
            random_str = ''.join(random_list)
            random_str = "START" + random_str + "END"
            print(random_str)
            # os.system("adb shell input text %s" % random_str)
            print("Inputed %s chars, please check the \"START\" and \"END\" keyword" % chars_num)
        else:
            print("chars num too short...")


t_obj = TextInputer()
t_obj.input_text(256)

os.system("pause")

Operation mode and effect

Make sure the Android device is connected to the computer through the USB cable, and the adb device is effectively connected,
The three implementation forms of the above code can be run directly, such as saving as input_text.py and putting it on the desktop,
It is recommended to run python input_text.py, or double-click it.
The operation effect is as follows:


For more and better original articles, please visit the official website: www.zipython.com
Selfie course (Python course of automatic test, compiled by Wu Sanren)
Original link: https://www.zipython.com/#/detail?id=4556ebb04f9f446095531eba4274a51f
You can also follow the wechat subscription number of "wusanren" and accept the article push at any time.

Tags: Python shell Android ascii

Posted on Mon, 23 Mar 2020 05:31:06 -0700 by surfnjunkie