|
| 1 | +import logging |
| 2 | + |
| 3 | +from config.constants import * |
| 4 | +from pages.adminPage import AdminPage |
| 5 | +from pages.webUserPage import WebUserPage |
| 6 | + |
| 7 | +logger = logging.getLogger(__name__) |
| 8 | + |
| 9 | + |
| 10 | +def test_golden_path_web_page_demo_script(login_logout): |
| 11 | + """Validate Golden path test case for Chat with your Data""" |
| 12 | + page = login_logout |
| 13 | + page.goto(ADMIN_URL) |
| 14 | + logger.info("Step 1: Validate Admin page is loaded.") |
| 15 | + admin_page = AdminPage(page) |
| 16 | + assert ( |
| 17 | + admin_page_title == page.locator(admin_page.ADMIN_PAGE_TITLE).text_content() |
| 18 | + ), "page title not found" |
| 19 | + logger.info("Step 2: Validate Files are uploaded or not") |
| 20 | + admin_page.click_delete_data_tab() |
| 21 | + assert ( |
| 22 | + page.locator(admin_page.DELETE_CHECK_BOXES).count() >= 1 |
| 23 | + ), "Files are not uploaded." |
| 24 | + logger.info("Step 3: Validate Web page is loaded.") |
| 25 | + page.goto(WEB_URL) |
| 26 | + home_page = WebUserPage(page) |
| 27 | + logger.info("Step 5: Validate Chat history has been deleted.") |
| 28 | + home_page.delete_chat_history() |
| 29 | + |
| 30 | + failed_questions = [] |
| 31 | + logger.info("Step 6: Validate Golden Path prompts response") |
| 32 | + |
| 33 | + def ask_question_and_check(question, attempt): |
| 34 | + home_page.wait_for_load(4000) |
| 35 | + home_page.enter_a_question(question) |
| 36 | + home_page.click_send_button() |
| 37 | + home_page.validate_response_status(question) |
| 38 | + |
| 39 | + response_text = page.locator(home_page.ANSWER_TEXT) |
| 40 | + response_count = response_text.count() |
| 41 | + |
| 42 | + if response_count == 0: |
| 43 | + return False # no response found |
| 44 | + |
| 45 | + response_text_content = response_text.nth(response_count - 1).text_content() |
| 46 | + |
| 47 | + if response_text_content == invalid_response: |
| 48 | + print(f"[Attempt {attempt}] Invalid response for prompt: {question}") |
| 49 | + return False |
| 50 | + return True |
| 51 | + |
| 52 | + # First run through all questions |
| 53 | + for question in questions: |
| 54 | + if not ask_question_and_check(question, attempt=1): |
| 55 | + failed_questions.append(question) |
| 56 | + |
| 57 | + # Retry failed questions once more |
| 58 | + if failed_questions: |
| 59 | + logger.info("Step 7: Retry failed question one more time.") |
| 60 | + for question in failed_questions: |
| 61 | + if not ask_question_and_check(question, attempt=2): |
| 62 | + home_page.soft_assert( |
| 63 | + False, |
| 64 | + f"Failed after retry- Invalid response for prompt: {question}", |
| 65 | + ) |
| 66 | + |
| 67 | + logger.info("Step 8: Validate chat history.") |
| 68 | + home_page.show_chat_history() |
| 69 | + logger.info("Step 9: Validate chat history closed.") |
| 70 | + home_page.close_chat_history() |
| 71 | + home_page.assert_all() |
0 commit comments