sak1b

selenium_2_ready_to_record.py

Jun 11th, 2021
578
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from bs4 import BeautifulSoup as soup
  2. from selenium import webdriver
  3. import time
  4. from selenium.webdriver.common.keys import Keys
  5.  
  6.  
  7.  
  8. print('Starting...\n')
  9. driver = webdriver.Chrome("E:\Anaconda\cdrivers\chromedriver")
  10.  
  11. driver.get("http://159.89.38.11/login")
  12.  
  13. email = driver.find_element_by_id('email-1')
  14. password = driver.find_element_by_id('password-1')
  15. login_button = driver.find_element_by_id('m_login_signin_submit')
  16.  
  17.  
  18. email.send_keys('test@orangetoolz.com')
  19. password.send_keys('8Kh8nTe*^jdk')
  20.  
  21.  
  22. login_button.click()
  23.  
  24. time.sleep(5)
  25.  
  26.  
  27.  
  28. #  driver.find_element_by_class_name('dt-brand__tool')
  29.  
  30. sidebar = driver.find_element_by_xpath('/html/body/div[2]/div/header/div/div/div')
  31. sidebar.click()
  32.  
  33. print('clicked side bar...\n')
  34. time.sleep(3)
  35.  
  36. profile_link = driver.find_element_by_xpath('//*[@id="main-sidebar"]/div[1]/ul/li[9]/a')
  37. profile_link.click()
  38.  
  39. print('Loaded profile page successfully...\n')
  40.  
  41.  
  42. MY_ERROR_MESSAGE = "Whoops, looks like something went wrong."
  43.  
  44.  
  45. print('------------------Testing First Name field------------------\n')
  46. print('Using valid cases--------------------------\n')
  47.  
  48. test_cases = ['helloone', 'hellotwo', 'hellobbbbb','myname','itsraining','football']
  49.  
  50. for case in test_cases:
  51.    
  52.     first_name = driver.find_element_by_name('first_name')
  53.     first_name.clear()
  54.     first_name.send_keys(case)
  55.     time.sleep(2)
  56.     save_button = driver.find_element_by_class_name('btn-primary')
  57.     driver.execute_script("arguments[0].click();", save_button)
  58.     error_message = driver.find_element_by_xpath('/html/body/div/h1').text
  59.    
  60.     if error_message == MY_ERROR_MESSAGE:
  61.         print("Case: ",case, "FAIL!\n")
  62.     else:
  63.         print("Case: ",case, "PASS!\n")
  64.  
  65.     driver.execute_script("window.history.go(-1)")
  66.  
  67. print('Using invalid cases------------------------\n')
  68. test_cases = ['123', '1', '/x.234...?']
  69.  
  70. for case in test_cases:
  71.    
  72.     first_name = driver.find_element_by_name('first_name')
  73.     first_name.clear()
  74.     first_name.send_keys(case)
  75.     time.sleep(2)
  76.     save_button = driver.find_element_by_class_name('btn-primary')
  77.     driver.execute_script("arguments[0].click();", save_button)
  78.     error_message = driver.find_element_by_xpath('/html/body/div/h1').text
  79.    
  80.     if error_message == MY_ERROR_MESSAGE:
  81.         print("Case: ",case, "PASS!\n")
  82.     else:
  83.         print("Case: ",case, "FAIL!\n")
  84.  
  85.     driver.execute_script("window.history.go(-1)")
  86.  
  87. print('------------------------------------------------------')
  88.  
  89. driver.refresh()
  90.  
  91. print('------------------Testing Last Name field-------------------\n')
  92. print('Using valid cases:-------------------------\n')
  93.  
  94. test_cases = ['iam randomn', 'itsraining', 'loremipsum']
  95.  
  96. for case in test_cases:
  97.    
  98.     last_name = driver.find_element_by_name('last_name')
  99.     last_name.clear()
  100.     last_name.send_keys(case)
  101.     time.sleep(2)
  102.     save_button = driver.find_element_by_class_name('btn-primary')
  103.     driver.execute_script("arguments[0].click();", save_button)
  104.     error_message = driver.find_element_by_xpath('/html/body/div/h1').text
  105.    
  106.     if error_message == MY_ERROR_MESSAGE:
  107.         print("Case: ",case, "FAIL!\n")
  108.     else:
  109.         print("Case: ",case, "PASS!\n")
  110.  
  111.     driver.execute_script("window.history.go(-1)")
  112.  
  113. print('Using invalid cases:-------------------------\n')
  114.  
  115. test_cases = ['123', '1', '/x.234...?']
  116.  
  117. for case in test_cases:
  118.    
  119.     last_name = driver.find_element_by_name('last_name')
  120.     last_name.clear()
  121.     last_name.send_keys(case)
  122.     time.sleep(2)
  123.     save_button = driver.find_element_by_class_name('btn-primary')
  124.     driver.execute_script("arguments[0].click();", save_button)
  125.     error_message = driver.find_element_by_xpath('/html/body/div/h1').text
  126.    
  127.     if error_message == MY_ERROR_MESSAGE:
  128.         print("Case: ",case, "PASS!\n")
  129.     else:
  130.         print("Case: ",case, "FAIL!\n")
  131.  
  132.     driver.execute_script("window.history.go(-1)")
  133.  
  134.  
  135. driver.refresh()
  136.  
  137. print('------------------Testing Phone field-------------------\n')
  138. print('Using valid cases:-------------------------\n')
  139.  
  140. test_cases = ['18000000000', '123123', '1121']
  141.  
  142. for case in test_cases:
  143.    
  144.     phone = driver.find_element_by_name('phone')
  145.     phone.clear()
  146.     phone.send_keys(case)
  147.     time.sleep(2)
  148.     save_button = driver.find_element_by_class_name('btn-primary')
  149.     driver.execute_script("arguments[0].click();", save_button)
  150.     error_message = driver.find_element_by_xpath('/html/body/div/h1').text
  151.    
  152.     if error_message == MY_ERROR_MESSAGE:
  153.         print("Case: ",case, "FAIL!\n")
  154.     else:
  155.         print("Case: ",case, "PASS!\n")
  156.  
  157.     driver.execute_script("window.history.go(-1)")
  158.  
  159. print('Using invalid cases:-------------------------\n')
  160.  
  161. test_cases = ['asdf', '222', '/x.234...?']
  162.  
  163. for case in test_cases:
  164.    
  165.     phone = driver.find_element_by_name('phone')
  166.     phone.clear()
  167.     phone.send_keys(case)
  168.     time.sleep(2)
  169.     save_button = driver.find_element_by_class_name('btn-primary')
  170.     driver.execute_script("arguments[0].click();", save_button)
  171.     error_message = driver.find_element_by_xpath('/html/body/div/h1').text
  172.    
  173.     if error_message == MY_ERROR_MESSAGE:
  174.         print("Case: ",case, "PASS!\n")
  175.     else:
  176.         print("Case: ",case, "FAIL!\n")
  177.  
  178.     driver.execute_script("window.history.go(-1)")
  179.  
  180.  
  181. driver.refresh()
  182.  
  183. print('------------------Testing Address field-------------------\n')
  184. print('Using valid cases:-------------------------\n')
  185.  
  186. test_cases = ['18000000000', '123123', '1121']
  187.  
  188. for case in test_cases:
  189.    
  190.     address = driver.find_element_by_name('address')
  191.     address.clear()
  192.     address.send_keys(case)
  193.     time.sleep(2)
  194.     save_button = driver.find_element_by_class_name('btn-primary')
  195.     driver.execute_script("arguments[0].click();", save_button)
  196.     error_message = driver.find_element_by_xpath('/html/body/div/h1').text
  197.    
  198.     if error_message == MY_ERROR_MESSAGE:
  199.         print("Case: ",case, "FAIL!\n")
  200.     else:
  201.         print("Case: ",case, "PASS!\n")
  202.  
  203.     driver.execute_script("window.history.go(-1)")
  204.  
  205. print('Using invalid cases:-------------------------\n')
  206.  
  207. test_cases = ['.....', 'zcxvxcv', 'asdf4445asf.?']
  208.  
  209. for case in test_cases:
  210.    
  211.     address = driver.find_element_by_name('address')
  212.     address.clear()
  213.     address.send_keys(case)
  214.     time.sleep(2)
  215.     save_button = driver.find_element_by_class_name('btn-primary')
  216.     driver.execute_script("arguments[0].click();", save_button)
  217.     error_message = driver.find_element_by_xpath('/html/body/div/h1').text
  218.    
  219.     if error_message == MY_ERROR_MESSAGE:
  220.         print("Case: ",case, "PASS!\n")
  221.     else:
  222.         print("Case: ",case, "FAIL!\n")
  223.  
  224.     driver.execute_script("window.history.go(-1)")
  225.  
  226.  
  227.  
  228. print('Good bye...\n')
  229.  
RAW Paste Data