How to use wait_for_text method in SeleniumBase

Best Python code snippet using SeleniumBase

tutorial.py

Source:tutorial.py Github

copy

Full Screen

...57 autoplay = 'GAMEDEV_AUTOPLAY' in os.environ58 if autoplay:59 speedscale = 1060 ypos = -2.2561 async def wait_for_text(text, delay=0.25, lineh=None, **kwargs):62 nonlocal ypos63 kwargs.setdefault('scale', 1)64 color = kwargs.pop('color', (*car.color,1))65 kwargs['color'] = (0,0,0,0)66 if isinstance(text, str):67 text = Text(car.group.ctx, text, ypos=ypos, **kwargs)68 ypos -= lineh or kwargs['scale']69 scene.things.append(text)70 text.body_color = animN(text.body_color, color, 0.5, sine_out)71 @fork72 async def f():73 await Wait(.7)74 text.body_color = animN(text.body_color, (1, 1, 1, 1), 1, sine_in)75 await Wait(delay/speedscale)76 return text77 async def next_page(keep_longer=()):78 nonlocal ypos79 ypos -= 480 scene.view_rect = -4, ypos - 8, 4, ypos + 481 @fork82 async def f():83 things = list(scene.things)84 for thing in things:85 if isinstance(thing, Text):86 @fork87 async def f():88 if thing in keep_longer:89 await Wait(0.2)90 duration = 191 thing.body_color = animN(92 thing.body_color, (0, 0, 0, 0), duration, sine_in)93 await Wait(0.2)94 await Wait(5)95 for thing in things:96 try:97 scene.things.remove(thing)98 except ValueError:99 pass100 def update_car_view_rect(area_x, area_y, dx=0, dy=0):101 x, y = car.pos102 vx, vy = car.velocity103 x += vx + dx104 y += vy + dy105 car_scene.view_rect = x-area_x, y-area_y, x+area_x, y+area_y106 @fork107 async def cont():108 nonlocal ypos109 await Wait(0.5/speedscale)110 update_car_view_rect(3, 3, 0, -4)111 await wait_for_text('← This is a race car. ', scale=0.75, lineh=1)112 await wait_for_text("Let's learn to control it.", scale=0.65, lineh=1)113 num_text = await wait_for_text(114 "If you have a numeric keypad,", scale=0.65, lineh=0.7)115 await wait_for_text("press 8 on it.", scale=0.65, lineh=1)116 qwerty_text = await wait_for_text("Otherwise, press W.", scale=0.65, lineh=2)117 kbd.claim_key(QWERTY_LAYOUT[7], keypad, 9)118 kbd.claim_key(NUMPAD_LAYOUT[7], keypad, 10)119 layout = None120 selected_text = None121 blocker = Blocker()122 @partial(keypad.set_callback, 9)123 def select_numpad():124 nonlocal selected_text125 nonlocal layout126 if layout is None:127 layout = QWERTY_LAYOUT128 selected_text = qwerty_text129 blocker.unblock()130 @partial(keypad.set_callback, 10)131 def select_qwerty():132 nonlocal layout133 nonlocal selected_text134 if layout is None:135 layout = NUMPAD_LAYOUT136 selected_text = num_text137 blocker.unblock()138 if autoplay:139 keypad.kbd(9, True)140 await blocker141 #selected_text.body_color = animN(142 # selected_text.body_color, (*car.color, 1), 2, sine_in)143 car.move(0, 1)144 update_car_view_rect(5, 5)145 keypad.claim_layout(kbd, layout)146 keypad.update(car)147 unblock_keypad(5)148 await Wait(0.5/speedscale)149 await next_page([selected_text])150 await wait_for_text("Nice!", scale=0.65, lineh=1)151 await wait_for_text(f"The {keyname(layout[7])} key accelerates.", scale=0.65, lineh=0.7)152 await wait_for_text("Try it again!", scale=0.65, lineh=1)153 blocker = Blocker()154 keypad.set_callback(7, blocker.unblock)155 if autoplay:156 keypad.kbd(9, True)157 await blocker158 duration = car.move(0, 1)159 update_car_view_rect(5, 7)160 await keypad.pause(duration, fadeout_time=0)161 keypad.update(car)162 unblock_keypad()163 #await next_page()164 unblock_keypad(2, reset=True)165 await wait_for_text("How about steering?.", scale=0.65, lineh=1)166 await wait_for_text(f"Use the {keyname(layout[6])} key to turn slightly.", scale=0.65, lineh=1)167 blocker = Blocker()168 keypad.set_callback(6, blocker.unblock)169 if autoplay:170 keypad.kbd(6, True)171 await blocker172 duration = car.move(-1, 1)173 update_car_view_rect(5, 8)174 await keypad.pause(duration, fadeout_time=0)175 keypad.update(car)176 await next_page()177 unblock_keypad(2)178 unblock_keypad(5)179 unblock_keypad(8)180 await wait_for_text("Labels on the grid show", scale=0.65, lineh=.7)181 await wait_for_text("where the car will go", scale=0.65, lineh=.7)182 await wait_for_text("if you press a key.", scale=0.65, lineh=1.05)183 await wait_for_text("There's a curve ahead;", scale=0.65, lineh=.7)184 await wait_for_text(" start turning left→", scale=0.65, lineh=.7)185 await wait_for_text("to try avoiding it.", scale=0.65, lineh=.7)186 blocker = Blocker()187 for n in 6, 7, 8:188 keypad.set_callback(n, partial(blocker.unblock, n))189 if autoplay:190 keypad.kbd(8, True)191 direction = await blocker192 duration = car.act(direction)193 update_car_view_rect(6, 8, 0, -3)194 await keypad.pause(duration, fadeout_time=0)195 keypad.update(car)196 await next_page()197 print(direction)198 ypos += 2199 if direction == 6:200 await wait_for_text("That wasn't left at all!", scale=0.65, lineh=.7)201 await wait_for_text("You're headed for a crash.", scale=0.65, lineh=.7)202 await wait_for_text("The curve ahead is close!", scale=0.65, lineh=1)203 elif direction == 7:204 await wait_for_text("The car didn't turn as much", scale=0.65, lineh=.7)205 await wait_for_text("to the left as it could,", scale=0.65, lineh=.7)206 await wait_for_text("but that was your choice.", scale=0.65, lineh=1)207 await wait_for_text("The curve ahead is close!", scale=0.65, lineh=.7)208 else:209 await wait_for_text("Good job!", scale=0.65, lineh=1)210 await wait_for_text("The curve ahead is close, though.", scale=0.65, lineh=.7)211 await wait_for_text("Decelerate!", scale=0.65, lineh=1)212 await wait_for_text(f"The keys closer to your car:", scale=0.65, lineh=0.7)213 await wait_for_text(f"{keyname(layout[0])}, {keyname(layout[1])} and {keyname(layout[2])}", scale=0.65, lineh=0.7)214 await wait_for_text(f"will reduce your speed.", scale=0.65, lineh=1)215 await wait_for_text(f"With the center one, {keyname(layout[4])}", scale=0.65, lineh=.7)216 await wait_for_text(f"you'll keep current speed.", scale=0.65, lineh=1)217 await wait_for_text(f"Try slowing down as much", scale=0.65, lineh=.7)218 await wait_for_text(f"as you can!", scale=0.65, lineh=1)219 speed_before_crash = 0220 blocker = Blocker()221 def drive(n):222 nonlocal speed_before_crash223 speed_before_crash = car.speed224 if car.blocker_on_direction(n):225 keypad.car = car226 car.keypad = keypad227 keypad.update()228 car.act(n)229 car_scene.follow_car = True230 blocker.unblock()231 else:232 duration = car.act(n)233 update_car_view_rect(6, 8, 0, -3)234 keypad.pause(duration, fadeout_time=0)235 keypad.update(car)236 for n in range(9):237 keypad.set_callback(n, partial(drive, n))238 await blocker239 for n in range(9):240 keypad.set_callback(n, None)241 keypad.update()242 blocker = Blocker()243 car.crash_callback = blocker.unblock244 await next_page()245 ypos += 2246 await wait_for_text("Whoops! You crashed!", scale=0.65, lineh=.7)247 await wait_for_text("(Yes, the tutorial is rigged)", scale=0.65, lineh=1)248 if speed_before_crash > 6:249 await wait_for_text("Next time,", scale=0.65, lineh=.7)250 t = 'try'251 else:252 t = 'Always try'253 await wait_for_text(t + " to slow down before", scale=0.65, lineh=.7)254 await wait_for_text("any crashes, so you respawn", scale=0.65, lineh=.7)255 await wait_for_text("faster.", scale=0.65, lineh=1)256 await wait_for_text("But now, drive on!", scale=0.65, lineh=1)257 with open('keypad_racer.conf', 'w') as f:258 if layout is NUMPAD_LAYOUT:259 f.write('numpad')260 else:261 f.write('qwerty')262 await wait_for_text("Or restart the game", scale=0.65, lineh=.65)263 await wait_for_text("for a multiplayer race!", scale=0.65, lineh=.65)264class TutorialScene(Scene):265 default_projection = 0, 0, 10, 0266 fixed_projection = True267 def __init__(self):268 self.things = []269 self.view_rect = (-4, -8, 4, 4)270 def draw(self, view):271 view.set_view_rect(self.view_rect)272 for thing in self.things:273 thing.draw(view)274class TutorialCarScene(Scene):275 def __init__(self, car, keypad):276 self.car = car277 self.keypad = keypad...

