main.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. from selenium import webdriver
  2. from selenium.webdriver.chrome.service import Service
  3. from webdriver_manager.chrome import ChromeDriverManager
  4. from selenium.webdriver.common.by import By
  5. from selenium.webdriver.common.keys import Keys
  6. from selenium.webdriver.support.select import Select
  7. from selenium.webdriver.support.ui import WebDriverWait
  8. from selenium.webdriver.support import expected_conditions as EC
  9. from time import sleep
  10. from form.form_a import FormA
  11. from form.form_b import FormB
  12. def checkout(driver, base_url):
  13. try:
  14. # 로그인
  15. driver.get(base_url + '/member-login')
  16. id_box = driver.find_element(By.ID, 'email-txt')
  17. pw_box = driver.find_element(By.ID, 'password-txt')
  18. id_box.clear()
  19. id_box.send_keys('wngur6076@naver.com')
  20. pw_box.clear()
  21. pw_box.send_keys('alsckd12@')
  22. driver.find_element(By.XPATH, '//*[@id="app"]/section/div/div/div/div/div[2]/form/div[5]/button').click()
  23. # 아이템 상세페이지로 이동
  24. driver.get(base_url + '/item-gallery/health-food')
  25. driver.find_element(By.XPATH, '//*[@id="app"]/section[2]/div/div[2]/div/form/div[1]/a').click()
  26. # 카트 담기
  27. driver.find_element(By.CSS_SELECTOR, '#cart-form > div.details-add-group > button').click()
  28. # sleep(3)
  29. driver.get(base_url + '/checkout')
  30. # 연락처 선택, 배송지 선택
  31. contact_button = driver.find_element(By.XPATH, '//*[@id="company-contact-bd-div"]/div[1]/div')
  32. driver.execute_script("arguments[0].click();", contact_button)
  33. destina_button = driver.find_element(By.XPATH, '//*[@id="company-destina-bd-div"]/div/div')
  34. driver.execute_script("arguments[0].click();", destina_button)
  35. # 결제방법 선택
  36. paymethod_radio = driver.find_element(By.XPATH, '//*[@id="paymethod-radio-Crypto2"]')
  37. driver.execute_script("arguments[0].click();", paymethod_radio)
  38. # 은행선택 및 입금자명 입력
  39. select_fr = Select(driver.find_element(By.CSS_SELECTOR, '#paymethod-Crypto2 #deposit-bank-select'))
  40. select_fr.select_by_index(1)
  41. driver.find_element(By.CSS_SELECTOR, '#paymethod-Crypto2 #remit-name-txt').send_keys('wngur6076@naver.com')
  42. # 약관동의 체크
  43. checkout_check = driver.find_element(By.CSS_SELECTOR, '#checkout-check')
  44. driver.execute_script("arguments[0].click();", checkout_check)
  45. # 결제하기
  46. checkout_submit = driver.find_element(By.CSS_SELECTOR, '#checkout-btn')
  47. driver.execute_script("arguments[0].click();", checkout_submit)
  48. # 테스트 완료 후 크롬 바로 종료
  49. # driver.close()
  50. except Exception as error:
  51. # error 종류 출력
  52. print(error)
  53. driver.close()
  54. if __name__ == '__main__':
  55. options = webdriver.ChromeOptions()
  56. # 리눅스 실행
  57. # options.add_argument('headless')
  58. # options.add_argument('--no-sandbox')
  59. options.add_argument('window-size=1920,1080')
  60. options.add_experimental_option('detach', True)
  61. driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
  62. driver.implicitly_wait(10)
  63. # FormA(driver, 'https://newerp.daboryhost.com').curd()
  64. FormB(driver, 'https://newerp.daboryhost.com').curd()
  65. # checkout(driver, 'https://p2u.kr')