from selenium.webdriver.common.by import By
from src.testproject.classes import DriverStepSettings, StepSettings
from src.testproject.decorator import report_assertion_errors
from src.testproject.enums import SleepTimingType
from src.testproject.sdk.drivers import webdriver
import pytest


"""
This pytest test was automatically generated by TestProject
    Project: Cristian Yesid Padilla Perea's first project
    Package: TestProject.Generated.Tests.CristianYesidPadillaPereasFirstProject
    Test: Ourshop register
    Generated by: Diego Alejandro Correa Diaz (dacorread05@gmail.com)
    Generated on 10/13/2021, 15:45:28
"""


@pytest.fixture()
def driver():
    driver = webdriver.Chrome(token="o8v_X93IdHO0IUPn0YdA3-MefybVO_j1d-rJd7FumiQ",
                              project_name="Cristian Yesid Padilla Perea's first project",
                              job_name="Ourshop register")
    step_settings = StepSettings(timeout=15000,
                                 sleep_time=500,
                                 sleep_timing_type=SleepTimingType.Before)
    with DriverStepSettings(driver, step_settings):
        yield driver
    driver.quit()


@report_assertion_errors
def test_main(driver):
    # Test Parameters
    # Auto generated application URL parameter
    ApplicationURL = "http://localhost:8100/home"
    name = "Esteban"
    email = "jemunoz84@ucatolica.edu.co"
    lastname = "munoz"
    nickname = "jemunoz84"
    address = "usmekistan"
    password = "123456"
    confirmPassword = "123456"

    # 1. Navigate to '{ApplicationURL}'
    # Navigates the specified URL (Auto-generated)
    driver.get(f'{ApplicationURL}')

    # 2. Click 'Sign Up'
    sign_up = driver.find_element(By.XPATH,
                                  "//ion-button[. = 'Sign Up']")
    sign_up.click()

    # 3. Click 'name'
    name = driver.find_element(By.XPATH,
                               "//input[@placeholder = 'Nombre']")
    name.click()

    # 4. Type '{name}' in 'name'
    name = driver.find_element(By.XPATH,
                               "//input[@placeholder = 'Nombre']")
    name.send_keys(f'{name}')

    # 5. Type '{lastname}' in 'lastName'
    lastname = driver.find_element(By.XPATH,
                                   "//input[@placeholder = 'Apellido']")
    lastname.send_keys(f'{lastname}')

    # 6. Click 'nickName'
    nickname = driver.find_element(By.XPATH,
                                   "//input[@placeholder = 'Nombre de Usuario']")
    nickname.click()

    # 7. Type '
    # {nickname}' in 'nickName'
    nickname = driver.find_element(By.XPATH,
                                   "//input[@placeholder = 'Nombre de Usuario']")
    nickname.send_keys(f'\n{nickname}')

    # 8. Click 'address'
    address = driver.find_element(By.XPATH,
                                  "//input[@placeholder = 'Dirección']")
    address.click()

    # 9. Type '{address}' in 'address'
    address = driver.find_element(By.XPATH,
                                  "//input[@placeholder = 'Dirección']")
    address.send_keys(f'{address}')

    # 10. Click 'email'
    email = driver.find_element(By.XPATH,
                                "//input[@placeholder = 'Email']")
    email.click()

    # 11. Type '{email}' in 'email'
    email = driver.find_element(By.XPATH,
                                "//input[@placeholder = 'Email']")
    email.send_keys(f'{email}')

    # 12. Click 'password'
    password = driver.find_element(By.XPATH,
                                   "//input[@placeholder = 'Contraseña']")
    password.click()

    # 13. Type '{password}' in 'password'
    password = driver.find_element(By.XPATH,
                                   "//input[@placeholder = 'Contraseña']")
    password.send_keys(f'{password}')

    # 14. Type '{confirmPassword}' in 'ion-input-6'
    ion_input_6 = driver.find_element(By.CSS_SELECTOR,
                                      "[name='ion-input-6']")
    ion_input_6.send_keys(f'{confirmPassword}')

    # 15. Click 'role'
    role = driver.find_element(By.XPATH,
                               "//ion-select[@placeholder = 'Seleccione su tipo de usuario']")
    role.click()

    # 16. Click 'ION-RADIO'
    ion_radio = driver.find_element(By.XPATH,
                                    "//ion-item[1]/ion-radio")
    ion_radio.click()

    # 17. Click 'Registrarme'
    registrarme = driver.find_element(By.XPATH,
                                      "//ion-button[. = 'Registrarme']")
    registrarme.click()

    # 18. Click 'Salir'
    salir = driver.find_element(By.XPATH,
                                "//ion-button[. = 'Salir']")
    salir.click()
