Advertisement
Guest User

test_ebuddy_login.py

a guest
Jan 21st, 2020
443
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.75 KB | None | 0 0
  1. import time
  2. from selenium import webdriver
  3. from selenium.common.exceptions import StaleElementReferenceException
  4. from selenium.webdriver.common.action_chains import ActionChains
  5. from selenium.webdriver.common.by import By
  6. from selenium.webdriver.common.keys import Keys
  7. from selenium.webdriver.support import expected_conditions as EC
  8. from selenium.webdriver.support.ui import WebDriverWait
  9. from selenium.common.exceptions import NoSuchElementException
  10.  
  11.  
  12.  
  13. class MeetingCreator:
  14.     def __init__(self):
  15.         super().__init__()
  16.         self.username, self.password = self.get_username_password()
  17.         self.driver = webdriver.Chrome("/usr/lib/chromium-browser/chromedriver")
  18.  
  19.     def __del__(self):
  20.         time.sleep(15)
  21.         self.driver.close()
  22.  
  23.     def open_site(self, url):
  24.  
  25.         self.driver.get(url)
  26.         self.driver.implicitly_wait(3)
  27.         self.driver.maximize_window()
  28.        
  29.  
  30.     def test_create_meeting_in_employee_buddy(self):
  31.         try:
  32.             url = "https://www.google.com/"
  33.             self.open_site(url)
  34.        
  35.             self.login_to_employee_buddy()
  36.             self.create_new_meeting()
  37.         except NoSuchElementException as exceptions:
  38.             print(exceptions)
  39.  
  40.     def login_to_employee_buddy(self):
  41.         self.driver.find_element_by_id('login_emp_id').send_keys(self.username)
  42.         self.driver.find_element_by_id('login_password').send_keys(self.password)
  43.         self.driver.find_element_by_xpath("//button[@type='submit']").click()
  44.  
  45.     def get_username_password(self):
  46.         username = None
  47.         password = None
  48.  
  49.         with open("ebuddy_crdn.txt", "r") as file_open:
  50.             for data in file_open.readlines():
  51.                 username, password = data.split()
  52.  
  53.         return username, password
  54.    
  55.     def create_new_meeting(self):
  56.         self.action = ActionChains(self.driver)
  57.         self.driver.find_element_by_link_text('Meeting').click()
  58.         self.driver.find_element_by_link_text('Create meeting').click()
  59.         self.meeting_creation_case_1()
  60.    
  61.     def meeting_creation_case_1(self):
  62.         self.driver.find_element_by_id('add_new_purpose').click()
  63.         self.driver.find_element_by_xpath("//li[text()='Conference']").click()
  64.         self.driver.find_element_by_id(
  65.         'add_new_meeting_title').send_keys('Meeting title 4')
  66.         self.driver.find_element_by_id('add_new_date').click()
  67.         self.driver.find_element_by_xpath(
  68.         "//tbody[@class='ant-calendar-tbody']//td[@title='January 29, 2020']").click()
  69.         self.selection_of_meeting_place()
  70.    
  71.     def selection_of_meeting_place(self):
  72.         self.driver.find_element_by_xpath(
  73.         "//input[@type='radio' and @value='Indoor']").click()
  74.         self.driver.find_element_by_id('add_new_room_id').click()
  75.         self.driver.implicitly_wait(10)
  76.         self.driver.find_element_by_xpath(
  77.         "//ul//li[contains(text(),'OLD Office Ground Ground Floor Big')]").click()
  78.         self.selection_of_start_time()
  79.    
  80.     def selection_of_start_time(self):
  81.         self.driver.find_element_by_id('add_new_start_time').click()
  82.         start_date = self.driver.find_element_by_xpath(
  83.         "//div[@class='ant-time-picker-panel-combobox']/div[1]/ul/li[contains(text(),'12')]")
  84.         self.action.move_to_element(start_date).perform()
  85.         start_date.click()
  86.         end_date = self.driver.find_element_by_xpath(
  87.             "//div[@class='ant-time-picker-panel-combobox']/div[2]/ul/li[contains(text(),'51')]")
  88.         self.action.move_to_element(end_date).perform()
  89.         end_date.click()
  90.         am_pm = self.driver.find_element_by_xpath(
  91.             "//div[@class='ant-time-picker-panel-combobox']/div[3]/ul/li[contains(text(),'pm')]")
  92.         self.action.move_to_element(am_pm).perform()
  93.         am_pm.click()
  94.         self.driver.implicitly_wait(10)
  95.         self.selection_of_end_time()
  96.  
  97.     def selection_of_end_time(self):
  98.  
  99.         self.driver.find_element_by_xpath(
  100.         "//input[@class='ant-time-picker-input' and @id='add_new_end_time']").click()
  101.         tries = 0
  102.         while tries < 3:
  103.             try:
  104.                 WebDriverWait(self.driver, 10).until(EC.presence_of_element_located(
  105.                     (By.XPATH, "//div[@class='ant-time-picker-panel-inner']/div[2]/div[1]/ul/li[contains(text(),'01')]")))
  106.                 start_date_2 = self.driver.find_element_by_xpath(
  107.                     "//div[@class='ant-time-picker-panel-inner']/div[2]/div[1]/ul/li[contains(text(),'01')]")
  108.                 ActionChains(self.driver).move_to_element(start_date_2).perform()
  109.                 start_date_2.click()
  110.                 end_date_2 = self.driver.find_element_by_xpath(
  111.                     "//div[@class='ant-time-picker-panel-inner']/div[2]/div[2]/ul/li[contains(text(),'51')]")
  112.                 ActionChains(self.driver).move_to_element(end_date_2).perform()
  113.                 end_date_2.click()
  114.                 am_pm_2 = self.driver.find_element_by_xpath(
  115.                     "//div[@class='ant-time-picker-panel-inner']/div[2]/div[3]/ul/li[contains(text(),'pm')]")
  116.                 ActionChains(self.driver).move_to_element(am_pm_2).perform()
  117.                 am_pm_2.click()
  118.                 tries = 3
  119.             except StaleElementReferenceException:
  120.                 tries += 1
  121.         self.selection_of_checkbox()
  122.  
  123.     def selection_of_checkbox(self):
  124.         self.driver.find_element_by_class_name('ant-checkbox-input').click()
  125.         self.login_button()
  126.  
  127.     def login_button(self):
  128.            
  129.         self.driver.find_element_by_xpath(
  130.             "//button[@class='ant-btn ant-btn-primary ant-btn-lg ant-btn-block']").click()
  131.  
  132.  
  133.  
  134. if __name__ == '__main__':
  135.     meeting_creator = MeetingCreator()
  136.     meeting_creator.create_meeting_in_employee_buddy()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement