Пример #1
0
 def VerifyEnabled(cls, trueOrfalse):
     log.step_normal(u"Element [%s]: Verify Enabled = [%s]" % (cls.__name__, trueOrfalse))
     
     cls.__wait()
     elements = env.threadlocal.BROWSER.find_elements(cls.by, cls.value)
     
     is_disabled = elements[cls.index].get_attribute("disabled")
     log.step_normal(u"Element [%s]: attribute 'is_disabled' = [%s]" % (cls.__name__, is_disabled))
     
     if is_disabled == "true":
         if trueOrfalse == False:
             log.step_pass("Pass...")
         else:
             log.step_fail("Fail...")
     
     elif elements[cls.index].is_enabled():
         if trueOrfalse == True:
             log.step_pass("Pass")
         else:
             log.step_fail("Fail")
     
     else:
         log.step_fail("Not verified.")
     
     
     cls.__clearup()
Пример #2
0
 def __wait_for_disappearing(cls):
     
     t = 0
     while t < 120:
         t = t + 1
         
         try:
             elements = env.threadlocal.BROWSER.find_elements(cls.by, cls.value)
         except NoSuchElementException:
             log.step_normal("Element [%s]: NoSuchElementException." % cls.__name__)
             elements = []
         except BadStatusLine:
             log.step_warning("Element [%s]: BadStatusLine." % cls.__name__)
             continue
         except UnexpectedAlertPresentException:
             log.step_warning("Element [%s]: UnexpectedAlertPresentException." % cls.__name__)
         
         if len(elements) == 0:
             return True
         else:
             time.sleep(0.5)
             log.step_normal("Element [%s]: WairForDisappearing... Found [%s] Element. Tried [%s] Times." % (cls.__name__, len(elements), t))
     
     
     return False
Пример #3
0
    def ClickList(cls):
        log.step_normal("Element [%s]: Do ClickList()" % cls.__name__)

        if env.RUNNING_BROWSER in ("Chrome", "Firefox", "IE", "Safari"):
            js1 = "var q = document.documentElement.scrollTop=0"
            env.driver.execute_script(js1)
            time.sleep(3)
            js2 = "var q = document.documentElement.scrollTop=100000"
            env.driver.execute_script(js2)

        # cls.__wait()
        WebDriverWait(env.driver, 10).until(lambda the_driver:
                                            the_driver.find_element(cls.by, cls.value).is_displayed())

        i = 0
        while i < 1:
            elements = env.driver.find_elements(cls.by, cls.value)
            rd = random.randint(0, len(elements)-1)

            action = webdriver.ActionChains(env.driver)
            action.move_to_element(elements[rd])
            action.click(elements[rd])
            action.perform()
            time.sleep(2)

            i += 1

        env.driver.switch_to_window(env.driver.window_handles[-1])
        env.driver.maximize_window()
        time.sleep(3)

        cls.__clearup()
Пример #4
0
 def Refresh(cls, times=4):
     log.step_normal(u"Element [%s]: Browser Refresh" % (cls.__name__,))
     
     for i in range(times):
         action = webdriver.ActionChains(env.threadlocal.BROWSER)
         action.key_down(Keys.CONTROL).send_keys(Keys.F5).key_up(Keys.CONTROL).perform()
         time.sleep(5)
Пример #5
0
 def cell_by_colname(self, rowx, col_name):
     for colx in range(0, self.sheet.ncols):
         if self.data[0][colx] == col_name:
             log.step_normal("[%s][%s]=[%s]" % (colx, col_name, self.data[rowx][colx]))
             return self.data[rowx][colx]
     
     return "ERROR: NO DATA FETCHED!"
Пример #6
0
    def Set(cls, value):
        if value == "":
            return
        
        if value == "SET_EMPTY":
            value = ""
        
        log.step_normal(u"Element [%s]: Set Value [%s]." % (cls.__name__, value))
        
        # cls.__wait()
        WebDriverWait(env.driver, 10).until(lambda the_driver:
                                            the_driver.find_element(cls.by, cls.value).is_displayed())
        elements = env.driver.find_elements(cls.by, cls.value)

        if elements[cls.index].tag_name == "select" or elements[cls.index].tag_name == "ul":
            cls.Select(value)
            time.sleep(3)
        
        else:
            elements[cls.index].clear()
            action = webdriver.ActionChains(env.driver)
            action.send_keys_to_element(elements[cls.index], value)
            action.perform()
            time.sleep(3)
            
            cls.__clearup()
