Verify if the action has succeeded
(
browser, action, track, username, person, person_id, logger, logfolder
)
| 1498 | |
| 1499 | |
| 1500 | def verify_action( |
| 1501 | browser, action, track, username, person, person_id, logger, logfolder |
| 1502 | ): |
| 1503 | """Verify if the action has succeeded""" |
| 1504 | # currently supported actions are follow & unfollow |
| 1505 | |
| 1506 | retry_count = 0 |
| 1507 | post_action_text_fail = None |
| 1508 | post_action_text_correct = None |
| 1509 | |
| 1510 | if action in ["follow", "unfollow"]: |
| 1511 | |
| 1512 | # assuming button_change testing is relevant to those actions only |
| 1513 | button_change = False |
| 1514 | |
| 1515 | if action == "follow": |
| 1516 | post_action_text_correct = ["Following", "Requested", "Message"] |
| 1517 | post_action_text_fail = ["Follow", "Follow Back", "Unblock"] |
| 1518 | |
| 1519 | elif action == "unfollow": |
| 1520 | post_action_text_correct = ["Follow", "Follow Back", "Unblock"] |
| 1521 | post_action_text_fail = ["Following", "Requested", "Message"] |
| 1522 | |
| 1523 | while True: |
| 1524 | |
| 1525 | # count retries at beginning |
| 1526 | retry_count += 1 |
| 1527 | |
| 1528 | # find out CURRENT follow status (this is safe as the follow button is before others) |
| 1529 | following_status, follow_button = get_following_status( |
| 1530 | browser, track, username, person, person_id, logger, logfolder |
| 1531 | ) |
| 1532 | if following_status in post_action_text_correct: |
| 1533 | button_change = True |
| 1534 | elif following_status in post_action_text_fail: |
| 1535 | button_change = False |
| 1536 | else: |
| 1537 | logger.error( |
| 1538 | "Hey! Last {} is not verified out of an unexpected " |
| 1539 | "failure!".format(action) |
| 1540 | ) |
| 1541 | return False, "unexpected" |
| 1542 | |
| 1543 | if button_change: |
| 1544 | break |
| 1545 | else: |
| 1546 | if retry_count == 1: |
| 1547 | reload_webpage(browser) |
| 1548 | sleep(4) |
| 1549 | |
| 1550 | elif retry_count == 2: |
| 1551 | # handle it! |
| 1552 | # try to do the action one more time! |
| 1553 | click_visibly(browser, follow_button) |
| 1554 | |
| 1555 | if action == "unfollow": |
| 1556 | confirm_unfollow(browser) |
| 1557 |
no test coverage detected