Best Python code snippet using SeleniumBase
master_qa.py
Source: master_qa.py
...61 print(62 "WARNING: %s manual checks were skipped! (MasterQA)"63 % self.check_count64 )65 if self.__has_exception():66 self.__add_failure(sys.exc_info()[1])67 self.__process_manual_check_results(self.auto_close_results_page)68 super(MasterQA, self).tearDown()69 ####################70 def __get_timestamp(self):71 return str(int(time.time() * 1000))72 def __manual_check_setup(self):73 self.manual_check_count = 074 self.manual_check_successes = 075 self.incomplete_runs = 076 self.page_results_list = []77 self.__clear_out_old_logs(archive_past_runs=False)78 def __clear_out_old_logs(79 self, archive_past_runs=True, get_log_folder=False80 ):81 abs_path = os.path.abspath(".")82 file_path = abs_path + "/%s" % self.LATEST_REPORT_DIR83 if not os.path.exists(file_path):84 os.makedirs(file_path)85 if archive_past_runs:86 archive_timestamp = int(time.time())87 if not os.path.exists("%s/../%s/" % (file_path, self.ARCHIVE_DIR)):88 os.makedirs("%s/../%s/" % (file_path, self.ARCHIVE_DIR))89 archive_dir = "%s/../%s/log_%s" % (90 file_path,91 self.ARCHIVE_DIR,92 archive_timestamp,93 )94 shutil.move(file_path, archive_dir)95 os.makedirs(file_path)96 if get_log_folder:97 return archive_dir98 else:99 # Just delete bad pages to make room for the latest run.100 filelist = [101 f102 for f in os.listdir("./%s" % self.LATEST_REPORT_DIR)103 if (f.startswith("failed_"))104 or (f == self.RESULTS_PAGE)105 or (f.startswith("automation_failure"))106 or (f == self.BAD_PAGE_LOG)107 ]108 for f in filelist:109 os.remove("%s/%s" % (file_path, f))110 def __jq_confirm_dialog(self, question):111 count = self.manual_check_count + 1112 title = self.DEFAULT_VALIDATION_TITLE113 title_content = (114 '<center><font color="#7700bb">%s #%s:'115 '</font></center><hr><font color="#0066ff">%s</font>'116 "" % (title, count, question)117 )118 title_content = js_utils.escape_quotes_if_needed(title_content)119 jqcd = (120 """jconfirm({121 boxWidth: '32.5%%',122 useBootstrap: false,123 containerFluid: false,124 animationBounce: 1,125 type: 'default',126 theme: 'bootstrap',127 typeAnimated: true,128 animation: 'scale',129 draggable: true,130 dragWindowGap: 1,131 container: 'body',132 title: '%s',133 content: '',134 buttons: {135 pass_button: {136 btnClass: 'btn-green',137 text: 'YES / PASS',138 keys: ['y', 'p', '1'],139 action: function(){140 $jqc_status = "Success!";141 jconfirm.lastButtonText = "Success!";142 }143 },144 fail_button: {145 btnClass: 'btn-red',146 text: 'NO / FAIL',147 keys: ['n', 'f', '2'],148 action: function(){149 $jqc_status = "Failure!";150 jconfirm.lastButtonText = "Failure!";151 }152 }153 }154 });"""155 % title_content156 )157 self.execute_script(jqcd)158 def __manual_page_check(self, *args):159 if not args:160 instructions = self.DEFAULT_VALIDATION_MESSAGE # self.verify()161 else:162 instructions = str(args[0])163 if len(args) > 1:164 pass165 question = "Approve?" # self.verify("")166 if instructions and "?" not in instructions:167 question = instructions + " <> Approve?"168 elif instructions and "?" in instructions:169 question = instructions170 wait_time_before_verify = self.WAIT_TIME_BEFORE_VERIFY171 if self.verify_delay:172 wait_time_before_verify = float(self.verify_delay)173 # Allow a moment to see the full page before the dialog box pops up174 time.sleep(wait_time_before_verify)175 use_jqc = False176 self.wait_for_ready_state_complete()177 if js_utils.is_jquery_confirm_activated(self.driver):178 use_jqc = True179 else:180 js_utils.activate_jquery_confirm(self.driver)181 get_jqc = None182 try:183 get_jqc = self.execute_script("return jconfirm")184 get_jqc = get_jqc["instances"]185 use_jqc = True186 except Exception:187 use_jqc = False188 if use_jqc:189 # Use the jquery_confirm library for manual page checks190 self.__jq_confirm_dialog(question)191 time.sleep(0.02)192 waiting_for_response = True193 while waiting_for_response:194 time.sleep(0.05)195 jqc_open = self.execute_script(196 "return jconfirm.instances.length"197 )198 if str(jqc_open) == "0":199 break200 time.sleep(0.1)201 status = None202 try:203 status = self.execute_script("return $jqc_status")204 except Exception:205 status = self.execute_script("return jconfirm.lastButtonText")206 else:207 # Fallback to plain js confirm dialogs if can't load jquery_confirm208 if self.browser == "ie":209 text = self.execute_script(210 """if(confirm("%s")){return "Success!"}211 else{return "Failure!"}"""212 % question213 )214 elif self.browser == "chrome":215 self.execute_script(216 """if(confirm("%s"))217 {window.master_qa_result="Success!"}218 else{window.master_qa_result="Failure!"}"""219 % question220 )221 time.sleep(0.05)222 self.__wait_for_special_alert_absent()223 text = self.execute_script("return window.master_qa_result")224 else:225 try:226 self.execute_script(227 """if(confirm("%s"))228 {window.master_qa_result="Success!"}229 else{window.master_qa_result="Failure!"}"""230 % question231 )232 except WebDriverException:233 # Fix for https://github.com/mozilla/geckodriver/issues/431234 pass235 time.sleep(0.05)236 self.__wait_for_special_alert_absent()237 text = self.execute_script("return window.master_qa_result")238 status = text239 self.manual_check_count += 1240 try:241 current_url = self.driver.current_url242 except Exception:243 current_url = self.execute_script("return document.URL")244 if "Success!" in str(status):245 self.manual_check_successes += 1246 self.page_results_list.append(247 '"%s","%s","%s","%s","%s","%s","%s","%s"'248 % (249 self.manual_check_count,250 "Success",251 "-",252 current_url,253 self.browser,254 self.__get_timestamp()[:-3],255 instructions,256 "*",257 )258 )259 return 1260 else:261 bad_page_name = "failed_check_%s.png" % self.manual_check_count262 self.save_screenshot(bad_page_name, folder=self.LATEST_REPORT_DIR)263 self.page_results_list.append(264 '"%s","%s","%s","%s","%s","%s","%s","%s"'265 % (266 self.manual_check_count,267 "FAILED!",268 bad_page_name,269 current_url,270 self.browser,271 self.__get_timestamp()[:-3],272 instructions,273 "*",274 )275 )276 return 0277 def __wait_for_special_alert_absent(self):278 timeout = self.MAX_IDLE_TIME_BEFORE_QUIT279 for x in range(int(timeout * 20)):280 try:281 alert = self.driver.switch_to.alert282 dummy_variable = alert.text # Raises exception if no alert283 if "?" not in dummy_variable:284 return285 time.sleep(0.05)286 except NoAlertPresentException:287 return288 self.driver.quit()289 raise Exception(290 "%s seconds passed without human action! Stopping..." % timeout291 )292 def __has_exception(self):293 has_exception = False294 if hasattr(sys, "last_traceback") and sys.last_traceback is not None:295 has_exception = True296 elif python3 and hasattr(self, "_outcome"):297 if hasattr(self._outcome, "errors") and self._outcome.errors:298 has_exception = True299 else:300 if python3:301 has_exception = sys.exc_info()[1] is not None302 else:303 if not hasattr(self, "_using_sb_fixture_class") and (304 not hasattr(self, "_using_sb_fixture_no_class")305 ):306 has_exception = sys.exc_info()[1] is not None...
Check out the latest blogs from LambdaTest on this topic:
The QA testing profession requires both educational and long-term or experience-based learning. One can learn the basics from certification courses and exams, boot camp courses, and college-level courses where available. However, developing instinctive and practical skills works best when built with work experience.
Ever since the Internet was invented, web developers have searched for the most efficient ways to display content on web browsers.
In general, software testers have a challenging job. Software testing is frequently the final significant activity undertaken prior to actually delivering a product. Since the terms “software” and “late” are nearly synonymous, it is the testers that frequently catch the ire of the whole business as they try to test the software at the end. It is the testers who are under pressure to finish faster and deem the product “release candidate” before they have had enough opportunity to be comfortable. To make matters worse, if bugs are discovered in the product after it has been released, everyone looks to the testers and says, “Why didn’t you spot those bugs?” The testers did not cause the bugs, but they must bear some of the guilt for the bugs that were disclosed.
Xamarin is an open-source framework that offers cross-platform application development using the C# programming language. It helps to simplify your overall development and management of cross-platform software applications.
When software developers took years to create and introduce new products to the market is long gone. Users (or consumers) today are more eager to use their favorite applications with the latest bells and whistles. However, users today don’t have the patience to work around bugs, errors, and design flaws. People have less self-control, and if your product or application doesn’t make life easier for users, they’ll leave for a better solution.
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!!