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 ""
''' 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()