Best Python code snippet using ATX
芭芭农场.py
Source:芭芭农场.py  
...31    if exist_img('res/baba/task_taobao.png'):32        return33    d.app_stop('com.taobao.taobao')34    d.app_start('com.taobao.taobao')35    d(description="æµ®å±å
³éæé®").click_exists(timeout=1)36    d(text="èèååº").click(timeout=5)37    # if click_img('res/baba/red_package.png'):38    #     d.press("back")39    #     d(text="èèååº").click(timeout=2)40    d(description="æµ®å±å
³éæé®").click_exists(timeout=2)41    d(text="ç»§ç»åªå").click_exists(timeout=3)42    if not click_img('res/baba/ji_fei_liao.png'):43        return4445def start_taobao():46    d.app_stop('com.taobao.taobao')47    d.app_start('com.taobao.taobao')48    d(description="æµ®å±å
³éæé®").click_exists(timeout=1)49    d(text="èèååº").click(timeout=5)50    # if click_img('res/baba/red_package.png'):51    #     d.press("back")52    #     d(text="èèååº").click(timeout=2)53    d(description="æµ®å±å
³éæé®").click_exists(timeout=2)54    d(text="ç»§ç»åªå").click_exists(timeout=3)55    item = d(text="ç«å³é¢å")56    if item:57        item.click()58        time.sleep(0.5)59        # é¢åä¸ä¸ªäº²å¯åº¦å¥å±60        d.click(0.209, 0.44)61        d.click(0.503, 0.434)62        d.click(0.807, 0.436)63        # ç¹å»å
³é64        d.click(0.907, 0.205)6566    #å
¨é¨é¢å67    d.click(0.822, 0.69)68    d(text="å
³é").click_exists(timeout=1)69    #ç¹å»å
å70    d.click(0.189, 0.684)71    #ç¹å»éè¥æ72    d.click(0.75, 0.898)73    #åä»»å¡74    taobao_task()75    #æ½è¥76    fertilize()777879def get_bound():80    if d(text="亲å¯åº¦"):81        d(text="亲å¯åº¦").click()82        time.sleep(0.5)83        # é¢åä¸ä¸ªäº²å¯åº¦å¥å±84        d.click(0.209, 0.44)85        d.click(0.503, 0.434)86        d.click(0.807, 0.436)87        # ç¹å»å
³é88        d.click(0.907, 0.205)8990def watch_15s():91    time.sleep(0.1)92    for i in range(5):93        d.swipe(500, 500, 500, 300, 0.1)94        time.sleep(3)95    time.sleep(0.3)96    d.press("back")9798def taobao_task():99    time.sleep(1)100    if not exist_img('res/baba/task_taobao.png'):101        if not click_img('res/baba/ji_fei_liao.png'):102            return103    time.sleep(1)104    mark = d(text="å»ç¾å°")105    if mark:106        mark.click()107    question = d(text="å»çé¢")108    if question:109        question.click()110        time.sleep(0.5)111        #éB112        d.click(0.533, 0.904)113        #d.click(0.478, 0.9)114        time.sleep(1)115        #é¢å¥å±116        d(textContains="é¢åå¥å±").click_exists(timeout=1)117        time.sleep(1)118        click_img('res/baba/ji_fei_liao.png')119    taobo_life = d(text="廿·å®äººçæéª°å(0/1)")120    if taobo_life:121        taobo_life.click()122        time.sleep(2)123        d.click(0.488, 0.677)124        time.sleep(2)125        d.click(0.488, 0.677)126        time.sleep(1)127        d.click(0.493, 0.645)128        time.sleep(1)129        d.press("back")130131    taote = d(text="廿·ç¹é¢å¥½ç¤¼(0/1)")132    if taote:133        taote.click()134        time.sleep(3)135        go_to_task()136137    task_list = ['éç²¾é好ç©(0/1)','éç²¾éåå(0/3)','éç²¾éåå(1/3)','éç²¾éåå(2/3)','æä¸æä½ å¿ä»ªçå®è´(0/1)','æµè§éå¸å°éå¾è¥æ(0/1)','æµè§çè§é¢(0/1)','éç²¾é好货(0/1)','æµè§å¤©å¤©é¢ç°é(0/1)']138    for task_text in task_list:139        task_item = d(text=task_text)140        if task_item:141            print(task_item)142            task_item.click()143            time.sleep(1)144            shan_mo = d(text="éªé")145            if shan_mo:146                shan_mo.click()147            if exist_img('res/baba/cash.png'):148                d.click(0.92, 0.254)149            watch_15s()150            go_to_task()151            d.swipe(500, 1000, 500, 700, 0.1)152    print('task_list process done')153    #ä¸å154    d.swipe(500, 1000, 500, 800, 0.1)155    d(text="æ¯æ¥7ç¹/12ç¹/20ç¹/22ç¹åé¢1次").click_exists(timeout=1)156    time.sleep(1)157    d.click(0.92, 0.232)158    time.sleep(2)159    print('task process done')160161162#æ½è¥163def fertilize():164    print('start fertilize')165    get_bound()166    if exist_img('res/baba/task_taobao.png'):167        d.click(0.92, 0.232)168    if not exist_img('res/baba/ji_fei_liao.png'):169        return170    while True:171        #ç¹å»å
å172        d.click(0.189, 0.684)173        #ç¹å»æ½è¥174        d.click(0.546, 0.888)175        time.sleep(1)176        if click_img('res/baba/task_taobao.png'):177            # æ½è¥å®æ178            return179        item = d(text="ç«å³é¢å")180        if item:181            item.click()182            time.sleep(0.5)183            #é¢åä¸ä¸ªäº²å¯åº¦å¥å±184            d.click(0.209, 0.44)185            d.click(0.503, 0.434)186            d.click(0.807, 0.436)187            #ç¹å»å
³é188            d.click(0.907, 0.205)189        #ç¹å»æçº¢å
190        d.click(0.503, 0.709)191        d(text="å
³é").click_exists(timeout=0.1)192        time.sleep(0.3)193194195196197198199def go_to_aplipay_task():200    if exist_img('res/baba/task_alipay.png'):201        return202    d.app_stop('com.eg.android.AlipayGphone')203    d.app_start('com.eg.android.AlipayGphone')204    d(text="èèååº").click(timeout=10)205    time.sleep(3)206    d(text="ç»§ç»åªå").click_exists(timeout=1)207    # å
¨é¨é¢åfor i in range(3):208    d.click(0.822, 0.606)209    d(text="å»é¢æ´å¤è¥æ").click_exists(timeout=1)210    # d(text="å
³é").click_exists(timeout=1)211    # ç¹å»éè¥æ212    d.click(0.867, 0.812)213214def alipay_task():215    time.sleep(1)216    if not exist_img('res/baba/task_alipay.png'):217        # 妿ä¸å¨ä»»å¡é¡µç¾218        if not click_img('res/baba/ling_fei_liao_alipay.png'):219            return220        else:221            time.sleep(1)222    #ç¾å°223    d.click(0.827, 0.43)224    #æµè§é¡µé¢225226    task_list = ['éä¸éå«éè´¢ç¥å¾å¤§ç¤¼ (0/1)','éä¸éæ¯ä»å®ä¼å (0/1)']227228    for task_text in task_list:229        print(task_text + ' start')230        item = d(text=task_text)231232        if not item:233            d.swipe(500, 1000, 500, 800, 0.2)234            d.swipe(500, 1000, 500, 800, 0.2)235            d.swipe(500, 1000, 500, 800, 0.2)236            item = d(text=task_text)237        if item:238            (x1,y1) = item.center()239            (x,y) = (x1+385,y1+20)240            (a, b) = d.window_size()241            print(x / a, y / b)242            d.click(x / a, y / b)243            #item.click()244            time.sleep(1)245            watch_15s()246            d(text="é¢å").click_exists(timeout=0.2)247            if not exist_img('res/baba/task_alipay.png'):248                go_to_aplipay_task()249        print(task_text + ' done')250    time.sleep(1)251    if exist_img('res/baba/task_alipay.png'):252        #é¢ååç§å¥å±253        d.swipe(500, 1000, 500, 800, 0.1)254        d(text="é¢å").click_exists(timeout=0.2)255        #å
³éä»»å¡é¡µç¾256        d.click(0.925, 0.291)257258259#æ½è¥260def alipay_fertilize():261    if not exist_img('res/baba/ling_fei_liao_alipay.png'):262        return263264    while True:265        #ç¹å»å
¨é¨é¢å266        #todo267        # if exist_img('res/baba/xx.png')268        #     d.click(0.812, 0.581)269        #ç¹å»æ½è¥270        d.click(0.503, 0.815)271        item = d(text="ç¹å»é¢å")272        if item:273            item.click()274            time.sleep(0.3)275            #é¢å276            d.click(0.488, 0.666)277            time.sleep(0.3)278        if exist_img('res/baba/task_alipay.png'):279            #æ½è¥å®æ280            break281282283284def start_alipay():285    d.app_stop('com.eg.android.AlipayGphone')286    d.app_start('com.eg.android.AlipayGphone')287    d(text="èèååº").click(timeout=10)288    time.sleep(3)289    d(text="ç»§ç»åªå").click_exists(timeout=1)290    #å
¨é¨é¢åfor i in range(3):291    d.click(0.822, 0.606)292    d(text="å»é¢æ´å¤è¥æ").click_exists(timeout=1)293    #d(text="å
³é").click_exists(timeout=1)294    #ç¹å»éè¥æ295    d.click(0.867, 0.812)296    #åä»»å¡297    alipay_task()298    #æ½è¥299    alipay_fertilize()300# startTaobao()301# taobao_task()302# fertilize()303304# alipay_task()305#alipay_fertilize()306# start_taobao()307# start_alipay()
...bot.py
Source:bot.py  
...9        return self.bot.sess10    def switch_screen(self, id_screen):11        util.logger('Switch screen: {}'.format(id_screen))12        if id_screen == ID_SCREEN_PROFILE:13            return self.bot.find_by_id('profile_tab').click_exists(timeout=2)14        elif id_screen == ID_SCREEN_SELECT_USERS:15            id_profile = self.bot.find_by_id('profile_tab')16            if id_profile.exists(timeout=2):17                return id_profile.long_click()18            return False19        elif id_screen == ID_SCREEN_OPTIONS:20            return self.bot.find_by_desc('Options').click_exists(timeout=2)21        elif id_screen == ID_SCREEN_UPLOAD_REEL:22            if self.switch_screen(ID_SCREEN_PROFILE):23                if self.bot.find_by_desc('Create New').click_exists(timeout=2):24                    if self.bot.find_by_desc('Reel').click_exists(timeout=2):25                        self.bot.find_by_id(26                            'auxiliary_button').click_exists(timeout=2)27                        if self.bot.find_by_id('dial_ar_effect_picker_left_side_button_container').click_exists(timeout=2):28                            if self.bot.find_by_id('gallery_folder_menu').click_exists(timeout=2):29                                if self.bot.find_by_desc('Instagram').click_exists(timeout=2):30                                    return True31            return False32        elif id_screen == ID_SCREEN_VIDEOS_SAVED:33            if self.bot.find_by_desc('Saved').click_exists(timeout=2):34                if self.bot.find_by_id('saved_collection_thumbnail').click_exists(timeout=5):35                    return self.bot.find_by_desc('Saved reels').click_exists(timeout=5)36            return False37    def remove_video_saved(self, item_selected):38        util.logger('Remove video: Select item')39        if self.bot.find_by_desc('Options').click_exists(timeout=2):40            if self.bot.find_by_text('Selectâ¦').click_exists(timeout=2):41                if item_selected.click_exists(timeout=2):42                    if self.bot.find_by_id('remove_button').click_exists(timeout=2):43                        self.bot.find_by_text('Unsave').click_exists(timeout=2)44                        util.logger('Remove video: Removed')45                        return True46        return False47    def set_user(self, user):48        util.logger('Set user')49        if self.switch_screen(ID_SCREEN_SELECT_USERS):50            if user.click_exists(timeout=2):51                util.logger('=> User: {}'.format(user.info['text']))52                if self.bot.find_by_id('bottom_sheet_container_view').exists(timeout=2):53                    self.bot.sess.press('back')54                    return True55        return False56    def select_item_video_saved(self, item_selected):57        util.logger('Select item video saved')58        return item_selected.click_exists(timeout=2)59    def get_items_video_saved(self):60        util.logger('Get items video saved')61        result = []62        id_items_videos_saved = self.bot.find_by_id(63            'clips_tab_grid_recyclerview')64        if id_items_videos_saved.exists(timeout=2):65            items = self.bot.find_child_by_class(66                id_items_videos_saved, 'android.widget.RelativeLayout')67            if items.exists(timeout=2):68                result = items69        util.logger('=> Total: {}'.format(result.count))70        return result71    def get_users(self):72        util.logger('Get users')73        data_users = {}74        if self.switch_screen(ID_SCREEN_SELECT_USERS):75            users = self.bot.find_by_id('row_user_textview')76            if users.exists(timeout=10):77                if users.count > 2:78                    for i in range(users.count-1):79                        data_users[users[i].info['text']] = users[i]80                    self.bot.sess.press('back')81        util.logger('=> Total: {}'.format(len(data_users)))82        return data_users83    def download_video(self):84        util.logger('Download video: Select video')85        if self.bot.find_by_id('direct_share_button').click_exists(timeout=4):86            if self.bot.find_by_desc('Add reel to your story').click_exists(timeout=10):87                if self.bot.find_by_id('overflow_button').click_exists(timeout=2):88                    if self.bot.find_by_id('gallery_menu_save').click_exists(timeout=2):89                        util.logger('Download video: Start')90                        # waiting download91                        msg_processing = self.bot.find_by_id('message')92                        if msg_processing.exists(timeout=2):93                            msg_processing.wait_gone(timeout=(60*10))94                            util.logger('Download video: Saved')95                            self.bot.sess.press('back')96                            self.bot.find_by_desc(97                                'Discard video').click_exists(timeout=4)98                            self.bot.sess.press('back')99                            self.bot.find_by_desc(100                                'Back').click_exists(timeout=2)101                            util.logger('Download video: End')102                            return True103        return False104    def download_video_by_login(self, item, account):105        util.logger('Download video by login')106        if self.select_item_video_saved(item):107            if self.bot.find_by_desc('More').click_exists(timeout=4):108                if self.bot.find_by_text('Copy Link').click_exists(timeout=4):109                    util.logger('=> Link: {}'.format(110                        self.bot.sess.clipboard))111                    self.bot.find_by_desc('Back').click_exists(timeout=2)112                    return True...uiauto.py
Source:uiauto.py  
...11    def device_initialize(self):12        self.device = uiautomator2.connect(self.ip)13    def click_by_text(self, text, contains=False, timeout=2):14        if contains:15            return self.device(textcontains=text).click_exists(timeout)16        return self.device(text=text).click_exists(timeout)17    def click_by_resourceId(self, resourceId, timeout):18        return self.device(resourceId=resourceId).click_exists(timeout)19    def click_by_description(self, description, contains=False, timeout=2):20        if contains:21            return self.device(descriptionContains=description).click_exists(timeout)22        return self.device(description=description).click_exists(timeout)23    def click_by_packageName(self, packageName, timeout):24        return self.device(packageName=packageName).click_exists(timeout)25    def click_list_text(self, list, contains=False, timeout=2):26        for text in list:...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!!
