# 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

class TestKUMARIBOOKSOPPlaceorder():
  def setup_method(self, method):
    self.driver = webdriver.Chrome()
    self.vars = {}
  
  def teardown_method(self, method):
    self.driver.quit()
  
  def wait_for_window(self, timeout = 2):
    time.sleep(round(timeout / 1000))
    wh_now = self.driver.window_handles
    wh_then = self.vars["window_handles"]
    if len(wh_now) > len(wh_then):
      return set(wh_now).difference(set(wh_then)).pop()
  
  def test_kUMARIBOOKSOPPlaceorder(self):
    # Test name: KUMARI BOOKSOP Place order
    # Step # | name | target | value
    # 1 | open | http://127.0.0.1:5000/transactions/add | 
    self.driver.get("http://127.0.0.1:5000/transactions/add")
    # 2 | setWindowSize | 1382x744 | 
    self.driver.set_window_size(1382, 744)
    # 3 | click | id=productCode | 
    self.driver.find_element(By.ID, "productCode").click()
    # 4 | type | id=productCode | 2
    self.driver.find_element(By.ID, "productCode").send_keys("2")
    # 5 | click | id=sellingPrice | 
    self.driver.find_element(By.ID, "sellingPrice").click()
    # 6 | type | id=sellingPrice | 20
    self.driver.find_element(By.ID, "sellingPrice").send_keys("20")
    # 7 | click | id=qty | 
    self.driver.find_element(By.ID, "qty").click()
    # 8 | type | id=qty | 10
    self.driver.find_element(By.ID, "qty").send_keys("10")
    # 9 | click | css=tr:nth-child(2) #productCode | 
    self.driver.find_element(By.CSS_SELECTOR, "tr:nth-child(2) #productCode").click()
    # 10 | type | css=tr:nth-child(2) #productCode | 3
    self.driver.find_element(By.CSS_SELECTOR, "tr:nth-child(2) #productCode").send_keys("3")
    # 11 | click | css=tr:nth-child(2) #sellingPrice | 
    self.driver.find_element(By.CSS_SELECTOR, "tr:nth-child(2) #sellingPrice").click()
    # 12 | type | css=tr:nth-child(2) #sellingPrice | 20
    self.driver.find_element(By.CSS_SELECTOR, "tr:nth-child(2) #sellingPrice").send_keys("20")
    # 13 | click | css=tr:nth-child(2) #qty | 
    self.driver.find_element(By.CSS_SELECTOR, "tr:nth-child(2) #qty").click()
    # 14 | type | css=tr:nth-child(2) #qty | 5
    self.driver.find_element(By.CSS_SELECTOR, "tr:nth-child(2) #qty").send_keys("5")
    # 15 | click | css=tr:nth-child(3) #productCode | 
    self.driver.find_element(By.CSS_SELECTOR, "tr:nth-child(3) #productCode").click()
    # 16 | type | css=tr:nth-child(3) #productCode | 4
    self.driver.find_element(By.CSS_SELECTOR, "tr:nth-child(3) #productCode").send_keys("4")
    # 17 | click | css=tr:nth-child(3) #sellingPrice | 
    self.driver.find_element(By.CSS_SELECTOR, "tr:nth-child(3) #sellingPrice").click()
    # 18 | type | css=tr:nth-child(3) #sellingPrice | 20
    self.driver.find_element(By.CSS_SELECTOR, "tr:nth-child(3) #sellingPrice").send_keys("20")
    # 19 | click | css=tr:nth-child(3) #qty | 
    self.driver.find_element(By.CSS_SELECTOR, "tr:nth-child(3) #qty").click()
    # 20 | type | css=tr:nth-child(3) #qty | 3
    self.driver.find_element(By.CSS_SELECTOR, "tr:nth-child(3) #qty").send_keys("3")
    # 21 | click | css=tr:nth-child(4) #productCode | 
    self.driver.find_element(By.CSS_SELECTOR, "tr:nth-child(4) #productCode").click()
    # 22 | type | css=tr:nth-child(4) #productCode | 5
    self.driver.find_element(By.CSS_SELECTOR, "tr:nth-child(4) #productCode").send_keys("5")
    # 23 | click | css=tr:nth-child(4) #sellingPrice | 
    self.driver.find_element(By.CSS_SELECTOR, "tr:nth-child(4) #sellingPrice").click()
    # 24 | type | css=tr:nth-child(4) #sellingPrice | 20
    self.driver.find_element(By.CSS_SELECTOR, "tr:nth-child(4) #sellingPrice").send_keys("20")
    # 25 | click | css=tr:nth-child(4) #qty | 
    self.driver.find_element(By.CSS_SELECTOR, "tr:nth-child(4) #qty").click()
    # 26 | type | css=tr:nth-child(4) #qty | 10
    self.driver.find_element(By.CSS_SELECTOR, "tr:nth-child(4) #qty").send_keys("10")
    # 27 | click | css=div:nth-child(2) > .btn:nth-child(2) | 
    self.driver.find_element(By.CSS_SELECTOR, "div:nth-child(2) > .btn:nth-child(2)").click()
    # 28 | click | css=div:nth-child(2) > .btn:nth-child(1) | 
    self.driver.find_element(By.CSS_SELECTOR, "div:nth-child(2) > .btn:nth-child(1)").click()
    # 29 | click | css=tr:nth-child(5) #productCode | 
    self.driver.find_element(By.CSS_SELECTOR, "tr:nth-child(5) #productCode").click()
    # 30 | type | css=tr:nth-child(5) #productCode | 6
    self.driver.find_element(By.CSS_SELECTOR, "tr:nth-child(5) #productCode").send_keys("6")
    # 31 | click | css=tr:nth-child(5) #sellingPrice | 
    self.driver.find_element(By.CSS_SELECTOR, "tr:nth-child(5) #sellingPrice").click()
    # 32 | type | css=tr:nth-child(5) #sellingPrice | 20
    self.driver.find_element(By.CSS_SELECTOR, "tr:nth-child(5) #sellingPrice").send_keys("20")
    # 33 | click | css=tr:nth-child(5) #qty | 
    self.driver.find_element(By.CSS_SELECTOR, "tr:nth-child(5) #qty").click()
    # 34 | type | css=tr:nth-child(5) #qty | 10
    self.driver.find_element(By.CSS_SELECTOR, "tr:nth-child(5) #qty").send_keys("10")
    # 35 | click | css=div:nth-child(2) > .btn:nth-child(2) | 
    self.driver.find_element(By.CSS_SELECTOR, "div:nth-child(2) > .btn:nth-child(2)").click()
    # 36 | click | id=cashRec | 
    self.driver.find_element(By.ID, "cashRec").click()
    # 37 | type | id=cashRec | 800.00
    self.driver.find_element(By.ID, "cashRec").send_keys("800.00")
    # 38 | click | css=div:nth-child(5) > .btn:nth-child(2) | 
    self.driver.find_element(By.CSS_SELECTOR, "div:nth-child(5) > .btn:nth-child(2)").click()
    # 39 | click | css=div:nth-child(5) > .btn:nth-child(1) | 
    self.driver.find_element(By.CSS_SELECTOR, "div:nth-child(5) > .btn:nth-child(1)").click()
    # 40 | click | css=tr:nth-child(2) a | 
    self.vars["window_handles"] = self.driver.window_handles
    # 41 | selectWindow | handle=${win2942} | 
    self.driver.find_element(By.CSS_SELECTOR, "tr:nth-child(2) a").click()
    self.vars["win2942"] = self.wait_for_window(2000)
    self.driver.switch_to.window(self.vars["win2942"])
  