Full Screen

Full Screen

test_bootstrap_interface.py

Source:test_bootstrap_interface.py Github

copy

Full Screen

...6 """LightweightM2M-1.1-int-07 Test the Client capability to connect the Bootstrap Server according to the8 Client Initiated Bootstrap Mode"""9 # check that client attempts to bootstrap10 assert lwm2mclient.wait_for_text("STATE_BOOTSTRAPPING")11 # Test Procedure 112 # bootstrap request is triggered by command line option13 assert lwm2mbootstrapserver.wait_for_text('Bootstrap request from "apa"\r\r\n')14 # Pass-Criteria A15 # should check for "2.04" changed but information not available at CLI.16 # Just check that we got packet (of correct size)17 assert lwm2mclient.wait_for_text("8 bytes received from")18 # check that DELETE /0 is sent and ack:ed (not in TC spec)19 assert lwm2mbootstrapserver.wait_for_text('Sending DELETE /0 to "apa" OK.')20 assert lwm2mbootstrapserver.wait_for_text("Received status 2.02 (COAP_202_DELETED)"21 " for URI /0 from endpoint apa.")22 # check that DELETE /1 is sent and ack:ed (not in TC spec)23 assert lwm2mbootstrapserver.wait_for_text('Sending DELETE /1 to "apa" OK.')24 assert lwm2mbootstrapserver.wait_for_text("Received status 2.02 (COAP_202_DELETED)"25 " for URI /1 from endpoint apa.")26 # check that bootstrap write operations are sent (not checking data)27 assert lwm2mbootstrapserver.wait_for_text('Sending WRITE /0/1 to "apa" OK.')28 # Pass-Criteria C29 # check that bootstrap server received success ACK30 assert lwm2mbootstrapserver.wait_for_text("Received status 2.04 (COAP_204_CHANGED)"31 " for URI /0/1 from endpoint apa.")32 # check that bootstrap write operations are sent (not checking data)33 assert lwm2mbootstrapserver.wait_for_text('Sending WRITE /1/1 to "apa" OK.')34 # Pass-Criteria C35 # check that bootstrap server received success ACK36 assert lwm2mbootstrapserver.wait_for_text("Received status 2.04 (COAP_204_CHANGED)"37 " for URI /1/1 from endpoint apa.")38 # Pass-Criteria D39 # check bootstrap discover ACK40 assert lwm2mbootstrapserver.wait_for_text("Received status 2.05 (COAP_205_CONTENT)"41 " for URI / from endpoint apa.")42 # Pass-Criteria E43 # check that bootstrap server receives a successful ACK for bootstrap finish44 assert lwm2mbootstrapserver.wait_for_text('Sending BOOTSTRAP FINISH to "apa" OK.')45 assert lwm2mbootstrapserver.wait_for_text("Received status 2.04 (COAP_204_CHANGED)"...

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 SeleniumBase 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