Best Python code snippet using toolium_python
basepage.py
Source:basepage.py
...21 # æ¶éå é¤è系人ååçååå表çé¿åº¦ï¼åå«æ¾å
¥å表ä¸22 _contactor_num = []23 def __init__(self, driver: WebDriver = None):24 self.driver = driver25 def set_implicitly_wait(self, timeout):26 self.driver.implicitly_wait(timeout)27 def find(self, by, locator=None):28 logger.info(f"find: by = {by},locator = {locator}")29 try:30 element = self.driver.find_element(by, locator)31 self._error_num = 032 self.set_implicitly_wait(10)33 return element34 except Exception as e:35 logger.info("è¿å
¥é»ååå¤ç")36 self.driver.get_screenshot_as_file('../report/error.png')37 self.set_implicitly_wait(3)38 if self._error_num > self._error_max:39 self._error_num = 040 self.set_implicitly_wait(10)41 raise e42 self._error_num += 143 for black in self._black_list:44 eles = self.finds(*black)45 if len(eles) > 0:46 eles[0].click()47 return self.find(by, locator)48 raise e49 def finds(self, by, locator=None):50 return self.driver.find_elements(by, locator)51 def find_click(self, by, locator):52 return self.find(by, locator).click()53 def send(self, by, locator, value):54 return self.find(by, locator).send_keys(value)...
classtimetable.py
Source:classtimetable.py
...15 # memu_ele = (By.XPATH, f'//div[@class="we-sider-menu app-sider-menu"]//span[contains(text(),"{memu}")]')16 # self.wait_for_display(memu_ele)17 # self.find_click(*memu_ele)18 self._params["memu"] = memu19 self.set_implicitly_wait(3)20 self.step(classtimetable_dir,"goto_undergradute_record")21 return UnderGraduteRecord(self._driver)22 def goto_teacher_management_degree(self,memu):23 '''24 æéæ師課表ï¼ç®¡ç端-æ¬ç§çï¼25 '''26 self._params["memu"] = memu27 self.set_implicitly_wait(5)28 self.step(classtimetable_dir, "goto_teacher_management_degree")29 return Teacher_Management_Degree(self._driver)30 def goto_teacher_management_master(self,memu):31 '''32 æéæ師課表ï¼ç®¡ç端-ç 究çï¼33 '''34 self._params["memu"] = memu35 self.set_implicitly_wait(3)36 self.step(classtimetable_dir, "goto_teacher_management_master")37 return Teacher_Management_Master(self._driver)38 def goto_room_management_degree(self,memu):39 '''40 æé課室課表ï¼ç®¡ç端-æ¬ç§çï¼41 '''42 self._params["memu"] = memu43 self.set_implicitly_wait(3)44 self.step(classtimetable_dir, "goto_room_management_degree")45 return Room_Management_Degree(self._driver)46 def goto_room_management_master(self,memu):47 '''48 æé課室課表ï¼ç®¡ç端-ç 究çï¼49 '''50 self._params["memu"] = memu51 self.set_implicitly_wait(3)52 self.step(classtimetable_dir, "goto_room_management_master")53 return Room_Management_Master(self._driver)54 def goto_student_management_degree(self,memu):55 '''56 æéå¸ç課表ï¼ç®¡ç端-æ¬ç§çï¼57 '''58 self._params["memu"] = memu59 self.set_implicitly_wait(3)60 self.step(classtimetable_dir, "goto_student_management_degree")61 return Student_Management_Degree(self._driver)62 def goto_student_management_master(self,memu):63 '''64 æéå¸ç課表ï¼ç®¡ç端-ç 究çï¼65 '''66 self._params["memu"] = memu67 self.set_implicitly_wait(3)68 self.step(classtimetable_dir, "goto_student_management_master")69 return Student_Management_Master(self._driver)70 def goto_postgraduate_sign_in_record(self,memu):71 '''72 測試å
¥å£ï¼æéç 究çç°½å°è¨é73 '''74 self._params["memu"] = memu75 self.set_implicitly_wait(3)76 self.step(classtimetable_dir, "goto_postgraduate_sign_in_record")...
page_read.py
Source:page_read.py
...21 article.click()22 return ArticlePage()23 @classmethod24 def get_video_time(cls, article: WebElement):25 cls.set_implicitly_wait(1)26 _list = article.find_elements_by_xpath('//*[contains(@text, ":")]')27 cls.set_implicitly_wait(6)28 if _list:29 return _list[0].get_attribute('text')30 else:31 return None32 @classmethod33 def simulate_page_turning(cls):34 _num = random.randint(5, 7)35 for _ in range(_num):36 cls.swipe_up()37 @classmethod38 def switch_channel(cls, channel: str):39 _channel = (cls.MB.XPATH, f'//*[@text="{channel}"]/..')40 try:41 cls.find(_channel).click()42 except NoSuchElementException:43 logger.critical(f'该é¢éä¸åå¨ï¼è¯·æ£æ¥ï¼{channel}')44class RDPage(StudyPage):45 def __init__(self):46 super(RDPage, self).__init__()47 self.sign = 'read'48 self._channel_recommend = (self.MB.XPATH, '//*[@text="æ¨è"]')49 self._channel_button = (self.MB.XPATH, '//*[@text="æ¨è"]/../../following-sibling::android.widget.FrameLayout')50 def verify_page_visible(self):51 return self.find(self._channel_recommend).is_displayed()52 def open_channel_group(self):53 self.find(self._channel_button).click()54 return ChannelPage()55 @classmethod56 def is_article(cls, article: WebElement):57 cls.set_implicitly_wait(0.2)58 # æç« éè¦ææ¥æ59 _date = article.find_elements_by_xpath('//*[starts-with(@text,"2019-")]')60 if len(_date) == 0:61 cls.set_implicitly_wait(6)62 return False63 # æç« ä¸åºè¯¥æææ¾æ¶é´64 _time = article.find_elements_by_xpath('//*[contains(@text, ":")]')65 if len(_time) != 0:66 cls.set_implicitly_wait(6)67 return False68 # # æç« ä¸åºè¯¥æææ¾è¿åº¦æ¡69 # _seek = article.find_elements_by_class_name('android.widget.SeekBar')70 # if len(_seek) != 0: return False71 # æç« ä¸å
å«ä¸é¢ä¸¤ä¸ªå72 _special = article.find_elements_by_xpath('//*[contains(@text, "ä¸é¢")]')73 if len(_special) != 0:74 cls.set_implicitly_wait(6)75 return False76 # TODO: éè¦æ´ä¼é
å°å®ç°è®¾ç½®éå¼çå¾
æ¶é´77 cls.set_implicitly_wait(6)78 return True79'''80new UiScrollable(new UiSelector().resourceId("cn.xuexi.android:id/view_pager")).setAsHorizontalList().scrollIntoView(new UiSelector().text("订é
"))81new UiScrollable(new UiSelector().className("android.widget.ListView")).setAsHorizontalList().scrollIntoView(new UiSelector().text("订é
"))...
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!!