cancel
Showing results for 
Search instead for 
Did you mean: 

The TestComplete manuals talk about script src=<fn>... need practical example

Highlighted
Contributor

The TestComplete manuals talk about script src=<fn>... need practical example

Need help. Woman Happy


The TestComplete manuals talk about <script src=<fn>... and how to call functions from your scripts but don't actually show you an entire script example.

Smartbear manual

They say contentDocument... "It provides access to both functions defined directly on the web page as well as in external JavaScript scripts loaded by using <script src="filename.js"/>." but how do you actually 'load' the js?

In the example below I am trying to get this "Into" TestComplete.
It's simple and returns a page. (an obviously i changed the url and token)


But 'translating' that into a TC script is difficult. The manual 'almost gets me there'.
A simple yet practical example would be nice.


<HTML>
<Head>
<script src="https://c.com/sdk/js/sdk.capsvc.min.js"></script>
</HEAD>
<Body>
    <script type="text/javascript">
        SVC.authToken = 'xyz';
        
SVC.content.get({
    id: 5,
    onSuccess: function (data) {
        document.getElementById('content-area').innerHTML = data;
    },
    onFailure: function (ex) {
        alert(ex.status + ':' + ex.content);
    }
});

</script>
<DIV  id="content-area"/>
</Body>
</HTML>

1 REPLY 1
Highlighted
Contributor

Re: The TestComplete manuals talk about script src=<fn>... need practical example

First,

Create this file. It happens to be called add4.html

 

<html>
<body>
<p id="demo"> here</p>
<script>
function toCelsius(fahrenheit) {
    return (5/9) * (fahrenheit-32);
}
document.getElementById("demo").innerHTML = toCelsius(fahrenheit);
</script>
</body>
</HTML>

 

Next create a script and enter this code.

When you run the script you will see that you are accessing the page's function toCelsius

 

function getContent()
{


var  reply;
  var  myWindow;
  var  curURL;
  var playerURL = "C:\\Temp\\add4.html"
  var  page;
 
  var curPage;
  var curPanel;
  var curLink;
   var ItemID;
   ItemID = 601
  try
  {
    //******************************************************
    //Attempt to go to page
    //******************************************************
    myWindow = Sys.Browser("firefox");
    curURL =   myWindow.Page("*").URL;
    page =     myWindow.Page(curURL);
    reply = page.ToURL(playerURL)
    var fahrenheit
    fahrenheit = 77
    
//reply = page.contentDocument.Script.eval("toCelsius(fahrenheit)");

var sum = page.contentDocument.Script.toCelsius(fahrenheit);
    MessageDlg("Degrees = " + sum ,0,1,0)
    
    fahrenheit = 55
    var sum = page.contentDocument.Script.toCelsius(fahrenheit);
    MessageDlg("Degrees = " + sum ,0,1,0)

  }
 
   catch(err)
  {
      Log.Warning("There was an error on this page." + "Error description: " + err.description);   
      //restartTestonIEExplode("iexplore")
  }  
}

 

New Here?
Join us and watch the welcome video:
Building with the Collaborator API

Help Documenation
The Collaborator API is a JSON-RPC API that lets you integrate with Collaborator 9.0 and above. For more information about how the API works, check out the API description here:


Sample Plugins
For an example of an add-in that uses the API, take a look at the Microsoft Word Add-in for Collaborator:


We list all the great plugins our network has already built on this page on the SmartBear website.

Labels