Blog do projektu Open Source JavaHotel

poniedziałek, 4 lipca 2011

BoaTester - new version

I added a simple enhancement do Selenium extension to BoaTest framework. I found very annoying using long XPath selectors for GWT Presentation CellTable. It looks like:
xpath=/html/body/table/tbody/tr[2]/td[2]/table/tbody/tr[3]/td/table/tbody/tr[2]/td/table/tbody/tr/td/table/tbody/tr[2]/td[2]/div
or
xpath=/html/body/table/tbody/tr[2]/td[2]/table/tbody/tr/td/table/tbody/tr[2]/td/table/tbody/tr/td/table/tbody/tr[2]/td/div[text() = '6'] 
But - if test case is related to the same table - all that selectors share the same starting xpath. So the solution is to introduce a "macro"or interpolation just avoiding entering repeating sequences. There is very useful option in Python ConfigParser class. But action sequence (selenium.file)  for Selenium based test case is read by basic File object so this option is not available immediately. So it was necessary to implement it manually through the following procedure:
"""Replace variables using format (like ConfigParser) %(..)s
    
    Args:
      line : line to be changed
      param : TestParam 
      teparam : OneTestParam
      
    Returns:
      Fixed line
      
    Raises: 
      Exception if variable for replacement not found
      
    """


def replaceLine(line,  param,  teparam):
    while 1 :
        low = line.rfind("%(")
        if low == -1 : break
        up = line.rfind(")s")
        if up == -1 : break
        before = line[0: low]
        after = line[up+2: len(line)]
        key = line[low+2: up]
        value = teparam.getPar(key)
        if value == None : value = param.getPar(key)
        if value == None : 
            raise TestException(key + " variable for replacement not found !")
        line = before + value + after
        
    return line     

I decided to use the same syntax (%(...)s) like in ConfigParser to avoid reinventing the wheel. "Variables" for macro substitution are taken for test.properties file.

So now it is possible to put long XPath selected sharing the same theme in much simpler and less error prone manner.

test.properties
tabletestbase=xpath=/html/body/table/tbody/tr[2]/td[2]/table/tbody/tr[3]/td/table/tbody/tr[2]/td/table/tbody/tr/td/table/tbody/tr[2]/td
and Selenium action file :
isPresent : %(tabletestbase)[2]/div
waitFor :  %(tabletestbase)s/td/div[text() = '6']

Brak komentarzy:

Prześlij komentarz