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:
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!!