Пример #7
0
 def GetParentElement(cls):
     log.step_normal("Element [%s]: GetParentElement()" % (cls.__name__))
     
     cls.__wait()
     elements = env.threadlocal.BROWSER.find_elements(cls.by, cls.value)
     
     return elements[cls.index].parent()
Пример #8
0
    def VerifyExistence(cls, trueORfalse):
        log.step_normal("Element [%s]: Verify Existence = [%s]." %
                        (cls.__name__, trueORfalse))

        if trueORfalse is True:
            cls.__wait_for_appearing()
        else:
            cls.__wait_for_disappearing()

        elements = env.driver.find_elements(cls.by, cls.value)
        log.step_normal("Element [%s]: Count = [%s]" %
                        (cls.__name__, len(elements)))

        cls.__clearup()

        if len(elements) > 0:
            if trueORfalse is True:
                log.step_pass("Exist!")
            else:
                log.step_fail("Exist!")
        else:
            if trueORfalse is False:
                log.step_pass("Not Exist!")
            else:
                log.step_fail("Not Exist!")
Пример #9
0
    def Select(cls, value):
        if value == "": return

        log.step_normal("Element [%s]: Do Select [%s]." %
                        (cls.__name__, value))

        cls.__wait()
        elements = env.BROWSER.find_elements(cls.by, cls.value)

        #### select ################
        if elements[cls.index].tag_name == "select":
            options = elements[cls.index].find_elements_by_tag_name('option')

            for option in options:
                if option.text == value:
                    option.click()
                    break

        #### ul ################
        elif elements[cls.index].tag_name == "ul":
            lis = elements[cls.index].find_elements_by_tag_name('li')

            for li in lis:
                if li.text == value:
                    li.click()
                    break

        #### NOT Supported ################
        else:
            log.step_fail("Element [%s]: Tag Name [%s] Not Support [Select]." %
                          (cls.__name__, elements[cls.index].tag_name))

        cls.__clearup()
Пример #10
0
    def ClickList(cls):
        log.step_normal("Element [%s]: Do ClickList()" % cls.__name__)

        if env.RUNNING_BROWSER in ("Chrome", "Firefox", "IE", "Safari"):
            js1 = "var q = document.documentElement.scrollTop=0"
            env.driver.execute_script(js1)
            time.sleep(3)
            js2 = "var q = document.documentElement.scrollTop=100000"
            env.driver.execute_script(js2)

        # cls.__wait()
        WebDriverWait(env.driver,
                      10).until(lambda the_driver: the_driver.find_element(
                          cls.by, cls.value).is_displayed())

        i = 0
        while i < 1:
            elements = env.driver.find_elements(cls.by, cls.value)
            rd = random.randint(0, len(elements) - 1)

            action = webdriver.ActionChains(env.driver)
            action.move_to_element(elements[rd])
            action.click(elements[rd])
            action.perform()
            time.sleep(2)

            i += 1

        env.driver.switch_to_window(env.driver.window_handles[-1])
        env.driver.maximize_window()
        time.sleep(3)

        cls.__clearup()
Пример #11
0
    def Set(cls, value):
        if value == "":
            return

        if value == "SET_EMPTY":
            value = ""

        log.step_normal(u"Element [%s]: Set Value [%s]." %
                        (cls.__name__, value))

        # cls.__wait()
        WebDriverWait(env.driver,
                      10).until(lambda the_driver: the_driver.find_element(
                          cls.by, cls.value).is_displayed())
        elements = env.driver.find_elements(cls.by, cls.value)

        if elements[cls.index].tag_name == "select" or elements[
                cls.index].tag_name == "ul":
            cls.Select(value)
            time.sleep(3)

        else:
            elements[cls.index].clear()
            action = webdriver.ActionChains(env.driver)
            action.send_keys_to_element(elements[cls.index], value)
            action.perform()
            time.sleep(3)

            cls.__clearup()
Пример #12
0
    def __clearup(cls):
        if cls.index != 0:
            log.step_normal(
                "Element [%s]: The Operation Element Index = [%s]." %
                (cls.__name__, cls.index))

        cls.index = 0
