How to use __swipe_move method in Airtest

Best Python code snippet using Airtest

base_touch.py

Source:base_touch.py Github

copy

Full Screen

...162 None163 """164 touch_events = [DownEvent(tuple_xy, pressure=self.default_pressure), SleepEvent(duration), UpEvent()]165 self.perform(touch_events)166 def __swipe_move(self, tuple_from_xy, tuple_to_xy, duration=0.8, steps=5):167 """168 Return a sequence of swipe motion events (only MoveEvent)169 minitouch protocol example::170 d 0 0 0 50171 c172 m 0 20 0 50173 c174 m 0 40 0 50175 c176 m 0 60 0 50177 c178 m 0 80 0 50179 c180 m 0 100 0 50181 c182 u 0183 c184 Args:185 tuple_from_xy: start point186 tuple_to_xy: end point187 duration: time interval for swipe duration, default is 0.8188 steps: size of swipe step, default is 5189 Returns:190 [MoveEvent(from_x, from_y), ..., MoveEvent(to_x, to_y)]191 """192 from_x, from_y = tuple_from_xy193 to_x, to_y = tuple_to_xy194 ret = []195 interval = float(duration) / (steps + 1)196 for i in range(1, steps):197 ret.append(MoveEvent((from_x + (to_x - from_x) * i / steps,198 from_y + (to_y - from_y) * i / steps)))199 ret.append(SleepEvent(interval))200 ret += [MoveEvent((to_x, to_y), pressure=self.default_pressure), SleepEvent(interval)]201 return ret202 @on_method_ready('install_and_setup')203 def swipe_along(self, coordinates_list, duration=0.8, steps=5):204 """205 Perform swipe event across multiple points in sequence.206 Args:207 coordinates_list: list of coordinates: [(x1, y1), (x2, y2), (x3, y3)]208 duration: time interval for swipe duration, default is 0.8209 steps: size of swipe step, default is 5210 Returns:211 None212 """213 tuple_from_xy = coordinates_list[0]214 swipe_events = [DownEvent(tuple_from_xy, pressure=self.default_pressure), SleepEvent(0.1)]215 for tuple_to_xy in coordinates_list[1:]:216 swipe_events += self.__swipe_move(tuple_from_xy, tuple_to_xy, duration=duration, steps=steps)217 tuple_from_xy = tuple_to_xy218 swipe_events.append(UpEvent())219 self.perform(swipe_events)220 @on_method_ready('install_and_setup')221 def swipe(self, tuple_from_xy, tuple_to_xy, duration=0.8, steps=5):222 """223 Perform swipe event.224 Args:225 tuple_from_xy: start point226 tuple_to_xy: end point227 duration: time interval for swipe duration, default is 0.8228 steps: size of swipe step, default is 5229 Returns:230 None231 """232 swipe_events = [DownEvent(tuple_from_xy, pressure=self.default_pressure), SleepEvent(0.1)]233 swipe_events += self.__swipe_move(tuple_from_xy, tuple_to_xy, duration=duration, steps=steps)234 swipe_events.append(UpEvent())235 self.perform(swipe_events)236 @on_method_ready('install_and_setup')237 def two_finger_swipe(self, tuple_from_xy, tuple_to_xy, duration=0.8, steps=5, offset=(0, 50)):238 """239 Perform two finger swipe action240 minitouch protocol example::241 d 0 0 0 50242 d 1 1 0 50243 c244 m 0 20 0 50245 m 1 21 0 50246 c247 m 0 40 0 50...

Full Screen

Full Screen

env_atari_2048.py

Source:env_atari_2048.py Github

copy

Full Screen

...25 points = 026 if action == 0:27 self.board = self.board_prev.copy()28 elif action == 1:29 points = self.__swipe_move(1)30 elif action == 2:31 points = self.__swipe_move(2)32 elif action == 3:33 points = self.__swipe_move(3)34 elif action == 4:35 points = self.__swipe_move(4)36 self.reward = points/8.037 self.set_no_terminal_state()38 if self.__board_max() == 4096:39 self.reward = 10.040 self.set_terminal_state()41 self.__respawn()42 elif self.__count_empty() == 0:43 self.reward = -10.044 self.set_terminal_state()45 self.__respawn()46 self.game_cnt+= 147 if self.game_cnt >= 20:48 self.next_game()49 self.game_cnt = 050 else:51 self.board_prev = self.board.copy()52 self.__spawn_element(2)53 self.__update_state()54 self.update_state()55 self.next_move()56 def __swipe_move(self, move):57 points = 058 for i in range(0, self.board_size):59 if move == 1:60 points+= self.__swipe_row_right(i)61 elif move == 2:62 points+= self.__swipe_row_left(i)63 elif move == 3:64 points+= self.__swipe_column_right(i)65 elif move == 4:66 points+= self.__swipe_column_left(i)67 return points68 def __swipe_row_right(self, row):69 change = True70 merged = 0...

Full Screen

Full Screen

env_2048.py

Source:env_2048.py Github

copy

Full Screen

...31 points = 032 if action == 0:33 self.board = self.board_prev.copy()34 elif action == 1:35 points = self.__swipe_move(1)36 elif action == 2:37 points = self.__swipe_move(2)38 elif action == 3:39 points = self.__swipe_move(3)40 elif action == 4:41 points = self.__swipe_move(4)42 self.reward = points/10.043 self.set_no_terminal_state()44 if self.__get_board_max_value() > self.max_value:45 self.max_value = self.__get_board_max_value()46 max_score = str(self.get_move()) + " "47 max_score+= str(self.game_idx) + " "48 max_score+= str(self.max_value) + " "49 max_score+= "\n"50 self.max_score_log.put_string(max_score)51 if self.__get_board_max_value() == 2048:52 self.reward = 10.053 self.game_idx+= 154 self.set_terminal_state()55 self.__respawn()56 elif self.__count_empty() == 0:57 self.reward = -10.058 self.game_idx+= 159 self.set_terminal_state()60 self.__respawn()61 else:62 self.board_prev = self.board.copy()63 self.__spawn_element(2)64 self.__update_state()65 self.__update_state()66 self.next_move()67 def __swipe_move(self, move):68 points = 069 for i in range(0, self.board_size):70 if move == 1:71 points+= self.__swipe_row_right(i)72 elif move == 2:73 points+= self.__swipe_row_left(i)74 elif move == 3:75 points+= self.__swipe_column_right(i)76 elif move == 4:77 points+= self.__swipe_column_left(i)78 return points79 def __swipe_row_right(self, row):80 change = True81 merged = 0...

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:

YouTube

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?

Helpful

NotHelpful