Exemplo n.º 1
0
 def explicit_wait_method(self, condition, address, extra=None):
     wait = WebDriverWait(driver, 20)
     element = None
     locater = By.XPATH, address
     if condition == "presenceofelement":
         cc = ec.presence_of_element_located(locater)
         element = wait.until(cc)
     elif condition == "elementtobeselected":
         cc = ec.element_to_be_selected(locater)
         element = wait.until(cc)
     elif condition == "elementlocatedtobeselected":
         cc = ec.element_located_to_be_selected(locater)
         element = wait.until(cc)
     elif condition == "elementtobeclickable":
         cc = ec.element_to_be_clickable(locater)
         wait.until(cc)
     elif condition == "visibilityofelementlocated":
         cc = ec.visibility_of_element_located(locater)
         wait.until(cc)
     elif condition == "titlecontains":
         cc = ec.title_contains(extra)
         element = wait.until(cc)
     elif condition == "presenceofallelementslocated":
         cc = ec.presence_of_all_elements_located(locater)
         element = wait.until(cc)
     elif condition == "visibilityof":
         cc = ec.visibility_of(element)
         element = wait.until(cc)
     else:
         log.error("invalid condition type for wait")
     return element
Exemplo n.º 2
0
 def nevigation_command_implementation(self, nevigation_type):
     if nevigation_type == "back":
         driver.back()
     elif nevigation_type == "forword":
         driver.forward()
     else:
         log.error("invalid nevigation type")
Exemplo n.º 3
0
 def switch_to_another_object(self, object_type, value=None, other=None):
     return_value = None
     if object_type == "window":
         parent_handle = driver.current_window_handle
         all_handles = driver.window_handles
         for handle in all_handles:
             if handle != parent_handle:
                 driver.switch_to.window(handle)
                 if driver.title == value:
                     break
                 else:
                     continue
     elif object_type == "frame":
         driver.switch_to.frame(value)
     elif object_type == "alert":
         alert = driver.switch_to.alert
         if other == "accept":
             alert.accept()
         elif other == "dismiss":
             alert.dismiss()
         elif other == "sendkeys":
             alert.send_keys(value)
         elif other == "gettext":
             return_value = alert.text
         else:
             log.error("invalid alert type")
     else:
         raise Exception
     return return_value
Exemplo n.º 4
0
 def perform_mouse_keyboard_actions(self,
                                    element,
                                    action_type,
                                    source_ele=None,
                                    dest_ele=None,
                                    value=None):
     ac = ActionChains(driver)
     if action_type == "rightclick":
         ac.context_click(element)
     elif action_type == "movetoelement":
         ac.move_to_element(element)
     elif action_type == "click":
         ac.click(element)
     elif action_type == "sendkeys":
         ac.send_keys(value)
     elif action_type == "doubleclick":
         ac.double_click(element)
     elif action_type == "draganddrop":
         ac.drag_and_drop(source_ele, dest_ele)
     elif action_type == "clickandhold":
         ac.click_and_hold(element)
     elif action_type == "keyup":
         ac.key_up(value, element)
     elif action_type == "keydown":
         ac.key_down(value, element)
     else:
         log.error("invalid mause key board action type")
     ac.perform()
Exemplo n.º 5
0
 def launch_application(browser_name, app_url):
     global driver
     log.info("in init method of selenium base")
     try:
         if browser_name == "chrome":
             option = ChromeOptions()
             option.add_argument("start-maximized")
             option.add_argument("--ignore-certificate-errors")
             option.add_argument("--disable-extensions")
             option.add_argument("--disable-infobars")
             option.add_argument("disable-notifications")
             driver = Chrome(executable_path="./drivers/chromedriver.exe",
                             options=option)
             log.info("chrome browser is launch successfully")
         elif browser_name == "firefox":
             profile = FirefoxProfile()
             profile.accept_untrusted_certs = True
             options = FirefoxOptions()
             options.add_argument("start-maximized")
             driver = Firefox(executable_path="./drivers/geckodriver.exe")
             log.info("firefox browser is launch successfully")
         elif browser_name == "ie":
             driver = Ie(executable_path="./drivers/IEDriverServer.exe")
         else:
             log.error("browser name is incorrect", browser_name)
     except WebDriverException:
         log.critical("exception", WebDriverException)
     driver.implicitly_wait(5)
     driver.get(app_url)
Exemplo n.º 6
0
 def launch_browser(self, browser_name, url):
     global driver
     try:
         if browser_name == "chrome":
             chromeoptions = ChromeOptions()
             chromeoptions.add_argument("start-maximized")
             chromeoptions.add_argument("disable-notifications")
             chromeoptions.add_argument("--ignore-certificate-errors")
             chromeoptions.add_argument("--disable-infobars")
             chromeoptions.add_argument("--disable-extensions")
             driver = webdriver.Chrome(
                 executable_path="./drivers/chromedriver.exe",
                 options=chromeoptions)
             log.info("chrome browser launch successfully")
         elif browser_name == "firefox":
             firefoxoptions = FirefoxOptions()
             firefoxoptions.add_argument("start-maximize")
             driver = webdriver.Firefox(
                 executable_path="./drivers/geckodriver.exe",
                 options=firefoxoptions)
             log.info("firefox browser launch successfully")
         elif browser_name == "ie":
             ieoptions = IeOptions()
             ieoptions.add_argument("start-maximize")
             driver = webdriver.Ie(
                 executable_path="./drivers/IEDriverServer.exe",
                 options=ieoptions)
             log.info("ie browser launch successfully")
         else:
             log.error("invalid browser name")
     except WebDriverException as e:
         log.error("exception ", e)
     driver.implicitly_wait(10)
     driver.get(url)
