from lib_python import execution, steps, variables
from lib_python.baseObjects.AppiumObject import AppiumObject


def check_dialog_title(params):
    expected_dialog_title = params["dialog_title"]

    dialog_text_view = AppiumObject(variables.driver, "alertTitle")
    dialog_text_view.wait_for(30)

    found_dialog_title = dialog_text_view.get_text()

    if expected_dialog_title == found_dialog_title:
        execution.passed()
    else:
        execution.error("Expected dialog title: {0}, but found {1} instead.".format(expected_dialog_title, found_dialog_title))

steps.new_step("Dialog - Check that dialog title shows: {dialog_title}", check_dialog_title)


def check_dialog_message(params):
    expected_dialog_message = params["dialog_message"]

    dialog_text_view = AppiumObject(variables.driver, "android:id/message")
    dialog_text_view.wait_for(30)

    found_dialog_message = dialog_text_view.get_text()

    if expected_dialog_message == found_dialog_message:
        execution.passed()
    else:
        execution.error("Expected dialog message: {0}, but found {1} instead.".format(expected_dialog_message, found_dialog_message))

steps.new_step("Dialog - Check that dialog message shows: {dialog_message}", check_dialog_message)
