# Generated by Selenium IDE
import pytest
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
from webdriver_manager.chrome import ChromeDriverManager


class TestCreatelocation():
  def setup_method(self, method):
    options = webdriver.ChromeOptions()
    # options.add_argument('--headless')
    # options.add_argument('--no-sandbox')
    options.add_argument("--disable-popup-blocking")
    self.driver = webdriver.Chrome(ChromeDriverManager().install(), options=options)
    self.vars = {}
  
  # def teardown_method(self, method):
    # self.driver.quit()
  
  def test_createlocation(self):
    self.driver.get("http://localhost:8080/server")
    with open("locations.csv", encoding="utf-8") as f:
      for line in f:
        parts = line.split(",")
        city = parts[0]
        lat = parts[1].strip()
        lon = parts[2].strip()


        self.driver.find_element(By.LINK_TEXT, "Create location").click()
        self.driver.find_element(By.ID, "name-input").click()
        self.driver.find_element(By.ID, "name-input").send_keys(city)
        self.driver.find_element(By.ID, "coords-input").click()
        self.driver.find_element(By.ID, "coords-input").send_keys(lat + "," + lon)
        self.driver.find_element(By.XPATH, "/html/body/div/form/button").click()
        # alert = self.driver.switch_to.alert()
        # alert.accept()
        self.driver.find_element(By.XPATH, "/html/body/div/form/a[2]").click()
        # assert self.driver.find_element(By.ID, "message-div").text == "Location has been created"
  