Пример #13
0
 def cell_by_rowname(self, row_name, colx):
     for rowx in range(0, self.sheet.nrows):
         if self.data[rowx][0] == row_name:
             log.step_normal("[%s][%s]=[%s]" % (row_name, colx, self.data[rowx][colx]))
             return self.data[rowx][colx]
     
     return "ERROR: NO DATA FETCHED!"
Пример #14
0
 def Select(cls, value):
     if value == "": return
     
     log.step_normal("Element [%s]: Do Select [%s]." % (cls.__name__, value))
     
     cls.__wait()
     elements = env.BROWSER.find_elements(cls.by, cls.value)
     
     
     #### select ################
     if elements[cls.index].tag_name == "select":
         options = elements[cls.index].find_elements_by_tag_name('option')
         
         for option in options:
             if option.text == value:
                 option.click()
                 break
     
     #### ul ################
     elif elements[cls.index].tag_name == "ul":
         lis = elements[cls.index].find_elements_by_tag_name('li')
         
         for li in lis:
             if li.text == value:
                 li.click()
                 break
     
     #### NOT Supported ################
     else:
         log.step_fail("Element [%s]: Tag Name [%s] Not Support [Select]." % (cls.__name__, elements[cls.index].tag_name))
     
     
     cls.__clearup()
Пример #15
0
 def AlertSendKeys(cls, value):
     log.step_normal("AlertSendKeys [%s]" % value)
     try:
         env.threadlocal.BROWSER.switch_to.alert.send_keys(value)
         env.threadlocal.BROWSER.switch_to.default_content()
     except:
         log.step_warning(str(sys.exc_info()))
Пример #16
0
    def SwitchToDefaultWindow(cls):
        log.step_normal("SwitchToDefaultWindow()")
        log.step_normal("Switch To The Default Window of: %s" % str(env.driver.window_handles))

        try:
            env.driver.switch_to.window(env.driver.window_handles[0])
        except:
            pass
Пример #17
0
def isElementExist(xpath):
    try:
        log.step_normal("find_elements_by_xpath: {0} is existed, return True.".format(xpath))
        element = driver.find_elements_by_xpath(xpath)[0]
        return True
    except Exception:
        log.step_normal("find_elements_by_xpath: {0} is not existed, return False.".format(xpath))
        return False
Пример #18
0
 def GetElementObj(cls): #### get real time obj counts, without waiting.
     log.step_normal("Element [%s]: GetElementObj." % (cls.__name__))
     
     cls.__wait()
     elements = env.threadlocal.BROWSER.find_elements(cls.by, cls.value)
     
     cls.__clearup()
     return elements[cls.index]
Пример #19
0
    def SwitchToDefaultContent(cls):
        log.step_normal("SwitchToDefaultContent()")
        
        try:
#           env.threadlocal.BROWSER.switch_to_default_content()
            env.threadlocal.BROWSER.switch_to.default_content()
        except:
            log.step_warning("env.threadlocal.BROWSER.switch_to.default_content()")
            pass
Пример #20
0
 def AlertTextHave(cls, txt_value):
     log.step_normal("AlertTextHave [%s]" % txt_value)
     alert_text = env.threadlocal.BROWSER.switch_to_alert().text()
     
     if txt_value in alert_text:
         log.step_pass("pass")
     else:
         log.step_fail("fail")
     env.threadlocal.BROWSER.switch_to_default_content()
Пример #21
0
    def SwitchToDefaultWindow(cls):
        log.step_normal("SwitchToDefaultWindow()")
        log.step_normal("Switch To The Default Window of: %s" %
                        str(env.driver.window_handles))

        try:
            env.driver.switch_to.window(env.driver.window_handles[0])
        except:
            pass
Пример #22
0
    def AlertTextHave(cls, txt_value):
        log.step_normal("AlertTextHave [%s]" % txt_value)
        alert_text = env.BROWSER.switch_to_alert().text()

        if txt_value in alert_text:
            log.step_pass("pass")
        else:
            log.step_fail("fail")
        env.BROWSER.switch_to_default_content()
