# How to use get_forwards method in Airtest

Best Python code snippet using Airtest

Player.py

Source:Player.py

`...46 self.eulers[1] = (self.eulers[1] + theta_increase) % 36047 self.eulers[0] = min(max(self.eulers[0] + phi_increase,-89),89)48 direction = (self.eulers[1]) % 36049 self.forward = Vector3(np.cos(np.radians(direction),dtype=np.float32),np.sin(np.radians(direction),dtype=np.float32),0)50 def get_forwards(self):51 #return np.array([self.forward.x,self.forward.y,self.forward.z])52 return np.array(53 [54 #x = cos(theta) * cos(phi)55 np.cos(56 np.radians(57 self.eulers[1]58 ),dtype=np.float3259 ) * np.cos(60 np.radians(61 self.eulers[0]62 ),dtype=np.float3263 ),64 #y = sin(theta) * cos(phi)65 np.sin(66 np.radians(67 self.eulers[1]68 ),dtype=np.float3269 ) * np.cos(70 np.radians(71 self.eulers[0]72 ),dtype=np.float3273 ),74 #x = sin(phi)75 np.sin(76 np.radians(77 self.eulers[0]78 ),dtype=np.float3279 )80 ], dtype = np.float3281 )82 83 def get_up(self):84 forwards = self.get_forwards()85 right = np.cross(86 a = forwards,87 b = self.global_up88 )89 return np.cross(90 a = right,91 b = forwards,92 )93 def updateToArray(self):94 self.position = np.array(self.position,dtype=np.float32)95# here lies the backup if the above vector3 start slowing down96 97# class Player:98# def __init__(self, position, eulers):99# self.position = np.array(position,dtype=np.float32)100# self.eulers = np.array(eulers,dtype=np.float32)101# self.moveSpeed = 1102# self.global_up = np.array([0, 0, 1], dtype=np.float32)103 104# def setProperties(self, position, eulers):105# self.position = np.array(position,dtype=np.float32)106# self.eulers = np.array(eulers,dtype=np.float32)107# self.moveSpeed = 1108# self.global_up = np.array([0, 0, 1], dtype=np.float32)109# def rotate(self, vector, angle):110# pass111# def move(self, direction, amount):112# walkDirection = (direction + self.eulers[1]) % 360113# self.position[0] += amount * self.moveSpeed * np.cos(np.radians(walkDirection),dtype=np.float32)114# self.position[1] += amount * self.moveSpeed * np.sin(np.radians(walkDirection),dtype=np.float32)115# def increment_direction(self, theta_increase, phi_increase):116# self.eulers[1] = (self.eulers[1] + theta_increase) % 360117# self.eulers[0] = min(max(self.eulers[0] + phi_increase,-89),89)118# def pull_down(self,amount):119# if(self.position[2] > -0.52):120# print(self.position)121# self.position[2] -= amount*1122 123# def pull_up(self,amount):124# if(self.position[2] < 13):125# print(self.position)126# self.position[2] += amount*1127 128# def get_forwards(self):129# return np.array(130# [131# #x = cos(theta) * cos(phi)132# np.cos(133# np.radians(134# self.eulers[1]135# ),dtype=np.float32136# ) * np.cos(137# np.radians(138# self.eulers[0]139# ),dtype=np.float32140# ),141# #y = sin(theta) * cos(phi)142# np.sin(143# np.radians(144# self.eulers[1]145# ),dtype=np.float32146# ) * np.cos(147# np.radians(148# self.eulers[0]149# ),dtype=np.float32150# ),151# #x = sin(phi)152# np.sin(153# np.radians(154# self.eulers[0]155# ),dtype=np.float32156# )157# ], dtype = np.float32158# )159 160# def get_up(self):161# forwards = self.get_forwards()162# right = np.cross(163# a = forwards,164# b = self.global_up165# )166# return np.cross(167# a = right,168# b = forwards,...`

