Beispiel #1
0
 def __wait(cls):
     t = 0
     while t < 300:
         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 UnexpectedAlertPresentException:
             log.step_warning("Element [%s]: UnexpectedAlertPresentException." % cls.__name__)
         
         
         if len(elements) == 0:
             time.sleep(0.5)
             log.step_normal("Element [%s]: Wait 0.5 second, By [%s :: %s :: %s]" % (cls.__name__, cls.by, cls.value, cls.index))
         else:
             if len(elements) > 1:
                 log.step_normal("Element [%s]: There are [%s] Elements!" % (cls.__name__, len(elements)))
             
             break
     
     
     if len(elements) < cls.index + 1:
         log.step_fail("Element [%s]: Element Index Issue! There are [%s] Elements! Index=[%s]" % (cls.__name__, len(elements), cls.index))
Beispiel #2
0
 def __wait(cls):
     t = 0
     while t < 300:
         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 UnexpectedAlertPresentException:
             log.step_warning("Element [%s]: UnexpectedAlertPresentException." % cls.__name__)
         
         
         if len(elements) == 0:
             time.sleep(0.5)
             log.step_normal("Element [%s]: Wait 0.5 second, By [%s :: %s :: %s]" % (cls.__name__, cls.by, cls.value, cls.index))
         else:
             if len(elements) > 1:
                 log.step_normal("Element [%s]: There are [%s] Elements!" % (cls.__name__, len(elements)))
             
             break
     
     
     if len(elements) < cls.index + 1:
         log.step_fail("Element [%s]: Element Index Issue! There are [%s] Elements! Index=[%s]" % (cls.__name__, len(elements), cls.index))
Beispiel #3
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()
Beispiel #4
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()
Beispiel #5
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()
Beispiel #6
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()
Beispiel #7
0
    def Select(cls, value):
        log.step_normal("Element [%s]: Select [%s]." % (cls.__name__, value))
        
        cls.__wait()
        elements = env.threadlocal.BROWSER.find_elements(cls.by, cls.value)
        
        is_selected = False
        
        #### select ################
        if elements[cls.index].tag_name == "select":
            options = elements[cls.index].find_elements_by_tag_name('option')

            for option in options:
#                 log.step_normal("Element [%s]: option [%s]" % (cls.__name__, option.text))
                
                if option.text == value:
                    option.click()
                    is_selected = True
                    break
        
        #### ul ################
        elif elements[cls.index].tag_name == "ul":
            lis = elements[cls.index].find_elements_by_tag_name('li')
            
            for li in lis:
#                 log.step_normal("Element [%s]: li [%s]" % (cls.__name__, li.text))
                
                if li.text == value:
                    li.click()
                    is_selected = True
                    break
        
        #### NOT Supported ################
        else:
            log.step_fail("Element [%s]: Tag [%s] NOT support [Select] method" % (cls.__name__, elements[cls.index].tag_name))
        
        
        if is_selected is False:
            log.step_fail("No item selected!")
        
        
        cls.__clearup()
Beispiel #8
0
    def Select(cls, value):
        log.step_normal("Element [%s]: Select [%s]." % (cls.__name__, value))
        
        cls.__wait()
        elements = env.threadlocal.BROWSER.find_elements(cls.by, cls.value)
        
        is_selected = False
        
        #### select ################
        if elements[cls.index].tag_name == "select":
            options = elements[cls.index].find_elements_by_tag_name('option')

            for option in options:
#                 log.step_normal("Element [%s]: option [%s]" % (cls.__name__, option.text))
                
                if option.text == value:
                    option.click()
                    is_selected = True
                    break
        
        #### ul ################
        elif elements[cls.index].tag_name == "ul":
            lis = elements[cls.index].find_elements_by_tag_name('li')
            
            for li in lis:
#                 log.step_normal("Element [%s]: li [%s]" % (cls.__name__, li.text))
                
                if li.text == value:
                    li.click()
                    is_selected = True
                    break
        
        #### NOT Supported ################
        else:
            log.step_fail("Element [%s]: Tag [%s] NOT support [Select] method" % (cls.__name__, elements[cls.index].tag_name))
        
        
        if is_selected is False:
            log.step_fail("No item selected!")
        
        
        cls.__clearup()
Beispiel #9
0
 def VerifyVisible(cls, trueORfalse):
     log.step_normal("Element [%s]: Verify Visible = [%s]." % (cls.__name__, trueORfalse))
     
     cls.__wait()
     
     elements = env.threadlocal.BROWSER.find_elements(cls.by, cls.value)
     log.step_normal("Element [%s]: Count = [%s]" % (cls.__name__, len(elements)))
     
     if elements[cls.index].is_displayed():
         if trueORfalse == True:
             log.step_pass("Visible!")
         else:
             log.step_fail("Visible!")
     else:
         if trueORfalse == False:
             log.step_pass("Not Visible!")
         else:
             log.step_fail("Not Visible!")
     
     cls.__clearup()