Пример #23
0
 def GetObjectsCount(cls):
     log.step_normal("Element [%s]: GetObjectsCount." % (cls.__name__))
     
     cls.__wait_for_appearing()
     
     elements = env.threadlocal.BROWSER.find_elements(cls.by, cls.value)
     log.step_normal("Element [%s]: GetObjectsCount = [%s]" % (cls.__name__, len(elements)))
     
     cls.__clearup()
     return len(elements)
Пример #24
0
 def SwitchToDefaultWindow(cls):
     log.step_normal("SwitchToDefaultWindow()")
     
     log.step_normal("Switch To The Default Window of: %s" % str(env.threadlocal.BROWSER.window_handles))
     
     try:
         env.threadlocal.BROWSER.switch_to.window(env.threadlocal.BROWSER.window_handles[0])
     except:
         log.step_warning("env.threadlocal.BROWSER.switch_to.window(env.threadlocal.BROWSER.window_handles[0])")
         pass
Пример #25
0
 def GetInnerHTML(cls):
     log.step_normal(u"Element [%s]: GetInnerHTML()" % (cls.__name__, ))
     
     cls.__wait()
     elements = env.threadlocal.BROWSER.find_elements(cls.by, cls.value)
     
     log.step_normal(u"Element [%s]: InnerHTML = [%s]" % (cls.__name__, elements[cls.index].get_attribute('innerHTML')))
     
     cls.__clearup()
     return elements[cls.index].get_attribute('innerHTML')
Пример #26
0
 def VerifyAttribute(cls, name, value, method='equal'):
     '''
     Example:
         NewClaim.Dates.ReminderDate.VerifyAttribute('ng-model', 'hello', method='equal')
         NewClaim.Dates.ReminderDate.VerifyAttribute('ng-model', 'hello', method='contain')
         NewClaim.Dates.ReminderDate.VerifyAttribute('ng-model', 'hello', method='in')
         NewClaim.Dates.ReminderDate.VerifyAttribute('ng-model', 'hello', method='not equal')
     
     Description for "method":
         equal  => real value is 'hello'
         has    => real value contains 'hello', e.g. 'hello world'.
         in     => real value in 'hello', e.g. 'he'
         differ => real value not equal to 'hello', e.g. 'hehe'
     
     '''
     log.step_normal("Element [%s]: VerifyAttribute [%s] <%s> [%s]." % (cls.__name__, name, method, value))
     
     cls.__wait()
     elements = env.threadlocal.BROWSER.find_elements(cls.by, cls.value)
     realvalue = elements[cls.index].get_attribute(name)
     
     if method.lower() == 'equal':
         if value == realvalue:
             log.step_pass("real value=[%s]" % realvalue)
         else:
             log.step_fail("real value=[%s]" % realvalue)
     
     elif method.lower() == 'not equal':
         if not value == realvalue:
             log.step_pass("real value=[%s]" % realvalue)
         else:
             log.step_fail("real value=[%s]" % realvalue)
     
     elif method.lower() == 'contain':
         if value in realvalue:
             log.step_pass("real value=[%s]" % realvalue)
         else:
             log.step_fail("real value=[%s]" % realvalue)
     
     elif method.lower() == 'not contain':
         if not value in realvalue:
             log.step_pass("real value=[%s]" % realvalue)
         else:
             log.step_fail("real value=[%s]" % realvalue)
     
     elif method.lower() == 'in':
         if realvalue in value:
             log.step_pass("real value=[%s]" % realvalue)
         else:
             log.step_fail("real value=[%s]" % realvalue)
     
     else:
         log.step_fail("code error.")
     
     cls.__clearup()
Пример #27
0
 def ClickAndHold(cls):
     log.step_normal("Element [%s]: Do ClickAndHold()" % (cls.__name__))
     
     cls.__wait()
     elements = env.BROWSER.find_elements(cls.by, cls.value)
     
     action = webdriver.ActionChains(env.BROWSER)
     action.click_and_hold(elements[cls.index])
     action.perform()
     
     cls.__clearup()
Пример #28
0
 def SendEnter(cls):
     log.step_normal(u"Element [%s]: SendEnter()" % (cls.__name__, ))
     
     cls.__wait()
     elements = env.threadlocal.BROWSER.find_elements(cls.by, cls.value)
     
     action = webdriver.ActionChains(env.threadlocal.BROWSER)
     action.send_keys_to_element(elements[cls.index], Keys.ENTER)
     action.perform()
     
     cls.__clearup()
