Best Python code snippet using Airtest
win.py
Source: win.py
...93 None94 """95 if isinstance(point, (tuple, list)):96 point = Point(x=point[0], y=point[1])97 point = self._windowpos_to_screenpos(point)98 self.mouse.press(button=button, coords=(point.x, point.y))99 time.sleep(duration)100 self.mouse.release(button=button, coords=(point.x, point.y))101 def swipe(self, point1: Union[Tuple[int, int], List, Point], point2: Union[Tuple[int, int], List, Point],102 duration: Union[float, int, None] = 0.01, steps=5):103 """104 æ»å¨ä¸æ®µè·ç¦»105 Args:106 point1: èµ·å§ç¹107 point2: ç»ç¹108 duration: æ»å¨ç»æåå»¶è¿å¤ä¹
æ¬èµ·109 steps: æ¥é¿110 Returns:111 """112 if isinstance(point1, (tuple, list)):113 point1 = Point(x=point1[0], y=point1[1])114 if isinstance(point2, (tuple, list)):115 point2 = Point(x=point2[0], y=point2[1])116 start = self._windowpos_to_screenpos(point1)117 end = self._windowpos_to_screenpos(point2)118 interval = float(duration) / (steps + 1)119 self.mouse.press(coords=(start.x, start.y))120 time.sleep(interval)121 for i in range(1, steps):122 x = int(start.x + (end.x - start.x) * i / steps)123 y = int(start.y + (end.y - start.y) * i / steps)124 self.mouse.move(coords=(x, y))125 time.sleep(interval)126 self.mouse.move(coords=(end.x, end.y))127 self.mouse.release(coords=(end.x, end.y))128 # # -----------129 # if isinstance(point1, (tuple, list)):130 # point1 = Point(x=point1[0], y=point1[1])131 #132 # if isinstance(point1, (tuple, list)):133 # point2 = Point(x=point2[0], y=point2[1])134 #135 # start = self._windowpos_to_screenpos(point1)136 # end = self._windowpos_to_screenpos(point2)137 # interval = float(duration) / (steps + 1)138 # self.mouse.press(coords=(start.x, start.x))139 # time.sleep(interval)140 # for i in range(1, steps):141 # x = int(start.x + (end.x - start.x) * i / steps)142 # y = int(start.y + (end.y - start.y) * i / steps)143 # self.mouse.move(coords=(x, y))144 # time.sleep(interval)145 # self.mouse.move(coords=(end.x, end.y))146 # self.mouse.release(coords=(end.x, end.y))147 def keyevent(self, keycode: str):148 """149 Perform a key event150 References:151 https://pywinauto.readthedocs.io/en/latest/code/pywinauto.keyboard.html152 Args:153 keycode: key code number or name154 Returns:155 None156 """157 self.keyboard.send_keys(keycode)158 def text(self, text: str):159 """160 è¾å
¥æå161 Args:162 text: å¾
è¾å
¥çæå163 Returns:164 None165 """166 self.keyevent(text)167 def screenshot(self):168 img = Image(self.cap_fun.screenshot())169 if self.cap_method == SCREENSHOT_MODE.WindowsGraphicsCapture:170 # ä¸,ä¸,å·¦,å³ self._window_border171 rect = Rect(x=self._window_border[2],172 y=self._window_border[0],173 width=self._screenshot_size.width,174 height=self._screenshot_size.height)175 return img.crop_image(rect)176 return img177 @staticmethod178 def set_foreground(handle) -> None:179 """180 å°æå®å¥æççªå£å¸¦å°åå°å¹¶æ¿æ´»è¯¥çªå£181 Returns:182 None183 """184 win32gui.SetForegroundWindow(handle)185 @property186 def rect(self) -> Rect:187 """188 è·åçªå£å®¢æ·ç«¯åºåå½åæå¨å±å¹çä½ç½®189 Returns:190 çªå£çä½ç½®(以å
¨å±å·¦ä¸è§å¼å§ä¸ºåç¹çåæ )191 """192 clientRect = win32gui.GetClientRect(self._hwnd)193 point = win32gui.ScreenToClient(self._hwnd, (0, 0))194 rect = Rect(x=abs(point[0]), y=abs(point[1]), width=clientRect[2], height=clientRect[3])195 return rect196 @property197 def title(self) -> str:198 """199 è·åçªå£å200 Returns:201 çªå£å202 """203 return self._top_window.texts()204 def kill(self) -> None:205 """206 å
³éçªå£207 Returns:208 None209 """210 self.app.kill()211 def _windowpos_to_screenpos(self, pos: Point):212 """213 转æ¢ç¸å¯¹åæ 为å±å¹çç»å¯¹åæ 214 Args:215 pos: éè¦è½¬æ¢çåæ 216 Returns:217 Point218 """219 windowpos = self.rect.tl220 pos = pos + windowpos221 return pos222 def get_window_border(self):223 info = GetWindowInfo(self._hwnd)224 print(f'rcWindow: {info.rcWindow.left} {info.rcWindow.top} {info.rcWindow.right} {info.rcWindow.bottom}')225 print(f'rcClient: {info.rcClient.left} {info.rcClient.top} {info.rcClient.right} {info.rcClient.bottom}')...
Check out the latest blogs from LambdaTest on this topic:
API (Application Programming Interface) is a set of definitions and protocols for building and integrating applications. It’s occasionally referred to as a contract between an information provider and an information user establishing the content required from the consumer and the content needed by the producer.
Before we discuss Scala testing, let us understand the fundamentals of Scala and how this programming language is a preferred choice for your development requirements.The popularity and usage of Scala are rapidly rising, evident by the ever-increasing open positions for Scala developers.
Have you ever struggled with handling hidden elements while automating a web or mobile application? I was recently automating an eCommerce application. I struggled with handling hidden elements on the web page.
There is just one area where each member of the software testing community has a distinct point of view! Metrics! This contentious issue sparks intense disputes, and most conversations finish with no definitive conclusion. It covers a wide range of topics: How can testing efforts be measured? What is the most effective technique to assess effectiveness? Which of the many components should be quantified? How can we measure the quality of our testing performance, among other things?
Agile software development stems from a philosophy that being agile means creating and responding to change swiftly. Agile means having the ability to adapt and respond to change without dissolving into chaos. Being Agile involves teamwork built on diverse capabilities, skills, and talents. Team members include both the business and software development sides working together to produce working software that meets or exceeds customer expectations continuously.
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!!