Beispiel #10
0
 def VerifyVisible(cls, trueORfalse):
     log.step_normal("Element [%s]: Verify Visible = [%s]." % (cls.__name__, trueORfalse))
     
     cls.__wait()
     
     elements = env.threadlocal.BROWSER.find_elements(cls.by, cls.value)
     log.step_normal("Element [%s]: Count = [%s]" % (cls.__name__, len(elements)))
     
     if elements[cls.index].is_displayed():
         if trueORfalse == True:
             log.step_pass("Visible!")
         else:
             log.step_fail("Visible!")
     else:
         if trueORfalse == False:
             log.step_pass("Not Visible!")
         else:
             log.step_fail("Not Visible!")
     
     cls.__clearup()
Beispiel #11
0
 def VerifyInnerHTMLContains(cls, contain_content):
     log.step_normal("Element [%s]: VerifyInnerHTMLContains [%s]." % (cls.__name__, str(contain_content)))
     
     cls.__wait()
     elements = env.threadlocal.BROWSER.find_elements(cls.by, cls.value)
     inner_html = elements[cls.index].get_attribute('innerHTML')
     
     if isinstance(contain_content, list):
         for content in contain_content:
             if content in inner_html:
                 log.step_pass("Real inner_hmtl=[%s]" % inner_html)
             else:
                 log.step_fail("Real inner_hmtl=[%s]" % inner_html)
             
     else:
         if contain_content in inner_html:
             log.step_pass("Real inner_hmtl=[%s]" % inner_html)
         else:
             log.step_fail("Real inner_hmtl=[%s]" % inner_html)
     
     cls.__clearup()
Beispiel #12
0
 def VerifyInnerHTMLContains(cls, contain_content):
     log.step_normal("Element [%s]: VerifyInnerHTMLContains [%s]." % (cls.__name__, str(contain_content)))
     
     cls.__wait()
     elements = env.threadlocal.BROWSER.find_elements(cls.by, cls.value)
     inner_html = elements[cls.index].get_attribute('innerHTML')
     
     if isinstance(contain_content, list):
         for content in contain_content:
             if content in inner_html:
                 log.step_pass("Real inner_hmtl=[%s]" % inner_html)
             else:
                 log.step_fail("Real inner_hmtl=[%s]" % inner_html)
             
     else:
         if contain_content in inner_html:
             log.step_pass("Real inner_hmtl=[%s]" % inner_html)
         else:
             log.step_fail("Real inner_hmtl=[%s]" % inner_html)
     
     cls.__clearup()
Beispiel #13
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()
Beispiel #14
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()
Beispiel #15
0
 def VerifyExistence(cls, trueORfalse):
     log.step_normal("Element [%s]: Verify Existence = [%s]." % (cls.__name__, trueORfalse))
     
     if trueORfalse == True:
         cls.__wait_for_appearing()
     else:
         cls.__wait_for_disappearing()
     
     elements = env.threadlocal.BROWSER.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 == True:
             log.step_pass("Exist!")
         else:
             log.step_fail("Exist!")
     else:
         if trueORfalse == False:
             log.step_pass("Not Exist!")
         else:
             log.step_fail("Not Exist!")
Beispiel #16
0
 def VerifyExistence(cls, trueORfalse):
     log.step_normal("Element [%s]: Verify Existence = [%s]." % (cls.__name__, trueORfalse))
     
     if trueORfalse == True:
         cls.__wait_for_appearing()
     else:
         cls.__wait_for_disappearing()
     
     elements = env.threadlocal.BROWSER.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 == True:
             log.step_pass("Exist!")
         else:
             log.step_fail("Exist!")
     else:
         if trueORfalse == False:
             log.step_pass("Not Exist!")
         else:
             log.step_fail("Not Exist!")
