How to use drag_to method in Playwright Python

Best Python code snippet using playwright-python

tft.py

Source:tft.py Github

copy

Full Screen

...118 for i in data.shop:119 for j in i:120 count += data.board_champ.count(j)121 return count122def drag_to(a, b):123 auto.moveTo(a, duration=random.uniform(t1, t2))124 auto.mouseDown(duration=random.uniform(t1, t2))125 auto.moveTo(b, duration=random.uniform(t1, t2))126 auto.mouseUp(duration=random.uniform(t1, t2))127def arrange_board(data):128 time.sleep(tping)129 k = -1130 kk = 0131 for i in data.shop:132 k += 1133 check = True134 for j in i[::-1]:135 if check:136 if j in data.board_champ:137 check = False138 kk += 1139 elif j in data.bench_champ:140 check = False141 kk += 1142 if count_champ(data) < data.level:143 drag_to(data.bench_pos[data.bench_champ.index(j)], data.board_pos[data.shop_champ_pos[k]])144 data.bench_champ[data.bench_champ.index(j)] = ""145 data.board_champ[data.shop_champ_pos[k]] = j146 else:147 stop = 0148 for ii in data.shop[:data.shop.index(i):-1]:149 for jj in ii:150 if data.board_champ.count(jj) == 2:151 drag_to(data.bench_pos[data.bench_champ.index(j)], data.board_pos[data.board_champ.index(jj, data.board_champ.index(jj) + 1)])152 drag_to(data.board_pos[data.board_champ.index(jj, data.board_champ.index(jj) + 1)], data.board_pos[data.shop_champ_pos[k]])153 data.bench_champ[data.bench_champ.index(j)] = jj154 data.board_champ[data.board_champ.index(jj, data.board_champ.index(jj) + 1)] = ""155 data.board_champ[data.board_pos.index(data.board_pos[data.shop_champ_pos[k]])] = j156 stop = 1157 if stop == 0:158 for ii in data.shop[:data.shop.index(i):-1]:159 for jj in ii:160 if stop == 0 and jj in data.board_champ:161 drag_to(data.bench_pos[data.bench_champ.index(j)], data.board_pos[data.board_champ.index(jj)])162 drag_to(data.board_pos[data.board_champ.index(jj)], data.board_pos[data.shop_champ_pos[k]])163 data.bench_champ[data.bench_champ.index(j)] = jj164 data.board_champ[data.board_champ.index(jj)] = ""165 data.board_champ[data.board_pos.index(data.board_pos[data.shop_champ_pos[k]])] = j166 stop = 1167 if kk == data.level:168 break169 for i in range(kk, data.level):170 for ii in range (0, len(data.bench_champ)):171 if data.bench_champ[ii] != "":172 drag_to(data.bench_pos[ii], data.board_pos[data.board_champ.index("", 25)])173 data.board_champ[data.board_champ.index("", 25)] = data.bench_champ[ii]174 data.bench_champ[ii] = ""175 break176 print(data.level)177 print(data.bench_champ, data.board_champ)178def sell_all(data, index):179 for champ in data.shop[index]:180 while champ in data.bench_champ:181 sell(data.bench_pos[data.bench_champ.index(champ)], data)182 data.bench_champ[data.bench_champ.index(champ)] = ""183 while champ in data.board_champ:184 sell(data.board_pos[data.board_champ.index(champ)], data)185 data.board_champ[data.board_champ.index(champ)] = ""186 del data.shop[index]187 del data.shop_champ_pos[index]188def bench_full(data):189 if "./captures/shen_shop.png" in data.bench_champ:190 sell(data.bench_pos[data.bench_champ.index("./captures/shen_shop.png")], data)191 data.bench_champ[data.bench_champ.index("./captures/shen_shop.png")] = ""192 elif "./captures/nidalee_shop.png" in data.bench_champ:193 sell(data.bench_pos[data.bench_champ.index("./captures/nidalee_shop.png")], data)194 data.bench_champ[data.bench_champ.index("./captures/nidalee_shop.png")] = ""195 elif "./captures/sivir_shop.png" in data.bench_champ:196 sell(data.bench_pos[data.bench_champ.index("./captures/sivir_shop.png")], data)197 data.bench_champ[data.bench_champ.index("./captures/sivir_shop.png")] = ""198 elif "./captures/yuumi_shop.png" in data.bench_champ:199 sell(data.bench_pos[data.bench_champ.index("./captures/yuumi_shop.png")], data)200 data.bench_champ[data.bench_champ.index("./captures/yuumi_shop.png")] = ""201 elif "./captures/kindred_shop.png" in data.bench_champ:202 sell(data.bench_pos[data.bench_champ.index("./captures/kindred_shop.png")], data)203 data.bench_champ[data.bench_champ.index("./captures/kindred_shop.png")] = ""204 elif "./captures/teemo_shop.png" in data.bench_champ:205 sell(data.bench_pos[data.bench_champ.index("./captures/teemo_shop.png")], data)206 data.bench_champ[data.bench_champ.index("./captures/teemo_shop.png")] = ""207 elif "./captures/diana_shop.png" in data.bench_champ:208 sell(data.bench_pos[data.bench_champ.index("./captures/diana_shop.png")], data)209 data.bench_champ[data.bench_champ.index("./captures/diana_shop.png")] = ""210 else:211 sell(data.bench_pos[8], data)212 data.bench_champ[8] = ""213def bench_manager(data, champ):214 if (data.bench_champ.count(champ[0]) + data.board_champ.count(champ[0])) <= 1:215 data.bench_champ[data.bench_champ.index("")] = champ[0]216 elif (data.bench_champ.count(champ[0]) + data.board_champ.count(champ[0])) == 2:217 if (data.bench_champ.count(champ[1]) + data.board_champ.count(champ[1])) == 2:218 if champ[1] in data.board_champ:219 if data.board_champ.count(champ[1]) == 2:220 data.board_champ[data.board_champ.index(champ[1])] = champ[2]221 data.board_champ[data.board_champ.index(champ[1])] = ""222 elif data.board_champ.count(champ[1]) == 1:223 data.board_champ[data.board_champ.index(champ[1])] = champ[2]224 data.bench_champ[data.bench_champ.index(champ[1])] = ""225 else:226 data.bench_champ[data.bench_champ.index(champ[1])] = champ[2]227 data.bench_champ[data.bench_champ.index(champ[1])] = "" 228 elif champ[0] in data.board_champ:229 if data.board_champ.count(champ[0]) == 2:230 data.board_champ[data.board_champ.index(champ[0])] = champ[1]231 data.board_champ[data.board_champ.index(champ[0])] = ""232 elif data.board_champ.count(champ[0]) == 1:233 data.board_champ[data.board_champ.index(champ[0])] = champ[1]234 data.bench_champ[data.bench_champ.index(champ[0])] = ""235 else:236 data.bench_champ[data.bench_champ.index(champ[0])] = champ[1]237 data.bench_champ[data.bench_champ.index(champ[0])] = ""238def bench_manager_chosen(data, champ):239 print("managerchamp={}".format(champ))240 if (data.bench_champ.count(champ[1]) + data.board_champ.count(champ[1])) <= 1:241 data.bench_champ[data.bench_champ.index("")] = champ[1]242 elif (data.bench_champ.count(champ[1]) + data.board_champ.count(champ[1])) == 2:243 if champ[1] in data.board_champ:244 if data.board_champ.count(champ[1]) == 2:245 data.board_champ[data.board_champ.index(champ[1])] = champ[2]246 data.board_champ[data.board_champ.index(champ[1])] = ""247 elif data.board_champ.count(champ[1]) == 1:248 data.board_champ[data.board_champ.index(champ[1])] = champ[2]249 data.bench_champ[data.bench_champ.index(champ[1])] = ""250 else:251 data.bench_champ[data.bench_champ.index(champ[1])] = champ[2]252 data.bench_champ[data.bench_champ.index(champ[1])] = ""253 for i in range(0, 2):254 if data.bench_champ.count(champ[0]) > 0:255 sell(data.bench_pos[data.bench_champ.index(champ[0])])256 data.bench_champ[data.bench_champ.index(champ[0])] = ""257 if data.board_champ.count(champ[0]) > 0:258 sell(data.board_champ[data.board_champ.index(champ[0])])259 data.board_champ[data.board_champ.index(champ[0])] = ""260def buy(data):261 time.sleep(tping)262 chosen = searcharea("./captures/chosen.png", data.shop_area[0], data.shop_area[1], data.shop_area[2], data.shop_area[3], 0.9)263 for i in data.shop:264 count = 0265 gold = True266 while gold and count < 5 and onscreenarea(i[0], data.shop_area[0], data.shop_area[1], data.shop_area[2], data.shop_area[3]) and not (i[2] in data.bench_champ or i[2] in data.board_champ):267 count += 1268 if searcharea("./captures/empty_bench_8.png", data.scan_bench_pos[8][0], data.scan_bench_pos[8][1], data.scan_bench_pos[8][2], data.scan_bench_pos[8][3], prec)[0] == -1:269 if (data.bench_champ.count(i[0]) + data.board_champ.count(i[0])) < 2:270 bench_full(data)271 pos = searcharea(i[0], data.shop_area[0], data.shop_area[1], data.shop_area[2], data.shop_area[3], prec)272 if pos[0] != -1:273 if chosen[0] != -1 and pos[0] > chosen[0] - 207 and pos[0] < chosen[0] - 142:274 if i[0] == "./captures/tristana_shop.png" or i[0] == "./captures/teemo_shop.png" or i[0] == "./captures/sivir_shop.png" or i[0] == "./captures/diana_shop.png" or i[0] == "./captures/yuumi_shop.png" or i[0] == "./captures/kindred_shop.png":275 if searcharea("./captures/chosen_sharp.png", data.shop_area[0], data.shop_area[1], data.shop_area[2], data.shop_area[3], 0.8)[0] != -1:276 auto.moveTo(pos[0] + data.shop_area[0], pos[1] + data.shop_area[1], duration=random.uniform(t1, t2))277 click_left()278 time.sleep(tping)279 if pos == searcharea(i[0], data.shop_area[0], data.shop_area[1], data.shop_area[2], data.shop_area[3], prec):280 gold = False281 print("NOGOLD")282 else:283 bench_manager_chosen(data, i)284 sell_all(data, 6)285 elif searcharea("./captures/chosen_spirit.png", data.shop_area[0], data.shop_area[1], data.shop_area[2], data.shop_area[3], 0.8)[0] != -1:286 auto.moveTo(pos[0] + data.shop_area[0], pos[1] + data.shop_area[1], duration=random.uniform(t1, t2))287 click_left()288 time.sleep(tping)289 if pos == searcharea(i[0], data.shop_area[0], data.shop_area[1], data.shop_area[2], data.shop_area[3], prec):290 gold = False291 print("NOGOLD")292 else:293 bench_manager_chosen(data, i)294 sell_all(data, 3)295 else:296 auto.moveTo(pos[0] + data.shop_area[0], pos[1] + data.shop_area[1], duration=random.uniform(t1, t2))297 click_left()298 time.sleep(tping)299 if pos == searcharea(i[0], data.shop_area[0], data.shop_area[1], data.shop_area[2], data.shop_area[3], prec):300 print("NOGOLD")301 gold = False302 else:303 bench_manager(data, i)304 auto.moveTo(data.loot_pos[0], duration=random.uniform(t1, t2))305 click_left()306def sell_loot(data):307 for i in range(0, len(data.bench_champ)):308 if data.bench_champ[i] == "":309 sell(data.bench_pos[i], data)310def search_loot(data):311 for i in data.loot_pos:312 auto.moveTo(i, duration=random.uniform(t1, t2))313 click_right()314 time.sleep(1)315 316def sell(pos, data):317 auto.moveTo(pos, duration=random.uniform(t1fast, t2fast))318 direct.press("e", _pause=False)319def spiral(data, pos, step, nb_loop):320 negx = -1321 negy = 1322 stepx = 0323 stepy = 0324 t = 0325 for i in range(0, nb_loop * 4 + 1):326 if i % 2 == 1:327 negx *= -1328 if i % 2 == 0:329 negy *= -1330 t += 0.01331 if i % 4 == 1:332 stepx += 1333 if i % 4 == 0:334 stepy += 1335 auto.moveTo(pos[0] + negx * step * stepx, pos[1] + negy * step * stepy, duration=random.uniform(t1/3, t2/3))336 click_right()337 time.sleep(t)338 auto.moveTo(data.loot_pos[0], duration=random.uniform(t1, t2))339 click_left()340 click_right()341def read_item(data):342 for i in range(0, len(data.item_bench)):343 data.item_bench[i] = ""344 for i in range(0, len(data.item_bench)):345 auto.moveTo(data.item_pos[i], duration=random.uniform(t1fast, t2fast))346 data.item_bench[i] = msearcharea(data.item, data.item_bench_area[0], data.item_bench_area[1], data.item_bench_area[2], data.item_bench_area[3], precision=prec)347 print(data.item_bench)348def put_item(data):349 for i in range(0, 5):350 if "./captures/rod.png" in data.item_bench and "./captures/chain.png" in data.item_bench and data.board_champ[4] != "":351 drag_to(data.item_pos[data.item_bench.index("./captures/rod.png")], data.board_pos[4])352 data.item_bench[data.item_bench.index("./captures/rod.png")] = ""353 drag_to(data.item_pos[data.item_bench.index("./captures/chain.png")], data.board_pos[4])354 data.item_bench[data.item_bench.index("./captures/chain.png")] = ""355 data.item_champ.append("locket")356 if not "qss" in data.item_champ and "./captures/glove.png" in data.item_bench and "./captures/negatron.png" in data.item_bench and data.board_champ[6] != "":357 drag_to(data.item_pos[data.item_bench.index("./captures/glove.png")], data.board_pos[6])358 data.item_bench[data.item_bench.index("./captures/glove.png")] = ""359 drag_to(data.item_pos[data.item_bench.index("./captures/negatron.png")], data.board_pos[6])360 data.item_bench[data.item_bench.index("./captures/negatron.png")] = ""361 data.item_champ.append("qss")362 if "./captures/belt.png" in data.item_bench and "./captures/sword.png" in data.item_bench and data.board_champ[5] != "":363 drag_to(data.item_pos[data.item_bench.index("./captures/belt.png")], data.board_pos[5])364 data.item_bench[data.item_bench.index("./captures/belt.png")] = ""365 drag_to(data.item_pos[data.item_bench.index("./captures/sword.png")], data.board_pos[5])366 data.item_bench[data.item_bench.index("./captures/sword.png")] = ""367 data.item_champ.append("zeke")368 if data.item_bench.count("./captures/sword.png") >= 2 and data.board_champ[6] != "":369 drag_to(data.item_pos[data.item_bench.index("./captures/sword.png")], data.board_pos[6])370 data.item_bench[data.item_bench.index("./captures/sword.png")] = ""371 drag_to(data.item_pos[data.item_bench.index("./captures/sword.png")], data.board_pos[6])372 data.item_bench[data.item_bench.index("./captures/sword.png")] = ""373 data.item_champ.append("db")374 if ("qss" in data.item_champ or data.item_bench.count("./captures/glove.png") >= 2) and "./captures/bow.png" in data.item_bench and data.board_champ[6] != "":375 drag_to(data.item_pos[data.item_bench.index("./captures/glove.png")], data.board_pos[6])376 data.item_bench[data.item_bench.index("./captures/glove.png")] = ""377 drag_to(data.item_pos[data.item_bench.index("./captures/bow.png")], data.board_pos[6])378 data.item_champ.append("lw")379 data.item_bench[data.item_bench.index("./captures/bow.png")] = ""380 if ("qss" in data.item_champ or data.item_bench.count("./captures/glove.png") >= 2) and "./captures/tear.png" in data.item_bench and data.board_champ[6] != "":381 drag_to(data.item_pos[data.item_bench.index("./captures/glove.png")], data.board_pos[6])382 data.item_bench[data.item_bench.index("./captures/glove.png")] = ""383 drag_to(data.item_pos[data.item_bench.index("./captures/tear.png")], data.board_pos[6])384 data.item_bench[data.item_bench.index("./captures/tear.png")] = ""385 data.item_champ.append("hoj")386def specific_routine(data, stage, substage):387 if data.check:388 data.check = False389 if substage == "./captures/stage/1-4.png":390 sell(data.board_pos[3], data)391 buy(data)392 arrange_board(data)393 if count_champ(data) < 2:394 auto.moveTo(data.shop_pos[0], duration=random.uniform(t1, t2))395 click_left()396 time.sleep(tping)397 drag_to(data.bench_pos[0], data.board_pos[21])398 auto.moveTo(data.shop_pos[1], duration=random.uniform(t1, t2))399 click_left()400 time.sleep(tping)401 drag_to(data.bench_pos[0], data.board_pos[22])402 elif substage == "./captures/stage/2-1.png":403 sell_loot(data)404 sell(data.board_pos[21], data)405 sell(data.board_pos[22], data)406 buy(data)407 arrange_board(data)408 if count_champ(data) < 3:409 auto.moveTo(data.shop_pos[0], duration=random.uniform(t1, t2))410 click_left()411 time.sleep(tping)412 drag_to(data.bench_pos[0], data.board_pos[21])413 auto.moveTo(data.shop_pos[1], duration=random.uniform(t1, t2))414 click_left()415 time.sleep(tping)416 drag_to(data.bench_pos[0], data.board_pos[22])417 auto.moveTo(data.shop_pos[2], duration=random.uniform(t1, t2))418 click_left()419 time.sleep(tping)420 drag_to(data.bench_pos[0], data.board_pos[23])421 sell_loot(data)422 elif substage == "./captures/stage/2-2.png":423 sell_loot(data)424 sell(data.board_pos[21], data)425 sell(data.board_pos[22], data)426 sell(data.board_pos[23], data)427 buy(data)428 arrange_board(data)429 elif substage == "./captures/stage/3-1.png" or substage == "./captures/stage/3-2.png":430 while not onscreen("./captures/notime.png") and not onscreenarea("./captures/no_interest_3.png", data.interest_pos[2][0], data.interest_pos[2][1], data.interest_pos[2][2], data.interest_pos[2][3]):431 buy(data)432 direct.press("d")433 buy(data)434 arrange_board(data)...

