Monday, February 8, 2010

Calling Scripts Located on a Web Page From TestComplete Scripts

Select language for code samples Web Testing

Calling Scripts Located on a Web Page From TestComplete Scripts

See Also

Web pages may contain VBScript or JScript functions that perform certain actions. For example, a script function may be called upon pressing a button or clicking a hyperlink on a tested page. Sometimes it is necessary to call scripts that are located in the tested web pages from TestComplete script routines. You can call a web page script using the following syntax:

  • Internet Explorer or WebBrowser control:

    DOM model:

    Page(page_URL).document.Script.routine_name( [Parameter1, Parameter2, ...] )

    Tree or Tag model:

    Page(page_URL).Application.document.Script.routine_name( [Parameter1, Parameter2, ...] )
  • Firefox:

    DOM model:

    Page(page_URL).document.Script.routine_name( [Parameter1, Parameter2, ...] )

    Tree or Tag model:

    Page(page_URL).contentDocument.Script.routine_name( [Parameter1, Parameter2, ...] )
Note: If you use the Hybrid model, you can call scripts using both the DOM and Tree model syntax.
In DelphiScript, it is possible to call scripts located on web pages only if the Tree, Tag or Hybrid model is active. This functionality is not supported when using the DOM model.

Suppose that the tested web page holds the following HTML fragment:

HTMLCopy Code

To call the MyFunc function from TestComplete, you can access this function through the Script property of the document object. The following code demonstrates this.

Show Example

There is no relationship between the scripting language of the function located in a web page and the scripting language you use in TestComplete. As you can see, in our example we used a TestComplete VBScript routine to call a JScript function located on the tested web page.

Note that no parameter preparations are needed, because scripts on web pages and in TestComplete are OLE compatible. The only problem you may encounter are arrays. The point is that different scripting languages use different array models. The array model of a web script is compatible with the model implemented in VBScript, but it is not compatible with JScript, C++Script and C#Script (C++Script and C#Script are based on JScript and, therefore, they use the same array model). If you pass, for example, a VBScript array created in a TestComplete routine to a JScript function located on a web page, an error may occur. To solve the problem, you can use JScript’s VBArray object. For more information on this, please see MSDN (the on-line version is available at http://msdn.microsoft.com).

Web pages may not hold scripts directly, but they can load them from a file that is specified as a script source. That is, a web page may hold the following HTML code:

HTMLCopy Code

TestComplete still has access to scripts located in the script source file (in our example, it has access to scripts located in MyScriptFile.js). You can call these scripts from TestComplete routines in the same manner that was described above.

See also
Web Testing | Testing Web Pages With TestComplete

© 2010 AutomatedQA Corp.
Send feedback on this topic

19 comments:

  1. This comment has been removed by a blog administrator.

    ReplyDelete
  2. This comment has been removed by a blog administrator.

    ReplyDelete
  3. This comment has been removed by a blog administrator.

    ReplyDelete
  4. This comment has been removed by a blog administrator.

    ReplyDelete
  5. This comment has been removed by a blog administrator.

    ReplyDelete
  6. This comment has been removed by a blog administrator.

    ReplyDelete
  7. This comment has been removed by a blog administrator.

    ReplyDelete
  8. This comment has been removed by a blog administrator.

    ReplyDelete
  9. This comment has been removed by a blog administrator.

    ReplyDelete
  10. This comment has been removed by a blog administrator.

    ReplyDelete
  11. This comment has been removed by a blog administrator.

    ReplyDelete
  12. This comment has been removed by a blog administrator.

    ReplyDelete
  13. This comment has been removed by a blog administrator.

    ReplyDelete
  14. This comment has been removed by a blog administrator.

    ReplyDelete
  15. This comment has been removed by a blog administrator.

    ReplyDelete
  16. This comment has been removed by a blog administrator.

    ReplyDelete
  17. This comment has been removed by a blog administrator.

    ReplyDelete
  18. This comment has been removed by a blog administrator.

    ReplyDelete
  19. This comment has been removed by a blog administrator.

    ReplyDelete

I welcome your comment, will respond and post it at the earliest:)