def py_click(self, obj, objName): try: gto = GuiTestObject(obj) gto.click() return 1 except: Log.logError("Failed to click " + objName) return 0
def py_type(self, obj, friendlyName, data, verify=False): """ Types the given data into the object requested Arguments: obj -- Object to type into friendlyName -- Friendly name for the object, used in logging data -- data to type into the object Keyword Arguments: verify -- true to retrieve the text after typing and retry to type the value if it does not match the data given Returns: Resulting text contained by the given object """ try: tgto = TextGuiTestObject(obj) tgto.setText(data) if verify: RationalTestScript.sleep(0.2) if (tgto.getText() == data) == False: tgto.setText(data) return tgto.getText() except UnregisteredObjectException: Log.logError( "Failed to type " + data + " Into " + friendlyName + " because the object became unregistered.", Console.getScreenshot(), ) except WindowActivateFailedException: Log.logError( "Failed to type " + data + " Into " + friendlyName + " because it is disabled.", Console.getScreenshot() ) except ObjectIsDisposedException: Log.logError( "Failed to type " + data + " Into " + friendlyName + " because the object was disposed.", Console.getScreenshot(), ) except: exception = sys.exc_info()[1] if isinstance(exception, Exception): Log.logException(exception, "Failed to type " + data + " Into " + friendlyName) else: Log.logError("Failed to type " + data + " Into " + friendlyName, exception.__str__()) return ""
def findObjects(self, obj_start, properties): """ Finds objects with the given properties using a given starting point Arguments: obj_start -- TestObject to start looking from properties -- Array of properties representing the object(s) you want to find in form of ["Property", "Value", "Property", "Value"] Returns: Array of TestObjects found """ if (len(properties) % 2) != 0: Log.logError("Uneven number of properties given! Cannot continue.") return None prop_array = [] for i in range(0, len(properties), 2): prop_array.append(Property(properties[i], properties[i + 1])) return obj_start.find(SubitemFactory.atDescendant(prop_array), False) if obj_start else None
def py_getSelectedItemsInList(self, obj, objName): try: nameList = obj.getTestData("selected") nameListElements = nameList.getElements() items = [] for i in range(nameList.getElementCount()): try: option = nameListElements.getElement(i) items.append(str(option.getElement())) except: pass return items except: exception = sys.exc_info()[1] if isinstance(exception, Exception): Log.logException(exception, "Failed to retrieve selected items in list " + objName) else: Log.logError("Failed to retrieve selected items in list " + objName, exception.__str__()) return None
def py_select(self, obj, item, objName): try: listItems = self.py_getItemsInList(obj, objName) theObj = SelectGuiSubitemTestObject(obj) if listItems: if item.lower().startswith("index="): index = item[6:] theObj = SelectGuiSubitemTestObject(obj) theObj.select(int(index)) elif item.lower().startswith("regex="): regex = item[6:] for i in range(0, len(listItems)): if listItems[i] and re.match(regex, listItems[i], flags=0): index = i theObj.select(int(index)) else: theObj.select(item) return self.py_getSelectedItemsInList(obj, objName) else: Log.logError("No items available in list " + objName) except: exception = sys.exc_info()[1] if isinstance(exception, Exception): Log.logException(exception, "Failed to Select " + item + " in Object " + objName) else: Log.logError("Failed to Select " + item + " in Object " + objName, exception.__str__()) return []
''' Created on May 27, 2012 @author: Jarga ''' from python.screens.W3SchoolEditor import W3SchoolEditor from com.advancedrft.common.automation.rft import Log from com.advancedrft.common.io import Console if __name__ == '__main__': w3s = W3SchoolEditor(url="http://www.w3schools.com/tags/tryit.asp?filename=tryhtml_option", launch=True) w3s.type("Input Text", "<html>\n" "<body>\n" " <select id=\"exampleSelect\">\n" " <option>Volvo</option>\n" " <option>Saab</option>\n" " <option>Mercedes</option>\n" " <option>Audi</option>\n" " </select>\n" "</body>\n" "</html>\n", False) w3s.click("Edit and Click Me") selected = w3s.py_select("Example Drop Down", "Saab") Log.logTestResult("Selected 'Saab' from drop down list", None, Console.getScreenshot(), selected and selected[0] == "Saab") w3s.close()
""" Created on May 27, 2012 @author: Jarga """ import sys from com.advancedrft.common.automation.rft import Log from com.advancedrft.ibminnovate.google.finance import MainPage, CompanySummary from com.advancedrft.ibminnovate.google.finance.MainPage import IndexName, IndexStatistic from com.advancedrft.common.automation.rft.object import Browser from com.advancedrft.common.lang import StringFunctions if __name__ == "__main__": if not sys.argv: Log.logError("Must supply a company name.") # Open a new browser to the appropriate Google Finance URL theBrowser = Browser("http://finance.google.com") # Create a new instance of our Google Finance Main Page class mp = MainPage(theBrowser) # Scrape the current market index chart to the log - We're actually downloading the image file. Log.logInfo("Today's market chart", mp.getMarketChart()) # Collect statistics on the indices. # In order to limit and control things better, we made the getMarketSummary() function take two enums. # Enums are nice because they let you control how (?) for n in IndexName.values(): # @UndefinedVariable - The Java enum values() method is only created at runtime logMsg = "".join( [