Full Screen

Full Screen

tests.py

Source:tests.py Github

copy

Full Screen

...100 assert S('a2').height == 1101 assert S('b3:c5').width == 2102 assert S('b3:c5').height == 3103def test_cell_contents_can_be_set_by_methods_which_can_be_cascaded():104 S('a1').set_value(1).drag_to('a5')105 assert S('a5').value == 5106 107 S('a1').set_string('hello').drag_to('a5')108 assert S('a5').string == 'hello'109 S('a1').value = 1110 S('a2').set_formula('=a1*2').drag_to('a5')111 assert S('a5').value == 16112 S('a1').set_date(datetime(2011, 1, 13)).drag_to('a5')113 assert S('a5').date == datetime(2011, 1, 17)114def test_drag_to():115 S('a1').value = 10116 S('a2').formula = '=a1+5'117 S('a2').drag_to('a3')118 assert S('a3').value == 20119def test_drag_to_with_cell_range():120 S('a1').value = 10121 S('a2').value = 20122 S('a3').value = 30123 S('a1:a3').drag_to('b3')124 assert S('b1').value == 11125 assert S('b2').value == 21126 assert S('b3').value == 31127def test_drag_calls_can_be_cascaded():128 S('a1').value = 1129 S('a1').drag_to('a5').drag_to('c5')130 assert S('c5').value == 7131def test_selector_handles_sheets():132 """This test requires english OpenOffice"""133 S('a1').value = 2134 S('Sheet2.a1').value = 5135 assert S('a1').value == 2136 assert S('Sheet2.a1').value == 5137 S('Sheet2.a2').value = 3138 S('Sheet2.a1:a2').drag_to('b2')139 assert S('Sheet2.b1').value == 6140 assert S('Sheet2.b2').value == 4141 S('Sheet2.a1:g10').delete()142def test_delete():143 S('a1').value = 1144 S('a1').delete()145 assert S('a1').value == 0146 assert S('a1').string == ''147 S('a1').value = 1148 S('a2').value = 1149 S('b1').value = 1150 S('b2').value = 1151 S('a1:b2').delete()152 assert S('a1').value == 0153 assert S('a1').string == ''154 assert S('a2').value == 0155 assert S('a2').string == ''156 assert S('b1').value == 0157 assert S('b1').string == ''158 assert S('b2').value == 0159 assert S('b2').string == ''160def test_last_rows_and_columns():161 assert S('a1:g10').first_row == S('A1:G1')162 assert S('a1:g10').last_row == S('A10:G10')163 assert S('a1:g10').first_column == S('A1:A10')164 assert S('a1:g10').last_column == S('G1:G10')165def test_insert_rows():166 S('a1').value = 10167 S('b2').formula = '=a1+5'168 S('b2').insert_row()169 assert S('b3').formula.lower() == '=a1+5'170 assert S('b2').value == 0171 assert S('b2').string == ''172def test_insert_row_expands_selector_and_can_be_cascaded():173 S('a1').value = 10174 S('a2').formula = '=a1+5'175 S('b1').value = 12176 S('a2').insert_row().drag_to('b3')177 assert S('b3').value == 17178def test_several_rows_can_be_inserted():179 S('a1').value = 11180 S('b2').formula = '=a1+5'181 result = S('b2').insert_rows(5)182 assert S('b7').formula.lower() == '=a1+5'183 result.value = 5184 assert S('b2').value == 5185 assert S('b4').value == 5186 assert S('b7').value == 5187 188def test_insert_column():189 S('a1').value = 10190 S('b2').formula = '=a1+5'191 S('b2').insert_column()192 assert S('c2').formula.lower() == '=a1+5'193 assert S('b2').value == 0194 assert S('b2').string == ''195def test_insert_column_expands_selector_and_can_be_cascaded():196 S('a1').value = 10197 S('b1').formula = '=a1+5'198 S('a2').value = 12199 S('b1').insert_column().drag_to('c2')200 assert S('c2').value == 17201def test_several_columns_can_be_inserted():202 S('a1').value = 11203 S('b2').formula = '=a1+5'204 result = S('b2').insert_columns(5)205 assert S('g2').formula.lower() == '=a1+5'206 result.value = 6207 assert S('b2').value == 6208 assert S('d2').value == 6209 assert S('g2').value == 6210def test_delete_rows():211 S('d5').value = 2212 S('a2').delete_rows()213 assert S('d4').value == 2214 S('a1:a3').delete_rows()215 assert S('d1').value == 2216def test_delete_columns():217 S('f5').value = 2218 S('a2').delete_columns()219 assert S('e5').value == 2220 S('a1:d1').delete_columns()221 assert S('a5').value == 2222def test_copy_cut_and_paste():223 S('a1').value = 4224 S('a1').copy()225 S('b2').paste()226 assert S('a1').value == 4227 assert S('b2').value == 4228 S('a1').cut()229 S('c1').paste()230 assert S('a1').value == 0231 assert S('c1').value == 4232def test_copy_cut_and_paste_can_be_cascaded():233 S('a1').set_value(12).copy().set_value(15).shift_right().paste().shift_down().set_value(18).cut().shift_left().paste()234 assert S('a1').value == 15235 assert S('b1').value == 12236 assert S('b2').value == 0237 assert S('a2').value == 18238def test_delete():239 S('a1').value = 10240 S('a1').delete()241 assert S('a1').value == 0242 S('a1').string = 'hello'243 S('a1').delete()244 assert S('a1').string == ''245def test_undo_redo():246 S('a1').value = 1247 S('a1').value = 2248 S('a1').value = 3249 S('a1').value = 4250 S('a1').value = 5251 S().undo()252 assert S('a1').value == 4253 S().undo()254 S().undo()255 assert S('a1').value == 2256 S().redo()257 assert S('a1').value == 3258 S().redo()259 assert S('a1').value == 4260 S().undo()261 assert S('a1').value == 3262def test_save_as():263 filename = '/tmp/test_oosheet.ods'264 assert not os.path.exists(filename)265 S().save_as(filename)266 assert os.path.exists(filename)267 os.remove(filename)268def test_shift_until_works_for_single_cell_with_value_as_parameter():269 S('g10').string = 'total'270 assert S('g1').shift_down_until('total') == S('G10')271 assert S('g20').shift_up_until('total') == S('G10')272 assert S('a10').shift_right_until('total') == S('G10')273 assert S('z10').shift_left_until('total') == S('G10')274 S('g10').value = 18275 assert S('g1').shift_down_until(18) == S('G10')276 S('g10').value = 18.5277 assert S('g1').shift_down_until(18.5) == S('G10')278 date = datetime(2011, 1, 20)279 S('g10').date = date280 assert S('g1').shift_down_until(date) == S('G10')281def test_shift_until_works_with_conditions_for_one_dimension_selectors():282 date = datetime(2011, 1, 20)283 S('c10').string = 'total'284 S('d11').value = 19285 S('e12').value = 19.5286 S('f13').date = date287 S('c14').value = 20288 assert S('a1:z1').shift_down_until(column_c = 'total') == S('A10:Z10')289 assert S('a1:z1').shift_down_until(column_d = 19) == S('A11:Z11')290 assert S('a1:z1').shift_down_until(column_e = 19.5) == S('A12:Z12')291 assert S('a1:z1').shift_down_until(column_f = date) == S('A13:Z13')292 assert S('a1:z1').shift_down_until(column_c = 20) == S('A14:Z14')293 assert S('a30:z30').shift_up_until(column_c = 'total') == S('A10:Z10')294 assert S('a1:a30').shift_right_until(row_11 = 19) == S('D1:D30')295 assert S('z1:z30').shift_left_until(row_12 = 19.5) == S('E1:E30')296def test_shift_until_works_with_conditions_for_two_dimension_selectors():297 date = datetime(2011, 1, 20)298 S('c10').string = 'total'299 S('d11').value = 19300 S('e12').value = 19.5301 S('f13').date = date302 S('c14').value = 20303 assert S('a1:z2').shift_down_until(column_c = 'total') == S('A9:Z10')304 assert S('a1:z2').shift_down_until(column_d = 19) == S('A10:Z11')305 assert S('a1:z2').shift_down_until(column_e = 19.5) == S('A11:Z12')306 assert S('a1:z2').shift_down_until(column_f = date) == S('A12:Z13')307 assert S('a1:z4').shift_down_until(column_c = 20) == S('A11:Z14')308 assert S('a20:z30').shift_up_until(column_c = 'total') == S('A10:Z20')309 assert S('a1:c30').shift_right_until(row_11 = 19) == S('B1:D30')310 assert S('x1:z30').shift_left_until(row_12 = 19.5) == S('E1:G30')311def test_shift_until_handles_unicode_properly():312 S('c10').string = u'fué'313 assert S('a1:d1').shift_down_until(column_c = u'fué') == S('A10:D10')314def test_shift_until_accepts_lambda_to_test_condition():315 S('f10').string = 'some stuff'316 S('g10').string = 'one string'317 S('h11').string = 'another string'318 S('h12').string = 'another stuff'319 assert S('a1:z1').shift_down_until(column_g_satisfies = lambda c: c.string.endswith('string')) == S('A10:Z10')320 assert S('a1:z2').shift_down_until(column_h_satisfies = lambda c: c.string.startswith('another')) == S('A10:Z11')321 assert S('a1:z2').shift_down_until(column_h_satisfies = lambda c: c.string.endswith('stuff')) == S('A11:Z12')322 assert S('a1:a20').shift_right_until(row_10_satisfies = lambda c: c.string.endswith('string')) == S('G1:G20')323def test_shift_until_accepts_none_for_empty_cell():324 S('a1').set_value(1).drag_to('g1').drag_to('g10')325 S('g10').delete()326 assert S('b1').shift_right_until(row_1 = None) == S('H1')327 assert S('b1').shift_down_until(column_b = None) == S('B11')328 assert S('b1:5').shift_down_until(column_c = None) == S('B7:B11')329 assert S('b1:5').shift_right_until(row_2 = None) == S('H1:H5')330 assert S('a2:z2').shift_down_until(column_f = None) == S('A11:Z11')331 assert S('a2:z2').shift_down_until(column_g = None) == S('A10:Z10')332def test_shift_right():333 S('a1').set_value(1).drag_to('a10').drag_to('f10')334 S('c1').set_value(100).drag_to('c10')335 S('b1:b5').shift_right().drag_to('d5')336 assert S('d3').value == 103337 S('a6:a10').shift_right(2).drag_to('d10')338 assert S('d7').value == 107339def test_shift_left():340 S('a1').set_value(1).drag_to('a10').drag_to('f10')341 S('c1').set_value(102).drag_to('c10')342 S('d1:d5').shift_left().drag_to('b5')343 assert S('b3').value == 103344 S('e6:e10').shift_left(2).drag_to('b10')345 assert S('b7').value == 107346def test_shift_down():347 S('a1').set_value(1).drag_to('a10').drag_to('g10')348 S('a4').set_value(100).drag_to('g4')349 S('a3:d3').shift_down().drag_to('d5')350 assert S('c5').value == 103351 S('e2:g2').shift_down(2).drag_to('g5')352 assert S('f5').value == 106353def test_shift_up():354 S('a1').set_value(1).drag_to('a10').drag_to('g10')355 S('a4').set_value(102).drag_to('g4')356 S('a5:d5').shift_up().drag_to('d3')357 assert S('c3').value == 103358 S('e6:g6').shift_up(2).drag_to('g3')359 assert S('f3').value == 106360def test_shifting_works_with_cell_contents():361 S('a1').set_value(10).shift_right().set_value(12).shift_down().set_value(15).shift_left().set_value(17)362 assert S('a2').value == 17363def test_shifting_can_be_done_with_arithmetic_operations():364 assert S('a1') + (1, 0) == S('B1')365 assert S('a1') + (0, 1) == S('A2')366 assert S('a1') + (2, 3) == S('C4')367 assert S('a1:b5') + (3, 4) == S('D5:E9')368 assert S('b1') - (1, 0) == S('A1')369 assert S('a2') - (0, 1) == S('A1')370 assert S('c4') - (2, 3) == S('A1')371 assert S('d5:e9') - (3, 4) == S('A1:B5')372def test_difference_between_two_selectors_can_be_calculated_with_subtraction():373 assert S('b4') - S('b3') == (0, 1)374 assert S('b3') - S('b4') == (0, -1)375 assert S('c5') - S('a5') == (2, 0)376 assert S('a5') - S('c5') == (-2, 0)377 assert S('c5') - S('a2') == (2, 3)378 assert S('a2') - S('c5') == (-2, -3)379 assert S('c5:d6') - S('a2:b3') == (2, 3)380def test_selector_can_be_expanded():381 assert S('d4').grow_right() == S('D4:E4')382 assert S('d4').grow_right(2) == S('D4:F4')383 assert S('d4').grow_left() == S('C4:D4')384 assert S('d4').grow_left(2) == S('B4:D4')385 assert S('d4').grow_down() == S('D4:D5')386 assert S('d4').grow_down(2) == S('D4:D6')387 assert S('d4').grow_up() == S('D3:D4')388 assert S('d4').grow_up(2) == S('D2:D4')389 assert S('d4:e5').grow_right(2).grow_left(2).grow_down(2).grow_up(2) == S('B2:G7')390def test_grow_until():391 S('a1').set_value(5).drag_to('a10').drag_to('g10')392 assert S('b3').grow_down_until(column_c = 15) == S('B3:B9')393 assert S('b3').grow_down_until(column_d_satisfies = lambda s: s.value > 14) == S('B3:B8')394 assert S('c4').grow_down_until(column_b = None) == S('C4:C11')395 assert S('b2:d2').grow_down_until(column_a = 11) == S('B2:D7')396 assert S('b2:b3').grow_down_until(column_a = 11) == S('B2:B7')397 assert S('e9').grow_up_until(column_c = 8) == S('E2:E9')398 assert S('e9:f10').grow_up_until(column_a_satisfies = lambda s: s.value < 6) == S('E1:F10')399 assert S('a3:b4').grow_right_until(row_3_satisfies = lambda s: s.value > 11) == S('A3:F4')400 assert S('f4:g5').grow_left_until(row_3_satisfies = lambda s:s.value < 9) == S('B4:G5') 401def test_shrink_until():402 S('a1').set_value(5).drag_to('a10').drag_to('g10')403 assert S('b2:f9').shrink_down_until(column_f = 13) == S('B2:F4')404 assert S('b2:f9').shrink_up_until(column_e_satisfies = lambda s: s.value > 13) == S('B6:F9')405 assert S('b2:f9').shrink_left_until(row_9 = 16) == S('D2:F9')406 assert S('b2:f9').shrink_right_until(row_9 = 16) == S('B2:D9')407def test_selector_can_be_reduced():408 assert S('b2:g7').shrink_right() == S('B2:F7')409 assert S('b2:g7').shrink_right(2) == S('B2:E7')410 assert S('b2:g7').shrink_left() == S('C2:G7')411 assert S('b2:g7').shrink_left(2) == S('D2:G7')412 assert S('b2:g7').shrink_down() == S('B2:G6')413 assert S('b2:g7').shrink_down(2) == S('B2:G5')414 assert S('b2:g7').shrink_up() == S('B3:G7')415 assert S('b2:g7').shrink_up(2) == S('B4:G7')416 assert S('B2:G7').shrink_right(2).shrink_left(2).shrink_down(2).shrink_up(2) == S('D4:E5')417def test_object_can_be_cloned():418 start = S('a1')419 end = S('a1').clone().shift_right()420 assert start == S('a1')421 assert end == S('b1')422def test_flatten():423 S('a1').value = 5424 S('a2').formula = '=a1+3'425 S('a2').flatten()426 S('a1').value = 10427 assert S('a2').value == 8428 S('a2').formula = '=a1+3'429 S('a2').drag_to('a10')430 431 S('a1:a10').flatten()432 S('a1').value = 0433 assert S('a2').value == 13434 assert S('a6').value == 25435 assert S('a10').value == 37436def test_flatten_works_with_string():437 S('a1').string = 'Hello World'438 S('a2').formula = u'=SUBSTITUTE(A1; "World"; "Moon")'439 S('a2').flatten()440 S('a1').string = 'asdf'441 assert S('a2').string == "Hello Moon"442def test_flatten_works_with_zero_formatted_as_string():443 S('a1').value = 0444 S('a2').value = 10445 S('a3').formula = '=a1+a2'446 S().sheet.getCellRangeByName('Sheet1.A1:A3').NumberFormat = 105 # $0.--447 string = S('a3').string448 S('a1').flatten()449 assert S('a3').string == string 450def test_protection():451 S('a1').unprotect()452 S('a2').protect()453 S('a2').protect_sheet()454 S('a1').value = 11455 456 S('a1').drag_to('a10')457 # cannot run over a protected cell458 459 assert S('a10').value == 0460 S('a1').unprotect_sheet()461 S('a1').set_value(1).drag_to('a10')462 assert S('a2').value == 2463 assert S('a10').value == 10464 S('a2').unprotect()465def test_protection_can_be_cascaded():466 S('a1').unprotect_sheet().unprotect().set_value(2)467 assert S('a1').value == 2468 S('b1').unprotect()469 S('a1').protect_sheet().protect().shift_right().set_value(3)470 S('a1').unprotect_sheet().unprotect()471 assert S('b1').value == 3472def test_sheet_protection_supports_password():473 S('a1').unprotect()474 S('a2').value = 5475 476 S('a1').set_value(10).drag_to('a3')477 assert S('a2').value == 11478 479 S('a2').protect().protect_sheet("secretpassword")480 S('a1').set_value(20).drag_to('a3')481 assert S('a2').value == 11482 try:483 S('a2').unprotect_sheet()484 except:485 pass486 487 S('a1').set_value(30).drag_to('a3')488 assert S('a2').value == 11489 490 S('a2').unprotect_sheet("secretpassword")491 S('a1').set_value(40).drag_to('a3')492 assert S('a2').value == 41493def test_user_selection():494 S('a1').focus()495 assert S().selector == 'Sheet1.A1'496 S('b2:g10').focus()497 assert S().selector == 'Sheet1.B2:G10'498 S('Sheet2.b2:g10').focus()499 assert S().selector == 'Sheet2.B2:G10'500def test_format_as():501 S().sheet.getCellRangeByName('Sheet1.A1').NumberFormat = 38502 S('a1').date = datetime(2011, 3, 1)503 S('a2:3').date = datetime(2011, 3, 8)504 weekday = S('a1').string.split()[0] #probably "wednesday", but might be localized505 S('a2').format_as('a1')506 assert S('a2').string.split()[0] == weekday507 S('a3').format_as(S('a1'))508 assert S('a3').string.split()[0] == weekday509def test_data_array():510 S('a1').value = 1511 S('a2').formula = '=a1 * 2'512 S('b1').formula = '=a1 * 1.5'513 S('a2').drag_to('a7')514 S('b1').drag_to('b7')515 S('b1:b7').drag_to('d7')516 assert len(S('a1:7').data_array) == 7517 assert len(S('a1:7').data_array[1]) == 1518 assert S('a1:7').data_array[2] == (4,)519 assert len(S('a1:c7').data_array[1]) == 3520 assert S('a1:d7').data_array[5][1] == 48521def test_iterator():522 for cell in S('a1:10'):523 cell.value = 31524 for cell in S('b1:c10'):525 cell.value = 32526 assert S('a1').value == 31527 assert S('a2').value == 31528 assert S('a3').value == 31529 assert S('a4').value == 31...

