Best Python code snippet using SeleniumBase
district_case.py
Source:district_case.py
...43 def test_002(self):44 name = DistrictCommon(self.driver).DistrictRequiredCommon()45 # print(name)46 DistrictPage(self.driver).search(name)47 DistrictPage(self.driver).click_search_result()48 DistrictPage(self.driver).addsubmit()49 DistrictPage(self.driver).search(name)50 Districname = DistrictPage(self.driver).gettable_body()[0].text51 Districcommon = DistrictPage(self.driver).gettable_body()[1].text52 self.assertEqual(Districname, name, msg='é误ï¼å¿
å¡«æ·»å åºåå表ä¸å称æ¾ç¤ºé误')53 self.assertEqual(Districcommon, '', msg='é误ï¼å¿
å¡«æ·»å åºåå表ä¸å¤æ³¨æ¾ç¤ºé误')54 DistrictPage(self.driver).click_search_result()55 Districtinfo= DistrictCommon(self.driver).GetDistrictInfo()56 districtlist = [name, None, 'ææ', None]57 Districtinfo2 = []58 for i in range(0, len(Districtinfo)):59 Districtinfo2.append(Districtinfo[i])60 if Districtinfo2[i] == '':61 Districtinfo2[i] = None62 self.assertEqual(Districtinfo2, districtlist, msg='å¿
å¡«æ·»å åºåäºæ¬¡ç¼è¾è¿å
¥ï¼æ°æ®æ¾ç¤ºé误')63 # æ£æ¥å¿
填项ï¼å¿
å¡«é¡¹ç©ºæ ¼è¾å
¥64 def test_003(self):65 strnumber = time.strftime('%y%m%d%M%S', time.localtime())66 name = "åºåå¿
å¡«" + strnumber67 EntranceAgentPage(self.driver).enter_district()68 time.sleep(5)69 DistrictPage(self.driver).click_add()70 submitinfo = DistrictPage(self.driver).check_submit_clickable()71 self.assertEqual(submitinfo, False, msg='é误ï¼å称æªè¾å
¥ï¼æ交æé®å¯è§¦å')72 DistrictPage(self.driver).input_name(' ')73 time.sleep(2)74 submitinfo = DistrictPage(self.driver).check_submit_clickable()75 self.assertEqual(submitinfo, False, msg='é误ï¼å¿
填项è¾å
¥ç©ºæ ¼ï¼æ交æé®å¯è§¦å')76 DistrictPage(self.driver).input_name(name)77 time.sleep(2)78 submitinfo = DistrictPage(self.driver).check_submit_clickable()79 self.assertEqual(submitinfo, True, msg='é误ï¼å¿
填项已填åï¼æ交æé®ä¸å¯è§¦å')80 DistrictPage(self.driver).delete_valid()81 time.sleep(2)82 submitinfo = DistrictPage(self.driver).check_submit_clickable()83 self.assertEqual(submitinfo, False, msg='é误ï¼æææ§ä¸ºç©ºï¼æ交æé®å¯è§¦å')84 # æ£æ¥è¿åå表æé® è¿å页é¢æ·»å æé®å¯ç¹å»85 DistrictPage(self.driver).backlist()86 submitinfo = DistrictPage(self.driver).check_add_clickable()87 self.assertEqual(submitinfo, True, msg='é误ï¼ç¹å»è¿åå表æé®ï¼è¿åå表失败')88 # å称éåæ£éª89 def test_004(self):90 strnumber = time.strftime('%y%m%d%M%S', time.localtime())91 name2 = name = "åºå å¿
å¡«" + strnumber92 name1 = DistrictCommon(self.driver).DistrictRequiredCommon()93 DistrictPage(self.driver).click_add()94 time.sleep(3)95 DistrictPage(self.driver).input_name(name2)96 DistrictPage(self.driver).choose_valid()97 DistrictPage(self.driver).addsubmit()98 DistrictPage(self.driver).click_add()99 time.sleep(3)100 DistrictPage(self.driver).input_name(name1)101 name_tip = DistrictPage(self.driver).get_name_tip()102 submitinfo = DistrictPage(self.driver).check_submit_clickable()103 self.assertEqual(name_tip,'该å称已åå¨ï¼è¯·æ´æ¢å
¶ä»å称ï¼', msg='å称éå¤æªæ示')104 self.assertEqual(submitinfo, False, msg='é误ï¼å称éå¤ï¼æ交æé®å¯è§¦å')105 # æ£æ¥å¸¦æç©ºæ ¼çå称éåæ£éª106 DistrictPage(self.driver).input_name(name2)107 name_tip = DistrictPage(self.driver).get_name_tip()108 submitinfo = DistrictPage(self.driver).check_submit_clickable()109 self.assertEqual(name_tip, '该å称已åå¨ï¼è¯·æ´æ¢å
¶ä»å称ï¼', msg='æ£æ¥å¸¦æç©ºæ ¼çå称éå¤æªæ示')110 self.assertEqual(submitinfo, False, msg='é误ï¼æ£æ¥å¸¦æç©ºæ ¼çå称éå¤ï¼æ交æé®å¯è§¦å')111 # æ·»å ä¸ä¸ªæ æåºå112 @Base.screenshot_about_case113 def test_005(self):114 name = DistrictCommon(self.driver).DistrictinvalidCommon()115 # åæ¢å°æ ætab click_invalid_tab116 DistrictPage(self.driver).click_invalid_tab()117 DistrictPage(self.driver).search(name)118 DistrictPage(self.driver).click_search_result()119 DistrictPage(self.driver).addsubmit()120 DistrictPage(self.driver).click_invalid_tab()121 DistrictPage(self.driver).search(name)122 Districname = DistrictPage(self.driver).gettable_body()[0].text123 Districcommon = DistrictPage(self.driver).gettable_body()[1].text124 self.assertEqual(Districname, name, msg='é误ï¼å¿
å¡«æ·»å åºåå表ä¸å称æ¾ç¤ºé误')125 self.assertEqual(Districcommon, '', msg='é误ï¼å¿
å¡«æ·»å åºåå表ä¸å¤æ³¨æ¾ç¤ºé误')126 DistrictPage(self.driver).click_search_result()127 Districtinfo= DistrictCommon(self.driver).GetDistrictInfo()128 districtlist = [name, None, 'æ æ', None]129 Districtinfo2 = []130 for i in range(0, len(Districtinfo)):131 Districtinfo2.append(Districtinfo[i])132 if Districtinfo2[i] == '':133 Districtinfo2[i] = None134 self.assertEqual(Districtinfo2, districtlist, msg='å¿
å¡«æ·»å åºåäºæ¬¡ç¼è¾è¿å
¥ï¼æ°æ®æ¾ç¤ºé误')135 # æ£æ¥æç´¢136 def test_006(self):137 strnumber = time.strftime('%y%m%d%M%S', time.localtime())138 # å å·,è±æåå· ç³»ç»æªå¤ç139 name2 = "TicketFree!@#$%^&*()Text" + strnumber140 # .get_attribute('content')141 EntranceAgentPage(self.driver).enter_district()142 time.sleep(5)143 # DistrictPage(self.driver).click_add()144 # time.sleep(3)145 # DistrictPage(self.driver).input_name(name2)146 # DistrictPage(self.driver).choose_valid()147 # DistrictPage(self.driver).addsubmit()148 #149 # num1, num2, num3, num4 = 0, 0, 0, 0150 # DistrictPage(self.driver).search('Ticket')151 # leftslaname = DistrictPage(self.driver).getleftslaname()152 # for i in range(0, len(leftslaname)):153 # print(len(leftslaname))154 # listinfo = leftslaname[i].get_attribute('content')155 # print(listinfo,1,name2)156 # if listinfo == name2:157 # num1 = num1 + 1158 #159 # DistrictPage(self.driver).search('Free')160 # leftslaname = DistrictPage(self.driver).getleftslaname()161 # for i in range(0, len(leftslaname)):162 # listinfo = leftslaname[i].text163 # if listinfo == name2:164 # num2 = num2 + 1165 #166 # DistrictPage(self.driver).search('Text')167 # leftslaname = DistrictPage(self.driver).getleftslaname()168 # for i in range(0, len(leftslaname)):169 # listinfo = leftslaname[i].text170 # if listinfo == name2:171 # num3 = num3 + 1172 #173 # DistrictPage(self.driver).search('!@#$%^&*()')174 # leftslaname = DistrictPage(self.driver).getleftslaname()175 # for i in range(0, len(leftslaname)):176 # listinfo = leftslaname[i].text177 # if listinfo == name2:178 # num4 = num4 + 1179 DistrictPage(self.driver).search('祥é¾åå
«æåå¤©å± é¾è®°')180 empty_tip = DistrictPage(self.driver).get_empty_tip()181 # self.assertEqual(num1, 1, msg='é误ï¼æ¨¡ç³æç´¢å段æ°æ®æªæ¥å°å¹é
æ°æ®')182 # self.assertEqual(num2, 1, msg='é误ï¼æ¨¡ç³æç´¢ä¸æ®µæ°æ®æªæ¥å°å¹é
æ°æ®')183 # self.assertEqual(num3, 1, msg='é误ï¼æ¨¡ç³æç´¢å段æ°æ®æªæ¥å°å¹é
æ°æ®')184 # self.assertEqual(num4, 1, msg='é误ï¼æ¨¡ç³æç´¢ç¹æ®å符æªæ¥å°å¹é
æ°æ®')185 self.assertEqual(empty_tip, 'ææ æ°æ®', msg='é误ï¼æ¨¡ç³æç´¢ç¹æ®å符æªæ¥å°å¹é
æ°æ®')186 # å
¨å¡«å建åºå bug å表ä¸ä¸æ¾ç¤ºå¤æ³¨ï¼æä¸å¤æå表æ°æ®187 # @Base.screenshot_about_case188 # def test_007(self):189 # # æªå®æï¼åºåå¼æªåå°190 # name, coment, parentdistrict = DistrictCommon(self.driver).DistrictFullCommon()191 # DistrictPage(self.driver).search(name)192 # DistrictPage(self.driver).click_search_result()193 # DistrictPage(self.driver).addsubmit()194 # DistrictPage(self.driver).search(name)195 # Districname = DistrictPage(self.driver).gettable_body()[0].text196 # Districcommon = DistrictPage(self.driver).gettable_body()[1].text197 # name2 = parentdistrict + "::" + name198 # self.assertEqual(Districname, name2, msg='é误ï¼å
¨å¡«æ·»å åºåå表ä¸å称æ¾ç¤ºé误')199 # # self.assertEqual(Districcommon, coment, msg='é误ï¼å
¨å¡«æ·»å åºåå表ä¸å¤æ³¨æ¾ç¤ºé误')200 #201 # DistrictPage(self.driver).click_search_result()202 # Districtinfo = DistrictCommon(self.driver).GetDistrictInfo()203 # districtlist = (name, parentdistrict, 'ææ', coment)...
test_page_objects.py
Source:test_page_objects.py
...4 def go_to_google(self, sb):5 sb.open("https://google.com/ncr")6 def do_search(self, sb, search_term):7 sb.type('input[title="Search"]', search_term + "\n")8 def click_search_result(self, sb, content):9 sb.click('a[href*="%s"]' % content)10class SeleniumBaseGitHubPage:11 def click_seleniumbase_io_link(self, sb):12 link = '#readme article a[href*="seleniumbase.io"]'13 sb.wait_for_element_visible(link)14 sb.js_click(link)15 sb.switch_to_newest_window()16class SeleniumBaseIOPage:17 def do_search_and_click(self, sb, search_term):18 if sb.is_element_visible('[for="__search"] svg'):19 sb.click('[for="__search"] svg')20 sb.type('form[name="search"] input', search_term)21 sb.click("li.md-search-result__item h1:contains(%s)" % search_term)22class MyTests(BaseCase):23 def test_page_objects(self):24 search_term = "SeleniumBase GitHub"25 expected_text = "seleniumbase/SeleniumBase"26 GooglePage().go_to_google(self)27 GooglePage().do_search(self, search_term)28 self.assert_text(expected_text, "#search")29 GooglePage().click_search_result(self, expected_text)30 SeleniumBaseGitHubPage().click_seleniumbase_io_link(self)31 SeleniumBaseIOPage().do_search_and_click(self, "Dashboard")...
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!!