Пример #29
0
 def ReleaseClick(cls):
     log.step_normal("Element [%s]: ReleaseClick()" % (cls.__name__))
     
     cls.__wait()
     elements = env.threadlocal.BROWSER.find_elements(cls.by, cls.value)
     
     action = webdriver.ActionChains(env.threadlocal.BROWSER)
     action.release(elements[cls.index])
     action.perform()
     
     cls.__clearup()
Пример #30
0
 def DoubleClick(cls):
     log.step_normal("Element [%s]: DoubleClick()" % (cls.__name__))
     
     cls.__wait()
     elements = env.threadlocal.BROWSER.find_elements(cls.by, cls.value)
     
     action = webdriver.ActionChains(env.threadlocal.BROWSER)
     action.double_click(elements[cls.index])
     action.perform()
     
     cls.__clearup()
Пример #31
0
 def GetInnerHTML(cls):
     log.step_normal(u"Element [%s]: GetInnerHTML." % (cls.__name__, ))
     
     # cls.__wait()
     WebDriverWait(env.driver, 10).until(lambda the_driver:
                                         the_driver.find_element(cls.by, cls.value).is_displayed())
     elements = env.driver.find_elements(cls.by, cls.value)
     log.step_normal(u"Element [%s]: InnerHTML = [%s]" % (cls.__name__, elements[cls.index].get_attribute('innerHTML')))
     
     cls.__clearup()
     return elements[cls.index].get_attribute('innerHTML').strip()
Пример #32
0
 def GetAttribute(cls, attr):
     log.step_normal(u"Element [%s]: GetAttribute [%s]." % (cls.__name__, attr))
     
     cls.__wait()
     elements = env.threadlocal.BROWSER.find_elements(cls.by, cls.value)
     
     attr_value = elements[cls.index].get_attribute(attr)
     log.step_normal(u"Element [%s]: Attribute Value = [%s]." % (cls.__name__, attr_value))
     
     cls.__clearup()
     return attr_value
Пример #33
0
 def DoubleClick(cls):
     log.step_normal("Element [%s]: Do DoubleClick()" % (cls.__name__))
     
     cls.__wait()
     elements = env.BROWSER.find_elements(cls.by, cls.value)
     
     action = webdriver.ActionChains(env.BROWSER)
     action.double_click(elements[cls.index])
     action.perform()
     
     cls.__clearup()
Пример #34
0
def get_urlIndex(tagurl, urls):
    i = 0
    has = -1
    for url in urls:
        if tagurl.split('/')[2] in url:
            has = True
            log.step_normal('url在搜索结果第[%s]个' % i)
            return i
        i = i + 1
    log.step_normal('url不在当前页')
    return has
Пример #35
0
    def Click_No_Switch(cls):
        log.step_normal("Element [%s]: Do Click_No_Switch()" % cls.__name__)

        # cls.__wait()
        WebDriverWait(env.driver, 10).until(lambda the_driver:
                                            the_driver.find_element(cls.by, cls.value).is_displayed())
        elements = env.driver.find_element(cls.by, cls.value)
        elements.click()
        time.sleep(3)

        cls.__clearup()
Пример #36
0
    def SendEnter(cls):
        log.step_normal(u"Element [%s]: SendEnter()" % (cls.__name__, ))

        cls.__wait()
        elements = env.BROWSER.find_elements(cls.by, cls.value)

        action = webdriver.ActionChains(env.BROWSER)
        action.send_keys_to_element(elements[cls.index], Keys.ENTER)
        action.perform()

        cls.__clearup()
Пример #37
0
    def ClickAndHold(cls):
        log.step_normal("Element [%s]: Do ClickAndHold()" % (cls.__name__))

        cls.__wait()
        elements = env.BROWSER.find_elements(cls.by, cls.value)

        action = webdriver.ActionChains(env.BROWSER)
        action.click_and_hold(elements[cls.index])
        action.perform()

        cls.__clearup()
Пример #38
0
    def ReleaseClick(cls):
        log.step_normal("Element [%s]: Do ReleaseClick()" % (cls.__name__))

        cls.__wait()
        elements = env.BROWSER.find_elements(cls.by, cls.value)

        action = webdriver.ActionChains(env.BROWSER)
        action.release(elements[cls.index])
        action.perform()

        cls.__clearup()
