|
15 | 15 | ForgotPasswordPage,
|
16 | 16 | GenericCASPage,
|
17 | 17 | GenericInstitutionEmailLoginPage,
|
| 18 | + GenericInstitutionIDLoginPage, |
18 | 19 | GenericInstitutionLoginPage,
|
19 | 20 | GenericInstitutionUsernameLoginPage,
|
20 | 21 | InstitutionalLoginPage,
|
@@ -330,6 +331,17 @@ def test_account_disabled_page(self, driver):
|
330 | 331 | assert exception_page.status_message.text == 'Account disabled'
|
331 | 332 |
|
332 | 333 |
|
| 334 | +def try_login_page(driver, page_class): |
| 335 | + """ |
| 336 | + Helper function to try and verify a login page. |
| 337 | + Returns True if successful, otherwise False. |
| 338 | + """ |
| 339 | + try: |
| 340 | + return page_class(driver, verify=True) |
| 341 | + except (PageException, NoSuchElementException): |
| 342 | + return False |
| 343 | + |
| 344 | + |
333 | 345 | @markers.smoke_test
|
334 | 346 | @markers.core_functionality
|
335 | 347 | class TestInstitutionLoginPage:
|
@@ -415,40 +427,50 @@ def test_individual_institution_login_pages(
|
415 | 427 | not have working testing environments.
|
416 | 428 | """
|
417 | 429 | failed_list = []
|
| 430 | + |
418 | 431 | for institution in institution_list:
|
419 |
| - if institution != '-- select an institution --': |
420 |
| - institution_select = Select(institution_login_page.institution_dropdown) |
421 |
| - institution_select.select_by_visible_text(institution) |
422 |
| - institution_login_page.sign_in_button.click() |
| 432 | + # This value represents a placeholder or default option in the dropdown list, |
| 433 | + # which isn't a valid institution for testing. Avoid wrapping the rest of the loop's logic |
| 434 | + # in an additional if statement by using an early continue |
| 435 | + if institution == '-- select an institution --': |
| 436 | + continue |
| 437 | + |
| 438 | + # Select institution and click sign in |
| 439 | + Select(institution_login_page.institution_dropdown).select_by_visible_text( |
| 440 | + institution |
| 441 | + ) |
| 442 | + institution_login_page.sign_in_button.click() |
| 443 | + |
| 444 | + try: |
| 445 | + # Verify that we get to a valid login page by checking for a |
| 446 | + # password input field |
| 447 | + assert GenericInstitutionLoginPage(driver, verify=True) |
| 448 | + except PageException: |
423 | 449 | try:
|
424 |
| - # Verify that we get to a valid login page by checking for a |
425 |
| - # password input field |
426 |
| - assert GenericInstitutionLoginPage(driver, verify=True) |
427 |
| - except PageException: |
428 |
| - try: |
429 |
| - # For a small number of institutions the initial login page |
430 |
| - # first asks for just an email without the passord field. |
431 |
| - assert GenericInstitutionEmailLoginPage(driver, verify=True) |
432 |
| - except PageException: |
433 |
| - try: |
| 450 | + # Try different login page verifications |
| 451 | + if not any( |
| 452 | + [ |
| 453 | + # For a small number of institutions the initial login page |
| 454 | + # first asks for just an email without the password field. |
| 455 | + try_login_page(driver, GenericInstitutionEmailLoginPage), |
434 | 456 | # A few institutions use a login page with a generic username
|
435 |
| - # or user id text input field. The page definition checks for |
436 |
| - # a form element with methdo="post". Then check that the page |
437 |
| - # also has an input box. |
438 |
| - assert GenericInstitutionUsernameLoginPage( |
439 |
| - driver, verify=True |
440 |
| - ) |
441 |
| - driver.find_element(By.CSS_SELECTOR, 'input[type="text"]') |
442 |
| - except (PageException, NoSuchElementException): |
443 |
| - # if there is a failure add the name of the institution to the |
444 |
| - # failed list |
445 |
| - failed_list.append(institution) |
446 |
| - # Need to go back to the original OSF Institution Login page |
447 |
| - institution_login_page.goto() |
448 |
| - # If there are any failed institutions then fail the test and print the list |
449 |
| - assert len(failed_list) == 0, 'The following Institutions Failed: ' + str( |
450 |
| - failed_list |
451 |
| - ) |
| 457 | + # or user id text input field. |
| 458 | + try_login_page(driver, GenericInstitutionUsernameLoginPage), |
| 459 | + # Chicago University has autocomplete="username" |
| 460 | + try_login_page(driver, GenericInstitutionIDLoginPage), |
| 461 | + ] |
| 462 | + ): |
| 463 | + failed_list.append(institution) |
| 464 | + except Exception as e: |
| 465 | + failed_list.append(institution) |
| 466 | + |
| 467 | + # Return to the original OSF Institution Login page |
| 468 | + institution_login_page.goto() |
| 469 | + |
| 470 | + # Fail the test if there are any failed institutions and print the list |
| 471 | + assert ( |
| 472 | + len(failed_list) == 0 |
| 473 | + ), f'The following Institutions Failed: {failed_list}' |
452 | 474 |
|
453 | 475 |
|
454 | 476 | @markers.dont_run_on_prod
|
|
0 commit comments