# Generated by Selenium IDE
import pytest
import random
import time
import json
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

link = "http://selenium1py.pythonanywhere.com/ru/"


@pytest.fixture(scope="function")
def browser(request):
    browser = webdriver.Chrome()
    yield browser
    print("\nquit browser..")
    browser.quit()

# Код написан руками:
def test_registration_by_code(browser):
    # Arrange
    browser.get(link)
    login = f'{random.randint(231, 999999)}login_email_test@gmail.com'  # Генерируется радомный почтовый адресс
    password = '328225328225'

    # Act
    browser.find_element_by_css_selector('[id="login_link"]').click()  # Переход на форму регистрации
    browser.find_element_by_css_selector('[name="registration-email"]').send_keys(login)  # Поле ввода почты
    browser.find_element_by_css_selector('[name="registration-password1"]').send_keys(password)  # Поле пароля
    browser.find_element_by_css_selector('[name="registration-password2"]').send_keys(password)  # Поле подтверждения пароля
    browser.find_element_by_css_selector('[name="registration_submit"]').click()  # Кнопка отправки
    welcome_massage = browser.find_element_by_css_selector('[class="alertinner wicon"]').text

    # Assert
    assert welcome_massage == 'Спасибо за регистрацию!', 'Неверный текст приветствия'

# Экспортирован из Selenium IDE
class Test_Registration_by_IDE():
    def setup_method(self, method):
        self.driver = webdriver.Chrome()
        self.vars = {}

    def teardown_method(self, method):
        self.driver.quit()

    def test_registration(self):
        self.driver.get("http://selenium1py.pythonanywhere.com/ru/")
        self.driver.set_window_size(968, 696)
        self.driver.find_element(By.ID, "login_link").click()
        self.driver.find_element(By.ID, "id_registration-email").click()
        self.driver.find_element(By.ID, "id_registration-email").send_keys("12323qq231123221211w@semareef.com")
        self.driver.find_element(By.ID, "id_registration-password1").send_keys("3282253282251111")
        self.driver.find_element(By.ID, "id_registration-password2").send_keys("3282253282251111")
        self.driver.find_element(By.NAME, "registration_submit").click()
        assert self.driver.find_element(By.CSS_SELECTOR, ".alertinner").text == "Спасибо за регистрацию!"