Пример #39
0
    def IsVisible(cls):
        log.step_normal("Element [%s]: IsVisible?" % (cls.__name__))

        cls.__wait()
        elements = env.BROWSER.find_elements(cls.by, cls.value)

        if elements[cls.index].is_displayed():
            cls.__clearup()
            return True
        else:
            cls.__clearup()
            return False
Пример #40
0
def send_keys_to_dialog(title=r".*Upload.*", key_valus=r""):
    log.step_normal("send_keys_to_dialogue(%s, %s)" % (title, key_valus))

    win_dialog = WindowFinder()

    win_dialog.find_window_wildcard(title)
    win_dialog.set_foreground()

    time.sleep(2)

    SendKeys.SendKeys(key_valus)
    SendKeys.SendKeys("{ENTER}")
Пример #41
0
    def Click_No_Switch(cls):
        log.step_normal("Element [%s]: Do Click_No_Switch()" % cls.__name__)

        # cls.__wait()
        WebDriverWait(env.driver,
                      10).until(lambda the_driver: the_driver.find_element(
                          cls.by, cls.value).is_displayed())
        elements = env.driver.find_element(cls.by, cls.value)
        elements.click()
        time.sleep(3)

        cls.__clearup()
Пример #42
0
 def IsVisible(cls):
     log.step_normal("Element [%s]: IsVisible?" % (cls.__name__))
     
     cls.__wait()
     elements = env.threadlocal.BROWSER.find_elements(cls.by, cls.value)
     
     if elements[cls.index].is_displayed():
         cls.__clearup()
         return True
     else:
         cls.__clearup()
         return False
Пример #43
0
    def movetoelement(cls):
        log.step_normal("Element [%s]: Do movetoelement()" % cls.__name__)
        
        # cls.__wait()
        WebDriverWait(env.driver, 10).until(lambda the_driver:
                                            the_driver.find_element(cls.by, cls.value).is_displayed())
        element = env.driver.find_element(cls.by, cls.value)

        action = webdriver.ActionChains(env.driver)
        action.move_to_element(element)
        action.perform()
        time.sleep(3)
Пример #44
0
    def ClickList_App(cls):
        log.step_normal("Element [%s]: Do ClickList_App()" % cls.__name__)

        # cls.__wait()
        WebDriverWait(env.driver, 10).until(lambda the_driver:
                                            the_driver.find_element(cls.by, cls.value).is_displayed())
        elements = env.driver.find_elements(cls.by, cls.value)
        rd = random.randint(0, len(elements)-1)
        elements[rd].click()

        time.sleep(3)
        cls.__clearup()
Пример #45
0
    def Right_Click(cls):
        log.step_normal("Element [%s]: Do Right_Click()" % cls.__name__)

        # cls.__wait()
        WebDriverWait(env.driver, 10).until(lambda the_driver:
                                            the_driver.find_element(cls.by, cls.value).is_displayed())
        elements = env.driver.find_element(cls.by, cls.value)
        action = webdriver.ActionChains(env.driver)
        action.context_click(elements).perform()
        time.sleep(3)

        cls.__clearup()
Пример #46
0
 def IsAttribute(cls, name, value, method="contain"):
     log.step_normal("Element [%s]: IsAttribute [%s] <%s> [%s]." % (cls.__name__, name, method, value))
     
     cls.__wait()
     elements = env.threadlocal.BROWSER.find_elements(cls.by, cls.value)
     realvalue = elements[cls.index].get_attribute(name)
     
     if method.lower() == 'equal':
         if value == realvalue:
             cls.__clearup()
             return True
         else:
             cls.__clearup()
             return False
     
     elif method.lower() == 'not equal':
         if not value == realvalue:
             cls.__clearup()
             return True
         else:
             cls.__clearup()
             return False
     
     elif method.lower() == 'contain':
         if value in realvalue:
             cls.__clearup()
             return True
         else:
             cls.__clearup()
             return False
     
     elif method.lower() == 'not contain':
         if not value in realvalue:
             cls.__clearup()
             return True
         else:
             cls.__clearup()
             return False
     
     elif method.lower() == 'in':
         if realvalue in value:
             cls.__clearup()
             return True
         else:
             cls.__clearup()
             return False
     
     
     else:
         log.step_fail("code error.")
     
     cls.__clearup()