Full Screen

Full Screen

CreateAvatar.py

Source:CreateAvatar.py Github

copy

Full Screen

...71 start = self.poco("ContentGrid").child(72 "CatalogItemDisplayMobile(Clone)")[12].child("Background")73 stop = self.poco("ContentGrid").child(74 "CatalogItemDisplayMobile(Clone)")[22].child("Background")75 start.drag_to(stop)76 def setUp(self):77 self.poco = UnityPoco()78 print("Checking for change...")79 AvatarHead = Template(self.R('res/img/default-avatar.jpg'),80 rgb=True, threshold=0.9)81 AvatarMenu = Template(self.R('res/img/default.jpg'), rgb=True,82 threshold=0.9)83 if not exists(AvatarMenu) or not exists(AvatarHead):84 try:85 self.poco("ColorToggle").click()86 except InvalidOperationException:87 nav_bar = self.poco("SalonNavbarMobile(Clone)")88 print("Scrolling nav bar...")89 nav_bar.focus([0.5, 0.2]).drag_to(nav_bar.focus([0.5, 0.8]))90 nav_bar.focus([0.5, 0.2]).drag_to(nav_bar.focus([0.5, 0.8]))91 nav_bar.focus([0.5, 0.2]).drag_to(nav_bar.focus([0.5, 0.8]))92 self.poco("ColorToggle").click()93 finally:94 self.poco("SkinToggle").click()95 self.colorToggleScrollUp()96 self.poco("ContentGrid").child("CatalogItemDisplayMobile(Clone)")[97 2].child("Background").click()98 self.poco("HairToggle").click()99 self.poco("ContentGrid").child("CatalogItemDisplayMobile(Clone)")[100 5].child("Background").click()101#--------------------------------------------------------------------#102# TEST CASES #103#--------------------------------------------------------------------#104# Tests zoom in/zoom out button and a simple color change for hair and skin105class SimpleTest(AvatarCustomizationCase):106 def runTest(self):107 AvatarMenu = Template(self.R('res/img/default.jpg'), rgb=True)108 wait(AvatarMenu)109 print('Loaded into avatar customization')110 self.poco("ZoomInButton").child("Button").click()111 self.poco("ZoomOutButton").child("Button").click()112 self.poco("OptionsButton").click()113 self.assertTrue(114 exists(Template(self.R('res/img/options.jpg'))), "Failed to enter optionsmenu")115 self.poco("exit_container").click()116 self.poco("SkinToggle").click()117 start = self.poco("ContentGrid").child(118 "CatalogItemDisplayMobile(Clone)")[12].child("Background")119 stop = self.poco("ContentGrid").child(120 "CatalogItemDisplayMobile(Clone)")[2].child("Background")121 start.drag_to(stop)122 self.poco("ContentGrid").child("CatalogItemDisplayMobile(Clone)")[123 23].child("Background").click()124 self.poco("HairToggle").click()125 self.poco("ContentGrid").child("CatalogItemDisplayMobile(Clone)")[126 23].child("Background").click()127 ChangedAvatar = Template(self.R('res/img/endresult.jpg'))128 self.assertTrue(exists(ChangedAvatar), 'Test failed')129# Full skin and hair color toggle test130# Set recapture to true to recapture screenshots used to assert changes131class ColorToggleTest(AvatarCustomizationCase):132 def helper(self, toggle, scroll=False, recapture=True):133 self.poco(toggle).click()134 content_grid = self.poco("ContentGrid").children()135 if scroll:136 self.colorToggleScrollUp()137 index = 1138 for catalog_items in content_grid:139 try:140 catalog_items.child("Background").click()141 except InvalidOperationException:142 start = self.poco("ContentGrid").child(143 "CatalogItemDisplayMobile(Clone)")[12].child("Background")144 stop = self.poco("ContentGrid").child(145 "CatalogItemDisplayMobile(Clone)")[2].child("Background")146 start.drag_to(stop)147 catalog_items.child("Background").click()148 finally:149 if recapture:150 snapshot("../../res/img/AvatarInitial/ColorToggle/" +151 toggle + "/" + str(index) + ".jpg")152 with self.subTest(item=toggle + str(index)):153 self.assertTrue(exists(Template(self.R(154 "res/img/AvatarInitial/ColorToggle/" + toggle + "/" + str(index) + ".jpg"), rgb=True, threshold=0.9)), toggle + str(index) + " not found")155 index += 1156 def runTest(self):157 self.helper("SkinToggle")158 self.helper("HairToggle", scroll=True)159# Full navigation bar and content test160# Set recapture to true to recapture screenshots used to assert changes161class SelectionTest(AvatarCustomizationCase):162 def helper(self, recapture=True):163 nav_bar = self.poco("SalonNavbarMobile(Clone)")164 nav_bar_children = self.poco("ToggleGroup").children()165 for toggle in nav_bar_children:166 name = toggle.get_name()167 if name != "Margin" and name != "ColorToggle":168 try:169 print("Testing... " + name)170 self.poco(name).click()171 except InvalidOperationException:172 print("Scrolling nav bar...")173 nav_bar.focus([0.5, 0.8]).drag_to(174 nav_bar.focus([0.5, 0.2]))175 self.poco(name).click()176 finally:177 if self.poco("ContentGrid").exists():178 content_grid = self.poco("ContentGrid")179 content_grid_children = content_grid.children()180 index = 1181 for catalog_items in content_grid_children:182 try:183 catalog_items.child("Background").click()184 except InvalidOperationException:185 print('Scrolling...')186 content_grid.focus([0.5, 0.8]).drag_to(187 content_grid.focus([0.5, 0.2]))188 catalog_items.child("Background").click()189 finally:190 if recapture:191 snapshot("../../res/img/AvatarInitial/" +192 name + "/" + str(index) + ".jpg")193 with self.subTest(item=name + str(index)):194 self.assertTrue(exists(Template(self.R(195 "res/img/AvatarInitial/" + name + "/" + str(index) + ".jpg"), rgb=True, threshold=0.9)), name + str(index) + " not found")196 index += 1197 def runTest(self):198 self.helper()199# Tests the randomize button and discard changes screen200class RandomizeTest(AvatarCustomizationCase):...

