form_a.py 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. from time import sleep
  2. from selenium.webdriver.common.by import By
  3. class FormA:
  4. def __init__(self, driver, base_url):
  5. self.driver = driver
  6. self.base_url = base_url
  7. def curd(self):
  8. try:
  9. # 로그인
  10. self.driver.get(self.base_url + '/user-login')
  11. id_box = self.driver.find_element(By.NAME, 'email')
  12. pw_box = self.driver.find_element(By.NAME, 'password')
  13. id_box.clear()
  14. pw_box.clear()
  15. id_box.send_keys('kimhi65@naver.com')
  16. pw_box.send_keys('China13579')
  17. self.driver.find_element(By.CSS_SELECTOR, '.login-form').submit()
  18. # 상품 등록 페이지 이동
  19. self.driver.get(
  20. self.base_url + '/dabory/erp/master-data/item?bpa=eyJtZW51X25hbWUiOiJcdWMwYzFcdWQ0ODggXHViNGYxXHViODVkIiwibWVudV9jb2RlIjoiMDIxMDAwIiwiZGlzYWJsZV9sX21lbnUiOiIwIiwiZW5hYmxlX3JfbWVudSI6IjAiLCJwZXJtaXNzaW9uIjp7ImlzX215bWVudSI6IjAiLCJpc19saXN0IjoiMSIsImlzX3JlYWQiOiIxIiwiaXNfY3JlYXRlIjoiMSIsImlzX3VwZGF0ZSI6IjEiLCJpc19kZWxldGUiOiIxIiwiaXNfbmV3dGFiIjoiMCJ9LCJwYWdlX3VyaSI6IlwvZGFib3J5XC9lcnBcL21hc3Rlci1kYXRhXC9pdGVtIiwicGFyYV9uYW1lIjoiXC9mb3JtLWFcL2l0ZW0iLCJ0aGVtZV9kaXIiOiIiLCJtYWluX2FwcF9pZCI6MCwiZ3Vlc3RfYXBwX2lkIjowfQ==')
  21. sleep(5)
  22. # 상품 등록
  23. self.create()
  24. print('create 성공')
  25. sleep(1)
  26. # 상품 수정
  27. self.update()
  28. print('update 성공')
  29. sleep(1)
  30. # 상품 읽기
  31. self.read( 'TEST-01')
  32. print('read 성공')
  33. sleep(1)
  34. # 상품 삭제
  35. self.delete()
  36. print('delete 성공')
  37. # 테스트 완료 후 크롬 바로 종료
  38. sleep(3)
  39. self.driver.close()
  40. except Exception as error:
  41. # error 종류 출력
  42. print(error)
  43. self.driver.close()
  44. def create(self):
  45. self.driver.find_element(By.ID, 'item-code-txt').send_keys('TEST-01')
  46. self.driver.find_element(By.ID, 'item-name-txt').send_keys('TEST-01')
  47. self.driver.find_element(By.ID, 'sub-name-txt').send_keys('TEST-01')
  48. self.driver.find_element(By.ID, 'sales-prc-txt').send_keys('5000')
  49. self.driver.find_element(By.ID, 'purch-prc-txt').send_keys('5000')
  50. sleep(1)
  51. save_act_btn = self.driver.find_element(By.CSS_SELECTOR, '.item-act.save-button')
  52. self.driver.execute_script("arguments[0].click();", save_act_btn)
  53. def update(self):
  54. item_name_txt = self.driver.find_element(By.ID, 'item-name-txt')
  55. item_name_txt.clear()
  56. item_name_txt.send_keys('TEST-01 UPDATE')
  57. sleep(1)
  58. save_act_btn = self.driver.find_element(By.CSS_SELECTOR, '.item-act.save-button')
  59. self.driver.execute_script("arguments[0].click();", save_act_btn)
  60. def read(self, search_txt):
  61. self.driver.find_element(By.ID, 'item-modal-btn').click()
  62. item_code_txt = self.driver.find_element(By.CSS_SELECTOR, '#modal-item .item-code.filter')
  63. item_code_txt.clear()
  64. item_code_txt.send_keys(search_txt)
  65. self.driver.find_element(By.CSS_SELECTOR, '#modal-item .modal-search').click()
  66. sleep(1)
  67. self.driver.find_element(By.XPATH, '//*[@id="table-body"]/tr[1]/td[3]/a').click()
  68. def delete(self):
  69. self.driver.find_element(By.CSS_SELECTOR, "#item-btn-group .dropdown-toggle").click()
  70. self.driver.find_element(By.CSS_SELECTOR, "#item-btn-group li[data-value='del']").click()
  71. sleep(1)
  72. self.driver.find_element(By.CSS_SELECTOR, ".swal2-confirm").click()