Exemplo n.º 7
0
 def perform_actions(element, action_type, value=None, other=None):
     return_value = None
     if action_type == "click":
         element.click()
     elif action_type == "settext":
         element.clear()
         element.send_keys(value)
     elif action_type == "gettext":
         return_value = element.text
     elif action_type == "getattribute":
         element.get_attribute(value)
     elif action_type == 'setattribute':
         script = "document.getElementsByClassName('" + other + "')[0].value = " + value + ")"
         driver.execute_script(script)
     elif action_type == "isdisplayed":
         return_value = element.is_displayed()
     elif action_type == "isselected":
         return_value = element.is_selected()
     elif action_type == "isenabled":
         return_value = element.is_enabled()
     elif action_type == "selectdropdown":
         sel = Select(element)
         if other == "index":
             sel.select_by_index(value)
         elif other == "value":
             sel.select_by_value(value)
         elif other == "visibletext":
             sel.select_by_visible_text(value)
         elif other == "options":
             return_value = sel.options
     else:
         log.error("invalid action type")
     return return_value
Exemplo n.º 8
0
 def get_page_details(detail_type, element=None):
     if detail_type == "text":
         return element.text
     elif detail_type == "title":
         return driver.title
     elif detail_type == "url":
         return driver.current_url
     else:
         log.error("invalid detail type")
Exemplo n.º 9
0
 def wait_emplimentation(element, wait_type):
     element = None
     if wait_type == "implicitewait":
         driver.implicitly_wait(20)
     elif wait_type == "explicitewait":
         wait = WebDriverWait(driver, 30)
         wait.until(ec.visibility_of_element_located(element))
         return element
     else:
         log.error("invalid wait type")
Exemplo n.º 10
0
 def get_page_details(self, detail_type, element=None):
     return_value = None
     if detail_type == "text":
         return element.text
     elif detail_type == "title":
         return_value = driver.title
     elif detail_type == "url":
         return_value = driver.current_url
     else:
         log.error("invalid page detail type")
     return return_value
Exemplo n.º 11
0
 def identify_elements(locater_type, address):
     element = None
     wait = WebDriverWait(driver, 20, 1)
     if locater_type == "id":
         locater = By.ID, address
         condition = ec.presence_of_all_elements_located(locater)
         element = wait.until(condition)
         return element
     elif locater_type == "name":
         locater = By.NAME, address
         condition = ec.presence_of_all_elements_located(locater)
         element = wait.until(condition)
         return element
     elif locater_type == "classname":
         locater = By.CLASS_NAME, address
         condition = ec.presence_of_all_elements_located(locater)
         element = wait.until(condition)
         return element
     elif locater_type == "tagname":
         locater = By.TAG_NAME, address
         condition = ec.presence_of_all_elements_located(locater)
         element = wait.until(condition)
         return element
     elif locater_type == "linktext":
         locater = By.LINK_TEXT, address
         condition = ec.presence_of_all_elements_located(locater)
         element = wait.until(condition)
         return element
     elif locater_type == "partiallinktext":
         locater = By.PARTIAL_LINK_TEXT, address
         condition = ec.presence_of_all_elements_located(locater)
         element = wait.until(condition)
         return element
     elif locater_type == "css":
         locater = By.CSS_SELECTOR, address
         condition = ec.presence_of_all_elements_located(locater)
         element = wait.until(condition)
         return element
     elif locater_type == "xpath":
         locater = By.XPATH, address
         condition = ec.presence_of_all_elements_located(locater)
         element = wait.until(condition)
         return element
     else:
         log.error("invalid locater type")
Exemplo n.º 12
0
 def identify_elements(self, locater_type, locater):
     if locater_type == "id":
         return driver.find_elements_by_id(locater)
     elif locater_type == "name":
         return driver.find_elements_by_name(locater)
     elif locater_type == "classname":
         return driver.find_elements_by_class_name(locater)
     elif locater_type == "tagname":
         return driver.find_elements_by_tag_name(locater)
     elif locater_type == "linktext":
         return driver.find_elements_by_link_text(locater)
     elif locater_type == "partiallinktext":
         return driver.find_elements_by_partial_link_text(locater)
     elif locater_type == "css":
         return driver.find_elements_by_css_selector(locater)
     elif locater_type == "xpath":
         return driver.find_elements_by_xpath(locater)
     else:
         log.error("invalid locater type for identify elements")
Exemplo n.º 13
0
 def key_operations(self, element, key_action_type):
     if key_action_type == "down":
         element.send_keys(Keys.DOWN)
     elif key_action_type == "arrowdown":
         element.send_keys(Keys.ARROW_DOWN)
     elif key_action_type == "arrowup":
         element.send_keys(Keys.ARROW_UP)
     elif key_action_type == "arrowright":
         element.send_keys(Keys.ARROW_RIGHT)
     elif key_action_type == "arrowleft":
         element.send_keys(Keys.ARROW_LEFT)
     elif key_action_type == "space":
         element.send_keys(Keys.SPACE)
     elif key_action_type == "tab":
         element.send_keys(Keys.TAB)
     elif key_action_type == "backspace":
         element.send_keys(Keys.BACKSPACE)
     elif key_action_type == "enter":
         element.send_keys(Keys.ENTER)
     else:
         log.error("invalid key operation action type")
Exemplo n.º 14
0
 def click_on_checkbox_1(self):
     element=self.get_checkbox_1_element()
     if element.is_selected()==False:
         self.perform_actions(element,"click")
     else:
         log.error("checkbox already selected",element.is_selected())