Launch Browser in Incognito/Private Mode
Thought of sharing the code in the community for launching browsers in their incognito modes. The function is parameterized such a way to run for the browsers Internet Explorer, Edge, Chrome and Firefox. Hope it will be useful for more people. function runIncognitoMode(browserName){ //var browserName = "firefox" //iexplore,edge,chrome,firefox if (Sys.WaitBrowser(browserName).Exists){ var browser = Sys.Browser(browserName); Log.Enabled = false // To disable the warning that might occur during closing of the browser browser.Close(); Log.Enabled = true // enabling the logs back } if(browserName=="edge"){ Browsers.Item(btEdge).RunOptions = "-inprivate" Delay(3000) Browsers.Item(btEdge).Run(); }else if (browserName=="iexplore"){ Browsers.Item(btIExplorer).RunOptions = "-private" Delay(3000) Browsers.Item(btIExplorer).Run(); }else if (browserName=="chrome"){ Browsers.Item(btChrome).RunOptions = "-incognito" Delay(3000) Browsers.Item(btChrome).Run(); }else if (browserName=="firefox"){ Browsers.Item(btFirefox).RunOptions = "-private" Delay(3000) Browsers.Item(btFirefox).Run(); } Sys.Browser(browserName).BrowserWindow(0).Maximize() }3.8KViews8likes3CommentsCustom “On Error Actions” by having a “Raise exception” option in the on error column
Attached as a PDF is my idea in a better format! In the project window there is a drop down under the column of On Error. This field determines what TestComplete does when it encounters an error. The option of this are Continue running, Stop test item, Stop project, or Inherit from project. I would like to add one option to this called Raise exception. This would allow users to do their own error handling by wrapping their entire test function associated with the test item in a try catch statement. One use case for this would be running a test multiple times with different data (ie: Account Number). When an error occurs we would like it to move onto the next account not continue executing with this same account so continue running will not work in this case. If we use stop test item we will not be able to execute the accounts after it. This is why there should be a 5th custom option that will let you handle it yourself. This is how a test case would be structured with multiple data points (ie: account numbers) if this feature existed: def MultipleDataPointTest(): accounts = ReadAccountsNumberDataBase(querry) for account in accounts: try: #Arrange testCaseAccountNumber = int(account[0]) Log.PushLogFolder(Log.CreateFolder("Test data: " + str(testCaseAccountNumber))) #Act TestStep1() TestStep2() TestStep3() #Assert confirmValue = getValue() if(not confirmValue): Log.Error("Test Failed") Log.Error("Test Passed") CloseOpenBrowsers() Log.PopLogFolder() except Exception as e: CloseOpenBrowsers() Log.Warning("The error was: " + str(e)) Log.Warning("Moving on to next account.") Log.PopLogFolder() continue This problem arises because Smart Bears has there own error handling and when there is an error in one of the TestComplete modules it is already handled. See code below for what kind of errors throw exception when test item on continue running: #generic function to call possible functions errors def Testing(): try: #replace with any below to see result Error2() except Exception as e: Log.Warning("The error was: " + str(e)) pass # generic python error # WILL raise exception def Error1(): Log.Message(badvar) Log.Message("Still going") # Click on Object that does not exist # will NOT raise exception def Error2(): Aliases.browser.Click() Log.Message("Still going") # Enter .Keys() on Object that does not exist # will NOT raise exception def Error3(): Aliases.browser.Keys('[Enter]') Log.Message("Still going") # Log.Error(string) # will NOT raise exception def Error4(): Log.Error("Bad thing") Log.Message("Still going") # Purposeful execution raising # WILL raise exception def Error5(): Log.Error("Bad thing") raise Exception Log.Message("Still going")1.5KViews3likes1CommentIn ServiceV, how do I return a scripted response without it being overwritten in the Editor?
Hello, In one of my Virts, I have a Response typed out in XML in the Editor. I am using the "Script" tab to make Gzip and Base64 the message, as this is what our service expects. The script looks like this: def targetStream = new ByteArrayOutputStream() def zipStream = new GZIPOutputStream(targetStream) def data = mockResponse.getResponseContent().toString() zipStream.write(data.getBytes()) zipStream.close() def zipped = targetStream.toByteArray() targetStream.close() mockResponse.setResponseContent(zipped.encodeBase64()) This code "works" because it sends back the message as I expect. However, it has the side effect of changing the content of the Editor from XML to the encoded/GZipped message. Is there a way to do this so that it does not overwrite what is in the Editor. i.e. It would be beneficial to be able to see the message in plaintext. Thanks in advance.2.2KViews1like2Comments