How to import a javascript class and extend it in another script unit
Hi I am trying to use two Javascript projects - and export a class defined in one to be extended (inherited) in another. The example herehttps://community.smartbear.com/t5/TestComplete-General-Discussions/how-to-import-a-javascript-class/m-p/149161#M27448 shows how to use require and create an instance of the class. However, I would like to inherit the class (ES6) and define or override the methods. I was able to do this using prototype based inheritance (ES3). But unable to do this using ES6 terms. The "import" keyword usage shows syntax error "Unexpected token import". If I use require, then I cannot actually use it with extends e.g. (Note that I have shared the Parent.js into the project) //In Parent.js class ParentApp { constructor(x) { this.name = x; } } module.exports = { ParentApp: ParentApp } //In Child.js var parent = require("Parent") class Child extends parent.ParentApp { constructor(y, z) { super(y); this.age = z; } } Here the "parent.Parent" is not working. And I can't use import keyword. (Note that sometimes having the script name same as class name seems to cause issues and that's why I use Parent and ParentApp to differentiate) So how do I do this? Is ES6 fully suppported in Test Complete 14?Solved16KViews0likes6CommentsExample of evaluateJavascript() usage in Webview for Smartbearbrowser on Android device
Mobile.Device().Process("*SmartBearBrowser").FindChild("ObjectType", "WebView", 2).evaluateJavascript("(function() { return null; })();", new ValueCallback<String>() { @Override public void onReceiveValue(String s) { Log.d("LogName", s); // Prints the string 'null' NOT Java null } }); The above example doesn't seem to work (Error 100). I also can't create ValueCallback's in generell ... Mobile.Device().Process("*SmartBearBrowser").FindChild("ObjectType", "WebView", 2).evaluateJavascript(script, ???) Is were an Example on how to write the Statemant correctly in Testcomplete ?4.4KViews0likes1CommentSetup and Tear down, as well as Try Catch questions.
Hello, I am fairly new to TestComplete, so please bear with me. I am using TestComplete to test a windows application. I am more used to the NUnit side of things. In NUnit, you can have setup and teardown functions that will run before any test as well as after any test, even if there is an failure in that test. Does TestComplete have this kind of functionality? If it does not, is there any easy work around to always be in a consistent state for each test? Also, I am trying a try catch block using JavaScript in TestComplete. Basically to try to close my app, and if it cannot, catch by writing to the log. My problem is, if inside the try look, there is an error, the test just stops. So, I am unsure why it just doesnt kick to the catch, and move on like nothing is wrong. Is this expected, and if so, what is the point of try catches in TestComplete. Thanks for all of your time.3.1KViews0likes8Commentsnot able to use Drag method
Hi, I am trying to drag and drop an item from one panel to another. When i record and play the script, it works fine. But when i try to use the Drag method in my script (using javascript), it says Drag is not a function. What is possible wrong here ? Record script - let page = Aliases.pageShoppingPortal; page.panel.Drag(134, 23, 26, 182); Javascript - let memberdrag = page.contentDocument.getElementsByClassName("name cdk-drag"); memberdrag.item(1).Drag(134, 23, 26, 182);Solved2.9KViews0likes18CommentsClicking a span button
Hi, I have a span button on the webpage with this code <span class="ui-autocomplete-icon searchmode" id="Schedule-00-Row471b178a-49c2-499d-828e-f0cac7690899E-Icon"></span> I use this Javascript code in TC to point to that span button Page = Sys.Browser('*').Page("www.myweb.com"); var button = page.QuerySelector("span.searchmode"); Var button successfully find that span button. But when I do this button.ClickButton(); or button.Click(); TC complains that TypeError button.ClickButton is not a function or TypeError button.Click is not a function wondering why TC cannot click that button:mansad: Thanks.2.3KViews0likes3CommentsTestComplete javascript implementation of an Dictionary object bugged.
The code example they give for the new "getActiveXObject("Scripting.Dictionary")" implementation of a dictionary is as follows: function DictionaryDemo() { let d = getActiveXObject("Scripting.Dictionary"); // Add keys and items. d.Add("a", "Alphabet"); d.Add("b", "Book"); d.Add("c", "Coffee"); // Get the item by key. var s = d.Item("c"); Log.Message(s); // Assign a new item to the same key. d.Item("c") = "Cookie"; s = d.Item("c"); Log.Message(s); // Assign a new key to the same item. d.Key("c") = "Co"; // Remove second pair. d.Remove("b"); if (d.Exists("b")) Log.Message("The pair exists.") else Log.Message("The pair does not exist.") } This code breaks in a couple of places. The line 'd.Item("c") = "Cookie";' gives the following error: JavaScript runtime error. ReferenceError: Invalid left-hand side in assignment. The line 'd.Key("c") = "Co";' gives the following error: JavaScript runtime error. Error: Member not found.Solved2.2KViews0likes4CommentsProblem Implementing 0Auth 2.0 Authentication through Javascript Language
Hi . I am working on complex calculation project in Ready APi which has scripting language as"javaScript". We would need to implement Authentication in the Composite Project. Could anyone share the script to retrieve the token automatically through Javascript. I am able to retrieve the details automatically through Groovy but i wont be able to change the project language to groovy as it has more complex language which was implemented using Javascript. It would take more effort to change the language for this issue. Problem Statement: Need support for oAuth 2.0 Implementation using Javascript. Retrieving token automatically. So Please anyone share the code to retrieve the token automatically.2.1KViews0likes7CommentsUnable to access file names from shared network path in “Directory” Data Source
Detailed problem statement: ReadyAPI Version 2.2.0 composite project has been created with “Javascript” language. We were in need to automate the validation of the output files. When we use Directory and give shared network drive as \\<servername>\<foldername>, we were not getting any output. But if we pass directory path as absolute as “C:\SLP”, we are able to get the output. Would need help to find a way to get the output of fileNames from Directory Datasource when we give "Network path"Solved1.9KViews0likes2CommentsJavascript equivalent to these Groovy scripts
Below scripts are working fine when I use Groovy, I need same functions to work with JAVASCRIPT in the SOAP UI Pro. //Get Login URL – //"Location" is one of the value returned in the response header of step "REST Request1". Need to add this to a Project/Global property which will be refered in subsequent steps def headerValue = testRunner.testCase.getTestStepByName("REST Request1").httpRequest.response.responseHeaders["Location"][0] projectProperty = testRunner.testCase.testSuite.project.setPropertyValue( "Login_URL", headerValue.toString() ) //Get Cookie 1 – //"Set-Cookie" is one of the value returned in the response header of step "Login URL". Need to split this using regex to get the required part def cookie1 = testRunner.testCase.getTestStepByName("Login URL").httpRequest.response.responseHeaders["Set-Cookie"][1] def (var1, cookieOBconsent, var3) = cookie1.split("t=|;") log.info cookieOBconsent projectProperty = testRunner.testCase.testSuite.project.setPropertyValue( "cookie1", cookieOBconsent.toString() ) For the 1st set of code, I have tried below Javascript - //Get Login URL - var headerValue = context.expand(testRunner.getTestCase().getTestStepByName("REST Request").httpRequest.response.responseHeaders["Location"]()); log.info(headerValue); But it returns a pop up message containing the complete response string including the header "Location" and an error. The log.info dosent work. Below is the contents of pop up window (masked for confidential area) org.mozilla.javascript.EcmaError: TypeError: Cannot find function Location in object Access-Control-Expose-Headers : APIm-Debug-Trans-Id, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-Global-Transaction-ID Access-Control-Allow-Origin : * X-Backside-Transport : FAIL FAIL Connection : close location : https://^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #status# : HTTP/1.1 302 Found Content-Type : application/json .1.9KViews0likes4CommentsHow to execute JavaScript (JS) in TestComplete during Web App testing?
I have used Selenium WebDriver. In some cases it needs to use JS. For example for hidden field, it needs to use JS. I have done this in Selenium WebDriver usingJavascriptExecutor interface. Is it possible to use JS in TestComplete? If yes, how?1.8KViews0likes1Comment