Best Python code snippet using Airtest
CREDENTIALBOX-ADDER.py
Source:CREDENTIALBOX-ADDER.py  
...20    except:21        print('could not maximise User Maintenance window')22    time.sleep(1)23    # Switch Search Field to Username24    ahk.key_press('F10')25    time.sleep(0.2)26    ahk.key_press('down')27    time.sleep(0.2)28    ahk.key_press('down')29    time.sleep(0.2)30    ahk.key_press('down')31    time.sleep(0.2)32    ahk.key_press('down')33    time.sleep(0.2)34    ahk.key_press('right')35    time.sleep(0.2)36    ahk.key_press('down')37    time.sleep(0.2)38    ahk.key_press('enter')39    time.sleep(0.2)40    ahk.key_press('tab')41    time.sleep(0.2)42    # Open Credential Box43    user = 'credentialbox'44    pyautogui.typewrite(user, interval=0.1)45    ahk.key_press('Enter')46    # Select Credential Button47    time.sleep(1)48    ahk.key_press('f10')49    time.sleep(0.2)50    ahk.key_press('down')51    time.sleep(0.2)52    ahk.key_press('down')53    time.sleep(0.2)54    ahk.key_press('right')55    time.sleep(0.2)56    ahk.key_press('c')57    time.sleep(1)58    count = int(0)59    while count < users_to_add:  60        # Click on create new credential61        if count == 0:62            time.sleep(0.2)63            ahk.key_press('tab')64            time.sleep(0.2)65            ahk.key_press('tab')66            time.sleep(0.2)67            ahk.key_press('tab')68            time.sleep(0.2)69            ahk.key_press('tab')70            time.sleep(0.2)71            ahk.key_press('down')72            time.sleep(0.2)73            ahk.key_press('tab')74            time.sleep(0.2)75        else:76            time.sleep(0.2)77            ahk.key_press('tab')78            time.sleep(0.2)79            ahk.key_press('tab')80            time.sleep(0.2)81            ahk.key_press('down')82            time.sleep(0.2)83            ahk.key_press('tab')84            time.sleep(0.2)     85        #Choose Credential86        to_type = 'a'87        pyautogui.typewrite(to_type, interval=0.1)88        time.sleep(0.2)89        # Go to type of licence90        ahk.key_press('tab')91        time.sleep(0.4)92        # Choose Licence93        ahk.key_press('l')94        time.sleep(0.2)95        ahk.key_press('tab')96        time.sleep(0.2)97        ahk.key_press('tab')98        time.sleep(0.2)99        ahk.key_press('tab')100        time.sleep(0.2)101        ahk.key_press('tab')102        time.sleep(0.2)103        # Enter date104        day = "{0:0=2d}".format(start_day) # convert two digit105        month = "{0:0=2d}".format(start_month) # convert two digit106        year = str(start_year) # year to string107        pyautogui.typewrite(day, interval=0.1)108        pyautogui.typewrite(month, interval=0.1)109        pyautogui.typewrite(year, interval=0.1)110        # Get date for next round111        start_day +=1112        if start_day > 25:113            start_day = int(1)114            start_month += 1115        if start_month > 12:116            start_day = 1117            start_month = 1118            start_year +=1119        # Hit Apply120        time.sleep(0.2)121        ahk.key_press('tab')122        time.sleep(0.2)123        ahk.key_press('tab')124        time.sleep(0.2)125        ahk.key_press('tab')126        time.sleep(0.2)127        ahk.key_press('tab')128        time.sleep(0.2)129        ahk.key_press('tab')130        time.sleep(0.2)131        ahk.key_press('tab')132        time.sleep(0.2)133        ahk.key_press('tab')134        time.sleep(0.2)135        ahk.key_press('enter')136        time.sleep(2)137        # delete credential138        ahk.key_press('tab')139        time.sleep(0.2)140        ahk.key_press('tab')141        time.sleep(0.2)142        ahk.key_press('space')143        time.sleep(0.2)144        ahk.key_press('tab')145        time.sleep(0.2)146        ahk.key_press('tab')147        time.sleep(0.2)148        ahk.key_press('enter')149        # Apply deletion150        time.sleep(0.2)151        ahk.key_press('tab')152        time.sleep(0.2)153        ahk.key_press('tab')154        time.sleep(0.2)155        ahk.key_press('enter')156        time.sleep(1)...Credential-Adder-User-dynamic-Input.py
Source:Credential-Adder-User-dynamic-Input.py  
...22except:23    print('could not maximise User Maintenance window')24time.sleep(1)25# Switch Search Field to Username26ahk.key_press('F10')27time.sleep(0.1)28ahk.key_press('down')29time.sleep(0.1)30ahk.key_press('down')31time.sleep(0.1)32ahk.key_press('down')33time.sleep(0.1)34ahk.key_press('down')35time.sleep(0.1)36ahk.key_press('right')37time.sleep(0.1)38ahk.key_press('down')39time.sleep(0.1)40ahk.key_press('enter')41time.sleep(0.1)42ahk.key_press('tab')43time.sleep(0.1)44# Open Credential Box45user = 'credentialbox'46pyautogui.typewrite(user, interval=0.1)47ahk.key_press('Enter')48# Select Credential Button49time.sleep(1)50ahk.key_press('f10')51time.sleep(0.1)52ahk.key_press('down')53time.sleep(0.1)54ahk.key_press('down')55time.sleep(0.1)56ahk.key_press('right')57time.sleep(0.1)58ahk.key_press('c')59time.sleep(1)60count = int(0)61while count < users_to_add:  62    # Click on create new credential63    if count == 0:64        time.sleep(0.1)65        ahk.key_press('tab')66        time.sleep(0.1)67        ahk.key_press('tab')68        time.sleep(0.1)69        ahk.key_press('tab')70        time.sleep(0.1)71        ahk.key_press('tab')72        time.sleep(0.1)73        ahk.key_press('down')74        time.sleep(0.1)75        ahk.key_press('tab')76        time.sleep(0.1)77    else:78        time.sleep(0.1)79        ahk.key_press('tab')80        time.sleep(0.1)81        ahk.key_press('tab')82        time.sleep(0.1)83        ahk.key_press('down')84        time.sleep(0.1)85        ahk.key_press('tab')86        time.sleep(0.1)     87    #Choose Credential88    to_type = 'a'89    pyautogui.typewrite(to_type, interval=0.1)90    time.sleep(0.1)91    # Go to type of licence92    ahk.key_press('tab')93    time.sleep(0.4)94    # Choose Licence95    ahk.key_press('l')96    time.sleep(0.1)97    ahk.key_press('tab')98    time.sleep(0.1)99    ahk.key_press('tab')100    time.sleep(0.1)101    ahk.key_press('tab')102    time.sleep(0.1)103    ahk.key_press('tab')104    time.sleep(0.1)105    # Enter date106    day = "{0:0=2d}".format(start_day) # convert two digit107    month = "{0:0=2d}".format(start_month) # convert two digit108    year = str(start_year) # year to string109    pyautogui.typewrite(day, interval=0.1)110    pyautogui.typewrite(month, interval=0.1)111    pyautogui.typewrite(year, interval=0.1)112    # Get date for next round113    start_day +=1114    if start_day > 25:115        start_day = int(1)116        start_month += 1117    if start_month > 12:118        start_day = 1119        start_month = 1120        start_year +=1121    # Hit Apply122    time.sleep(0.1)123    ahk.key_press('tab')124    time.sleep(0.1)125    ahk.key_press('tab')126    time.sleep(0.1)127    ahk.key_press('tab')128    time.sleep(0.1)129    ahk.key_press('tab')130    time.sleep(0.1)131    ahk.key_press('tab')132    time.sleep(0.1)133    ahk.key_press('tab')134    time.sleep(0.1)135    ahk.key_press('tab')136    time.sleep(0.1)137    ahk.key_press('enter')138    time.sleep(2)139    # delete credential140    ahk.key_press('tab')141    time.sleep(0.1)142    ahk.key_press('tab')143    time.sleep(0.1)144    ahk.key_press('space')145    time.sleep(0.1)146    ahk.key_press('tab')147    time.sleep(0.1)148    ahk.key_press('tab')149    time.sleep(0.1)150    ahk.key_press('enter')151    # Apply deletion152    time.sleep(0.1)153    ahk.key_press('tab')154    time.sleep(0.1)155    ahk.key_press('tab')156    time.sleep(0.1)157    ahk.key_press('enter')158    time.sleep(1)...menu.py
Source:menu.py  
1import readchar2from data import define_menu, set_disclaimer3class Menu:4    def __init__(self, tesla):5        self.tesla = tesla6        self.display_disclaimer = True7        self.menu = define_menu()8        self.disclaimer = set_disclaimer()9    def get(self, level):10        return self.menu[level]11    def show_disclaimer(self):12        if self.display_disclaimer:13            print(self.disclaimer)14            self.display_disclaimer = False15    def show_menu(self, level):16        menu = self.get(level)17        if 'main' in level.lower():18            self.show_disclaimer()19        print(f'\n\n{level.title()} Menu')20        commands = {}21        for item in menu:22            print(f"{menu[item]['select'].upper()} - {item}")23            commands[menu[item]['select']] = (menu[item]['method'], menu[item]['endpoint'])24            if 'parameters' in menu[item]:25                commands[menu[item]['select']] += (menu[item]['parameters'],)26            if 'help' in menu[item]:27                commands[menu[item]['select']] += (menu[item]['help'],)28        print(f"B - Back")29        print(f"E - Exit")30        return commands31    def get_keypress(self):32        key_press_key = repr(readchar.readkey())33        return key_press_key.replace("'", "").lower()34    def process_keypress(self, key_press, commands):35        if key_press in commands:36            if commands[key_press][0] == 'menu':37                self.display(self.tesla, commands[key_press][1])38            else:39                payload = {}40                if len(commands[key_press]) > 2:41                    if len(commands[key_press]) == 4:42                        print(commands[key_press][3])43                    for param in commands[key_press][2]:44                        value = input(f'Value for {param}:')45                        payload[param] = value46                self.tesla.run_command(commands[key_press][0], commands[key_press][1], payload)47        elif key_press == 'e':48            exit()49        elif key_press == 'b':50            return True51        else:52            print(f'  {key_press.upper()} not found.')53        return False54    def display(self, tesla, level):55        done = False56        while not done:57            commands = self.show_menu(level)58            key_press = self.get_keypress()...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