Beispiel #17
0
 def WaitForAttribute(cls, name, value, method="equal"):
     '''
     
     Example:
         NewClaim.Dates.ReminderDate.WaitForAttribute('ng-model', 'hello', method='equal')
         NewClaim.Dates.ReminderDate.WaitForAttribute('ng-model', 'hello', method='contain')
         NewClaim.Dates.ReminderDate.WaitForAttribute('ng-model', 'hello', method='not contain')
         NewClaim.Dates.ReminderDate.WaitForAttribute('ng-model', 'hello', method='in')
         NewClaim.Dates.ReminderDate.WaitForAttribute('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]: WaitForAttribute [%s] <%s> [%s]." % (cls.__name__, name, method, value))
     
     i = 0
     while True:
         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.lower() == realvalue.lower():
                 log.step_normal("Yes! real value=[%s]" % realvalue)
                 break
             else:
                 log.step_normal("No! real value=[%s]" % realvalue)
         
         elif method.lower() == 'contain':
             if value.lower() in realvalue.lower():
                 log.step_normal("Yes! real value=[%s]" % realvalue[:150])
                 break
             else:
                 log.step_normal("No! real value=[%s]" % realvalue[:150])
         
         elif method.lower() == 'not contain':
             if value.lower() in realvalue.lower():
                 log.step_normal("Yes! real value=[%s]" % realvalue[:150])
             else:
                 log.step_normal("No! real value=[%s]" % realvalue[:150])
                 break
         
         elif method.lower() == 'in':
             if realvalue.lower() in value.lower():
                 log.step_normal("Yes! real value=[%s]" % realvalue[:150])
                 break
             else:
                 log.step_normal("No! real value=[%s]" % realvalue[:150])
         
         elif method.lower() == 'not equal':
             if value.lower() == realvalue.lower():
                 log.step_normal("No! real value=[%s]" % realvalue)
             else:
                 log.step_normal("Yes! real value=[%s]" % realvalue)
                 break
         
         else:
             log.step_fail("code error.")
         
         
         i = i + 1
         if i > 90:
             log.step_fail("Not Found Expected Value! real value=[%s]" % realvalue)
             break
         
         time.sleep(1)
     
     
     cls.__clearup()
Beispiel #18
0
 def SelectByOrder(cls, order):
     log.step_normal("Element [%s]: Select by Order [%s]" % (cls.__name__, order))
     
     order = int(order)
     
     cls.__wait()
     elements = env.threadlocal.BROWSER.find_elements(cls.by, cls.value)
     
     #### ul ################
     if elements[cls.index].tag_name == "ul":
         lis = elements[cls.index].find_elements_by_tag_name('li')
         
         if order > 0:
             
             ### Wait and try more times if NO item found. ###
             t = 0
             while (len(lis) == 0):
                 lis = elements[cls.index].find_elements_by_tag_name('li')
                 time.sleep(3)
                 t = t + 1
                 log.step_normal("Element [%s]: Wait 3 Seconds for [li]" % cls.__name__)
                 
                 if t == 20 and len(lis) == 0:
                     log.step_fail("Element [%s]: List Count = [%s]." % (cls.__name__, len(lis)))
                     return
             
             
             log.step_normal("Element [%s]: List Count = [%s]." % (cls.__name__, len(lis)))
             
             if (order > len(lis)):
                 log.step_fail("Element [%s]: Not so many lists. [%s]" % (cls.__name__, len(lis)))
             else:
                 log.step_normal("Element [%s]: Do Click [%s]" % (cls.__name__, order))
                 action = webdriver.ActionChains(env.threadlocal.BROWSER)
                 
                 # Added to avoid error: "Element is no longer attached to the DOM"
                 elements = env.threadlocal.BROWSER.find_elements(cls.by, cls.value)
                 lis = elements[cls.index].find_elements_by_tag_name('li')
                 
                 action.click(lis[order-1])
                 action.perform()
                 
         else:
             log.step_fail("Order = [%s], Value Error." % order)
             
             
     #### select ################
     #### if elements[cls.index].tag_name == "select":
     else:
         options = elements[cls.index].find_elements_by_tag_name('option')
         
         if order > 0:
             
             ### Wait and try more times if NO item found. ###
             t = 0
             while (len(options) == 0):
                 options = elements[cls.index].find_elements_by_tag_name('option')
                 time.sleep(3)
                 t = t + 1
                 log.step_normal("Element [%s]: Wait 3 Seconds for [option]" % cls.__name__)
                 
                 if t == 20 and len(lis) == 0:
                     log.step_fail("Element [%s]: options Count = [%s]." % (cls.__name__, len(options)))
                     return
             
             
             log.step_normal("Element [%s]: options Count = [%s]." % (cls.__name__, len(options)))
             
             if (order > len(options)):
                 log.step_fail("Element [%s]: Not so many options. [%s]" % (cls.__name__, len(options)))
             else:
                 log.step_normal("Element [%s]: Do Click [%s]" % (cls.__name__, order))
                 action = webdriver.ActionChains(env.threadlocal.BROWSER)
                 action.click(options[order-1])
                 action.perform()
         else:
             log.step_fail("Order = [%s], Value Error." % order)
     
     
     cls.__clearup()
Beispiel #19
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()
Beispiel #20
0
 def SelectByOrder(cls, order):
     log.step_normal("Element [%s]: Select by Order [%s]" % (cls.__name__, order))
     
     order = int(order)
     
     cls.__wait()
     elements = env.threadlocal.BROWSER.find_elements(cls.by, cls.value)
     
     #### ul ################
     if elements[cls.index].tag_name == "ul":
         lis = elements[cls.index].find_elements_by_tag_name('li')
         
         if order > 0:
             
             ### Wait and try more times if NO item found. ###
             t = 0
             while (len(lis) == 0):
                 lis = elements[cls.index].find_elements_by_tag_name('li')
                 time.sleep(3)
                 t = t + 1
                 log.step_normal("Element [%s]: Wait 3 Seconds for [li]" % cls.__name__)
                 
                 if t == 20 and len(lis) == 0:
                     log.step_fail("Element [%s]: List Count = [%s]." % (cls.__name__, len(lis)))
                     return
             
             
             log.step_normal("Element [%s]: List Count = [%s]." % (cls.__name__, len(lis)))
             
             if (order > len(lis)):
                 log.step_fail("Element [%s]: Not so many lists. [%s]" % (cls.__name__, len(lis)))
             else:
                 log.step_normal("Element [%s]: Do Click [%s]" % (cls.__name__, order))
                 action = webdriver.ActionChains(env.threadlocal.BROWSER)
                 
                 # Added to avoid error: "Element is no longer attached to the DOM"
                 elements = env.threadlocal.BROWSER.find_elements(cls.by, cls.value)
                 lis = elements[cls.index].find_elements_by_tag_name('li')
                 
                 action.click(lis[order-1])
                 action.perform()
                 
         else:
             log.step_fail("Order = [%s], Value Error." % order)
             
             
     #### select ################
     #### if elements[cls.index].tag_name == "select":
     else:
         options = elements[cls.index].find_elements_by_tag_name('option')
         
         if order > 0:
             
             ### Wait and try more times if NO item found. ###
             t = 0
             while (len(options) == 0):
                 options = elements[cls.index].find_elements_by_tag_name('option')
                 time.sleep(3)
                 t = t + 1
                 log.step_normal("Element [%s]: Wait 3 Seconds for [option]" % cls.__name__)
                 
                 if t == 20 and len(lis) == 0:
                     log.step_fail("Element [%s]: options Count = [%s]." % (cls.__name__, len(options)))
                     return
             
             
             log.step_normal("Element [%s]: options Count = [%s]." % (cls.__name__, len(options)))
             
             if (order > len(options)):
                 log.step_fail("Element [%s]: Not so many options. [%s]" % (cls.__name__, len(options)))
             else:
                 log.step_normal("Element [%s]: Do Click [%s]" % (cls.__name__, order))
                 action = webdriver.ActionChains(env.threadlocal.BROWSER)
                 action.click(options[order-1])
                 action.perform()
         else:
             log.step_fail("Order = [%s], Value Error." % order)
     
     
     cls.__clearup()
Beispiel #21
0
 def WaitForAttribute(cls, name, value, method="equal"):
     '''
     
     Example:
         NewClaim.Dates.ReminderDate.WaitForAttribute('ng-model', 'hello', method='equal')
         NewClaim.Dates.ReminderDate.WaitForAttribute('ng-model', 'hello', method='contain')
         NewClaim.Dates.ReminderDate.WaitForAttribute('ng-model', 'hello', method='not contain')
         NewClaim.Dates.ReminderDate.WaitForAttribute('ng-model', 'hello', method='in')
         NewClaim.Dates.ReminderDate.WaitForAttribute('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]: WaitForAttribute [%s] <%s> [%s]." % (cls.__name__, name, method, value))
     
     i = 0
     while True:
         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.lower() == realvalue.lower():
                 log.step_normal("Yes! real value=[%s]" % realvalue)
                 break
             else:
                 log.step_normal("No! real value=[%s]" % realvalue)
         
         elif method.lower() == 'contain':
             if value.lower() in realvalue.lower():
                 log.step_normal("Yes! real value=[%s]" % realvalue[:150])
                 break
             else:
                 log.step_normal("No! real value=[%s]" % realvalue[:150])
         
         elif method.lower() == 'not contain':
             if value.lower() in realvalue.lower():
                 log.step_normal("Yes! real value=[%s]" % realvalue[:150])
             else:
                 log.step_normal("No! real value=[%s]" % realvalue[:150])
                 break
         
         elif method.lower() == 'in':
             if realvalue.lower() in value.lower():
                 log.step_normal("Yes! real value=[%s]" % realvalue[:150])
                 break
             else:
                 log.step_normal("No! real value=[%s]" % realvalue[:150])
         
         elif method.lower() == 'not equal':
             if value.lower() == realvalue.lower():
                 log.step_normal("No! real value=[%s]" % realvalue)
             else:
                 log.step_normal("Yes! real value=[%s]" % realvalue)
                 break
         
         else:
             log.step_fail("code error.")
         
         
         i = i + 1
         if i > 90:
             log.step_fail("Not Found Expected Value! real value=[%s]" % realvalue)
             break
         
         time.sleep(1)
     
     
     cls.__clearup()
Beispiel #22
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()