How to use gen_screen_log method in Airtest

Best Python code snippet using Airtest Github


Full Screen

...17 self.operation_to_func = {"xpath": self.find_element_by_xpath, "id": self.find_element_by_id,18 "name": self.find_element_by_name}19 def find_element_by_xpath(self, xpath):20 web_element = super(WebChrome, self).find_element_by_xpath(xpath)21 self.gen_screen_log(web_element)22 return Element(web_element)23 def find_element_by_id(self, id):24 web_element = super(WebChrome, self).find_element_by_id(id)25 self.gen_screen_log(web_element)26 return Element(web_element)27 def find_element_by_name(self, name):28 web_element = super(WebChrome, self).find_element_by_name(name)29 self.gen_screen_log(web_element)30 return Element(web_element)31 def switch_to_latest_window(self):32 _father = self.number33 self.number = len(self.window_handles) - 134 self.father_number[self.number] = _father35 self.switch_to_window(self.window_handles[self.number])36 time.sleep(0.5)37 def assert_exist(self, path, operation):38 try:39 func = self.operation_to_func[operation]40 except Exception:41 print("There was no operation: ", operation)42 return False43 try:44 func(path)45 except Exception as e:46 return False47 return True48 def switch_to_last_window(self):49 self.number = self.father_number[self.number]50 self.switch_to_window(self.window_handles[self.number])51 time.sleep(0.5)52 def snapshot(self):53 self.gen_screen_log()54 @logwrap55 def get(self, address):56 super(WebChrome, self).get(address)57 log_in_func({"args": address})58 time.sleep(2)59 @logwrap60 def back(self):61 super(WebChrome, self).back()62 log_in_func({"args": ""})63 time.sleep(1)64 @logwrap65 def forward(self):66 super(WebChrome, self).forward()67 log_in_func({"args": ""})68 time.sleep(1)69 def gen_screen_log(self, element=None):70 if ST.LOG_DIR is None:71 return None72 jpg_file_name = str(int(time.time())) + '.jpg'73 jpg_path = os.path.join(ST.LOG_DIR, jpg_file_name)74 self.save_screenshot(jpg_path)75 saved = {"screen": jpg_file_name}76 if element:77 size = element.size78 location = element.location79 x = size['width'] / 2 + location['x']80 y = size['height'] / 2 + location['y']81 if "darwin" in sys.platform:82 x, y = x * 2, y * 283 saved.update({"args": [[x, y]],})...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:


You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Airtest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?