Full Screen

Full Screen

Location.py

Source:Location.py Github

copy

Full Screen

...104 logger.debug('scroll in ({x}, {y}) {count} times, {dir_} direction'.format(105 x=self.x, y=self.y, count=count,106 dir_='forward' if direction == 1 else 'backward'))107108 def drag_to(self, *dest_location):109110 delay = DRAGnDROP_MOVE_DELAY111 if len(dest_location) == 1 and isinstance(dest_location[0], Location):112 (dest_x, dest_y) = (dest_location[0].x, dest_location[0].y)113 elif len(dest_location) == 2:114 try:115 (dest_x, dest_y) = (int(dest_location[0]), int(dest_location[1]))116 except ValueError:117 raise FailExit('Location.drag_to: incorrect parameters')118 elif len(dest_location) == 3:119 try:120 (dest_x, dest_y) = (int(dest_location[0]), int(dest_location[1]))121 except ValueError:122 raise FailExit('Location.drag_to: incorrect parameters')123 delay = float(dest_location[2])124125 else:126 raise FailExit('')127128 self.mouse.drag_to(self.x, self.y, dest_x, dest_y, delay)129 logger.debug('Mouse drag from (%i, %i) to (%i, %i)' %130 (self.x, self.y, dest_x, dest_y))131 return self132133 def drop(self):134 self.mouse.drop()135 logger.debug('Mouse drop')136137 def dragndrop(self, *dest_location):138 self.drag_to(*dest_location)139 self.drop()140 return self141142 def type(self, text, modifiers=None, click=True, click_type_delay=DELAY_BETWEEN_CLICK_AND_TYPE):143 log = 'Typed "{}"'.format(text)144 log += ' with modifiers "{}"'.format(modifiers) if modifiers is not None else ''145 if click:146 self.click(after_click_delay=click_type_delay)147 self.keyboard.type_text(str(text), modifiers)148 logger.info(log)149150 def enter_text(self, text, modifiers=None, click=True,151 click_type_delay=DELAY_BETWEEN_CLICK_AND_TYPE):152 if click: ...