`...14 def get_data(self):15 return self._data16 def set_forwards(self, forwards):17 self._forwards = forwards18 def get_forwards(self):19 return self._forwards20class SkipList:21 _max_level = 622 def __init__(self):23 self._level_count = 124 self._head = Node()25 self._head._forwards = [None] * type(self)._max_level26 def find(self, value: int) -> Optional[None]:27 p = self._head28 # ä»æå¤å±çæéå¼å§éå29 for i in range(self._level_count - 1, -1, -1):30 while p.get_forwards()[i] and p.get_forwards()[i].get_data() < value:31 p = p.get_forwards()[i]32 # å¤æ­ç¬¬ä¸å±ï¼å®éä¸å°±æ¯å¤æ­pçä¸ä¸ä¸ªèç¹33 return p.get_forwards()[0] if p.get_forwards()[0] and p.get_forwards()[0].get_data() == value else None34 def insert(self, value: int):35 level = self._random_level()36 new_node = Node(value)37 new_node.set_forwards([None] * level)38 update = [None] * level39 p = self._head40 for i in range(level - 1, -1, -1):41 while p.get_forwards()[i] and p.get_forwards()[i].get_data() < value:42 p = p.get_forwards()[i]43 update[i] = p44 # äº¤æ¢æ¯ä¸å±æéçæå45 for i in range(level):46 new_node.get_forwards()[i] = update[i].get_forwards()[i]47 update[i].get_forwards()[i] = new_node48 if level > self._level_count:49 self._level_count = level50 def delete(self, value: int):51 update = [None] * self._level_count52 p = self._head53 for i in range(self._level_count - 1, -1, -1):54 while p.get_forwards()[i] and p.get_forwards()[i].get_data() < value:55 p = p.get_forwards()[i]56 update[i] = p57 # ç¡®å®æ¾å°valueåï¼äº¤æ¢æ¯ä¸å±æéçæå58 if p.get_forwards()[0] and p.get_forwards()[0].get_data() == value:59 for i in range(self._level_count - 1, -1, -1):60 if update[i].get_forwards()[i] and update[i].get_forwards()[i].get_data() == value:61 update[i].get_forwards()[i] = update[i].get_forwards()[i].get_forwards()[i]62 def _random_level(self, p: float = 0.5) -> int:63 """64 è·åèç¹æéå±çº§ï¼çè®ºæ¥è®²ï¼ä¸çº§ç´¢å¼ä¸­åç´ ä¸ªæ°åºè¯¥å åå§æ°æ®ç 50%ï¼äºçº§ç´¢å¼ä¸­åç´ ä¸ªæ°å  25%ï¼ä¸çº§ç´¢å¼12.5% ï¼ä¸ç´å°æé¡¶å±ã65 å ä¸ºè¿éæ¯ä¸å±çæåæ¦çæ¯ 50%ãå¯¹äºæ¯ä¸ä¸ªæ°æå¥çèç¹ï¼é½éè¦è°ç¨ randomLevel çæä¸ä¸ªåççå±æ°ã66 è¯¥ randomLevel æ¹æ³ä¼éæºçæ 1~MAX_LEVEL ä¹é´çæ°ï¼ä¸ ï¼67 50%çæ¦çè¿å 168 25%çæ¦çè¿å 269 12.5%çæ¦çè¿å 3 ...70 :param p:71 :return:72 """73 level = 174 while random.random() < p and level < type(self)._max_level:75 level += 176 return level77 def pprint(self):78 for i in range(self._level_count):79 datas = []80 node = self._head81 while node.get_forwards()[i]:82 datas.append(str(node.get_forwards()[i].get_data()))83 node = node.get_forwards()[i]84 print("pointer path" + str(i) + ": *head -> " + " -> ".join(datas))85if __name__ == '__main__':86 sk = SkipList()87 for v in range(-30, 200, 3):88 sk.insert(v)89 sk.pprint()90 node = sk.find(189)91 print("find num {}".format(node.get_data()) if node else "not found 189")92 sk.delete(189)93 node = sk.find(189)...`

BaseCommunicateVK.py

Source:BaseCommunicateVK.py

`...48 attach_string = "{}{}_{}".format(attach_type, attach_owner_id, attach_id)49 attach_strings.append(attach_string)50 return ",".join(attach_strings)51 @staticmethod52 def get_forwards(attachments, last_message):53 if not attachments or "fwd_count" not in attachments:54 return ""55 if len(last_message["fwd_messages"]) == int(attachments["fwd_count"]):56 return last_message["id"]57 def send(self, user_id, message, attachments=None, destroy=False, destroy_type=0, **kwargs):58 send_to = int(user_id)59 if "last_message" in kwargs:60 last_message = kwargs["last_message"]61 else:62 last_message = None63 p_attachments = self.get_attachments(last_message)64 p_forward = self.get_forwards(attachments, last_message)65 if message or p_attachments or p_forward:66 self.api.messages.send(67 user_id=send_to, message=message,68 attachment=p_attachments,69 forward_messages=p_forward)70 if destroy:71 accept_msg_id = self.api.messages \72 .getHistory(peer_id=user_id, count=1) \73 .get('items')[0].get('id')74 self.delete(accept_msg_id, destroy_type=destroy_type)75 def delete(self, msg_id, destroy_type=1):...`

## 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.