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: My first Project
    Package: TestProject.Generated.Tests.MyFirstProject
    Test: Editar producto
    Generated by: Fabio Blanco (fablanco45@ucatolica.edu.co)
    Generated on 10/14/2021, 00:04:05
"""


@pytest.fixture()
def driver():
    driver = webdriver.Chrome(token="9YMUsLk66WOGc3Dz5dL5rH53KY99wF1zvatoBn7Lxzs",
                              project_name="My first Project",
                              job_name="Editar producto")
    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"

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

    # 2. Click 'pro'
    pro = driver.find_element(By.XPATH,
                              "//ion-card[1]//ion-card-title[. = 'pro']")
    pro.click()

    # 3. Click 'EDITAR'
    editar = driver.find_element(By.XPATH,
                                 "//ion-button[. = 'Editar']")
    editar.click()

    # 4. Click 'ion-input-2'
    ion_input_2 = driver.find_element(By.CSS_SELECTOR,
                                      "[name='ion-input-2']")
    ion_input_2.click()

    # 5. Type 'pro editado' in 'ion-input-2'
    ion_input_2 = driver.find_element(By.CSS_SELECTOR,
                                      "[name='ion-input-2']")
    ion_input_2.send_keys("pro editado")

    # 6. Click 'ion-input-3'
    ion_input_3 = driver.find_element(By.CSS_SELECTOR,
                                      "[name='ion-input-3']")
    ion_input_3.click()

    # 7. Type '101' in 'ion-input-3'
    ion_input_3 = driver.find_element(By.CSS_SELECTOR,
                                      "[name='ion-input-3']")
    ion_input_3.send_keys("101")

    # 8. Click 'ion-textarea-0'
    ion_textarea_0 = driver.find_element(By.CSS_SELECTOR,
                                         "[name='ion-textarea-0']")
    ion_textarea_0.click()

    # 9. Type 'nuevo editado' in 'ion-textarea-0'
    ion_textarea_0 = driver.find_element(By.CSS_SELECTOR,
                                         "[name='ion-textarea-0']")
    ion_textarea_0.send_keys("nuevo editado")

    # 10. Click 'EDITAR1'
    editar1 = driver.find_element(By.XPATH,
                                  "//ion-col[1]/ion-button[. = 'Editar']")
    editar1.click()

    # 11. Click 'EDITAR1'
    editar1 = driver.find_element(By.XPATH,
                                  "//ion-col[1]/ion-button[. = 'Editar']")
    editar1.click()

    # 12. Click 'EDITAR1'
    editar1 = driver.find_element(By.XPATH,
                                  "//ion-col[1]/ion-button[. = 'Editar']")
    editar1.click()

    # 13. Click 'Cancelar'
    cancelar = driver.find_element(By.XPATH,
                                   "//a[. = 'Cancelar']")
    cancelar.click()