Full Screen

Full Screen

Playwright tutorial

LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.

Chapters:

  1. What is Playwright : Playwright is comparatively new but has gained good popularity. Get to know some history of the Playwright with some interesting facts connected with it.
  2. How To Install Playwright : Learn in detail about what basic configuration and dependencies are required for installing Playwright and run a test. Get a step-by-step direction for installing the Playwright automation framework.
  3. Playwright Futuristic Features: Launched in 2020, Playwright gained huge popularity quickly because of some obliging features such as Playwright Test Generator and Inspector, Playwright Reporter, Playwright auto-waiting mechanism and etc. Read up on those features to master Playwright testing.
  4. What is Component Testing: Component testing in Playwright is a unique feature that allows a tester to test a single component of a web application without integrating them with other elements. Learn how to perform Component testing on the Playwright automation framework.
  5. Inputs And Buttons In Playwright: Every website has Input boxes and buttons; learn about testing inputs and buttons with different scenarios and examples.
  6. Functions and Selectors in Playwright: Learn how to launch the Chromium browser with Playwright. Also, gain a better understanding of some important functions like “BrowserContext,” which allows you to run multiple browser sessions, and “newPage” which interacts with a page.
  7. Handling Alerts and Dropdowns in Playwright : Playwright interact with different types of alerts and pop-ups, such as simple, confirmation, and prompt, and different types of dropdowns, such as single selector and multi-selector get your hands-on with handling alerts and dropdown in Playright testing.
  8. Playwright vs Puppeteer: Get to know about the difference between two testing frameworks and how they are different than one another, which browsers they support, and what features they provide.
  9. Run Playwright Tests on LambdaTest: Playwright testing with LambdaTest leverages test performance to the utmost. You can run multiple Playwright tests in Parallel with the LammbdaTest test cloud. Get a step-by-step guide to run your Playwright test on the LambdaTest platform.
  10. Playwright Python Tutorial: Playwright automation framework support all major languages such as Python, JavaScript, TypeScript, .NET and etc. However, there are various advantages to Python end-to-end testing with Playwright because of its versatile utility. Get the hang of Playwright python testing with this chapter.
  11. Playwright End To End Testing Tutorial: Get your hands on with Playwright end-to-end testing and learn to use some exciting features such as TraceViewer, Debugging, Networking, Component testing, Visual testing, and many more.
  12. Playwright Video Tutorial: Watch the video tutorials on Playwright testing from experts and get a consecutive in-depth explanation of Playwright automation testing.

Run Playwright Python 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