Best Python code snippet using Airtest
report.py
Source: report.py
1# -*- coding: utf-8 -*-2import os3import airtest.report.report as report4LOGDIR = "log"5old_trans_screen = report.LogToHtml._translate_screen6old_trans_desc = report.LogToHtml._translate_desc7old_trans_code = report.LogToHtml._translate_code8screen_func = ["find_element_by_xpath", "find_element_by_id", "find_element_by_name", "assert_exist",9 "back", "forward", "switch_to_new_tab", "switch_to_previous_tab", "get",10 "click", "send_keys"]11second_screen_func = ["click", "send_keys"]12other_func = []13def new_trans_screen(self, step, code):14 trans = old_trans_screen(self, step, code)15 if "name" in step['data'] and step['data']["name"] in screen_func:16 screen = {17 "src": None,18 "rect": [],19 "pos": [],20 "vector": [],21 "confidence": None,22 }23 src = ""24 if step["data"]["name"] in second_screen_func:25 res = step["data"]['ret']26 src = res["screen"]27 if "pos" in res:28 screen["pos"] = res["pos"]29 for item in step["__children__"]:30 if item["data"]["name"] == "_gen_screen_log":31 res = item["data"]['ret']32 src = res["screen"]33 if "pos" in res:34 screen["pos"] = res["pos"]35 break36 if self.export_dir and src:37 src = os.path.join(LOGDIR, src)38 screen["src"] = src39 return screen40 else:41 return trans42def new_translate_desc(self, step, code):43 trans = old_trans_desc(self, step, code)44 if "name" in step['data'] and (step['data']["name"] in screen_func or step["data"]["name"] in other_func):45 name = step["data"]["name"]46 args = {i["key"]: i["value"] for i in code["args"]}47 desc = {48 "find_element_by_xpath": lambda: u"Find element by xpath: %s" % args.get("xpath"),49 "find_element_by_id": lambda: u"Find element by id: %s" % args.get("id"),50 "find_element_by_name": lambda: u"Find element by name: %s" % args.get("name"),51 "assert_exist": u"Assert element exists.",52 "click": u"Click the element that been found.",53 "send_keys": u"Send some text and keyboard event to the element that been found.",54 "get": lambda: u"Get the web address: %s" % args.get("address"),55 "switch_to_last_window": u"Switch to the last tab.",56 "switch_to_latest_window": u"Switch to the new tab.",57 "back": u"Back to the last page.",58 "forward": u"Forward to the next page.",59 "snapshot": u"Snopshot current page."60 }61 desc_zh = {62 "find_element_by_xpath": lambda: u"寻æ¾æå®é¡µé¢å
ç´ : \"%s\"" % args.get("xpath"),63 "find_element_by_id": lambda: u"寻æ¾æå®é¡µé¢å
ç´ : \"%s\"" % args.get("id"),64 "find_element_by_name": lambda: u"寻æ¾æå®é¡µé¢å
ç´ : \"%s\"" % args.get("name"),65 "assert_exist": u"æè¨é¡µé¢å
ç´ åå¨.",66 "click": u"ç¹å»æ¾å°ç页é¢å
ç´ .",67 "send_keys": u"ä¼ éææ¬\"%s\"å°éä¸ææ¬æ¡." % (args.get("text", "")),68 "get": lambda: u"访é®ç½ç»å°å: %s" % args.get("address"),69 "switch_to_last_window": u"åæ¢å°ä¸ä¸ä¸ªæ ç¾é¡µ.",70 "switch_to_latest_window": u"åæ¢å°ææ°æ ç¾é¡µ.",71 "back": u"åéå°ä¸ä¸ä¸ªé¡µé¢.",72 "forward": u"åè¿å°ä¸ä¸ä¸ªé¡µé¢.",73 "snapshot": u"æªåå½å页é¢."74 }75 if self.lang == 'zh':76 desc = desc_zh77 ret = desc.get(name)78 if callable(ret):79 ret = ret()80 return ret81 else:82 return trans83def new_translate_code(self, step):84 trans = old_trans_code(self, step)85 if trans:86 for idx, item in enumerate(trans["args"]):87 if item["key"] == "self":88 trans["args"].pop(idx)89 return trans90report.LogToHtml._translate_screen = new_trans_screen91report.LogToHtml._translate_desc = new_translate_desc...
Check out the latest blogs from LambdaTest on this topic:
Unit testing is typically software testing within the developer domain. As the QA role expands in DevOps, QAOps, DesignOps, or within an Agile team, QA testers often find themselves creating unit tests. QA testers may create unit tests within the code using a specified unit testing tool, or independently using a variety of methods.
People love to watch, read and interact with quality content — especially video content. Whether it is sports, news, TV shows, or videos captured on smartphones, people crave digital content. The emergence of OTT platforms has already shaped the way people consume content. Viewers can now enjoy their favorite shows whenever they want rather than at pre-set times. Thus, the OTT platform’s concept of viewing anything, anytime, anywhere has hit the right chord.
Agile project management is a great alternative to traditional methods, to address the customer’s needs and the delivery of business value from the beginning of the project. This blog describes the main benefits of Agile for both the customer and the business.
The purpose of developing test cases is to ensure the application functions as expected for the customer. Test cases provide basic application documentation for every function, feature, and integrated connection. Test case development often detects defects in the design or missing requirements early in the development process. Additionally, well-written test cases provide internal documentation for all application processing. Test case development is an important part of determining software quality and keeping defects away from customers.
I routinely come across test strategy documents when working with customers. They are lengthy—100 pages or more—and packed with monotonous text that is routinely reused from one project to another. Yawn once more— the test halt and resume circumstances, the defect management procedure, entrance and exit criteria, unnecessary generic risks, and in fact, one often-used model replicates the requirements of textbook testing, from stress to systems integration.
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!!