The information in this topic applies both to cross-platform and classic web tests.
Typically, you launch a web browser and open your tested web page in it at the beginning of a web test. However, you may also need to navigate to web pages in an already running browser. For example, you may share the same browser instance among several test steps. You can navigate to web pages in a running web browser in one of the following ways:
- By using navigation operations (as explained further in this topic).
- By simulating clicks on web page links (as explained in Simulating Mouse Actions).
From Scripts
To navigate to an URL in a running browser, you can use one of the following methods:
-
Browsers.CurrentBrowser.Navigate
- navigates to an URL in the running web browser. The browser must be launched beforehand by using theBrowsers.Item(...).Run
method or theBrowsers.RemoteItem(...).Run
method.JavaScript, JScript
function NavigateTest()
{
…
// Navigate to an URL
Browsers.CurrentBrowser.Navigate("http://smartbear.com/");
}Python
def Navigate(): ... # Navigate to an URL Browsers.CurrentBrowser.Navigate("http://smartbear.com/");
VBScript
Sub NavigateTest
…
' Navigate to an URL
Browsers.CurrentBrowser.Navigate("http://smartbear.com/")
End SubDelphiScript
procedure NavigateTest;
begin
…
// Navigate to an URL
Browsers.CurrentBrowser.Navigate('http://smartbear.com/');
end;C++Script, C#Script
function NavigateTest()
{
…
// Navigate to an URL
Browsers["CurrentBrowser"]["Navigate"]("http://smartbear.com/");
} -
Sys.Browser().ToUrl
- opens the specified URL in the browser.JavaScript, JScript
function WebTest()
{
…
// Navigate to an URL
var Page = Sys.Browser().ToUrl("http://smartbear.com/");
}Python
def BrowserToURL(): ... # Navigate to an URL Page = Sys.Browser().ToUrl("http://smartbear.com/");
VBScript
Sub WebTest
…
Dim Page
' Navigate to an URL
Set Page = Sys.Browser.ToUrl("http://smartbear.com/")
End SubDelphiScript
procedure WebTest;
var Page;
begin
…
// Navigate to an URL
Page := Sys.Browser.ToUrl('http://smartbear.com/');
end;C++Script, C#Script
function WebTest()
{
// Navigate to an URL
var Page = Sys["Browser"]()["ToUrl"]("http://smartbear.com/");
} -
Page.ToUrl
- opens the specified web page.JavaScript, JScript
function PageToURL()
{
var Page;
…
// Get a web page test object
var Page = Sys.Browser().Page("*");
// Navigate to an URL
Page.ToUrl("http://blog.smartbear.com");
}Python
def PageToURL(): ... # Get a web page test object Page = Sys.Browser().Page("*"); # Navigate to an URL Page.ToUrl("http://blog.smartbear.com");
VBScript
Sub PageToURL
Dim Page
…
' Get a web page test object
Set Page = Sys.Browser.Page("*")
' Navigate to another page
Page.ToUrl("http://blog.smartbear.com")
End SubDelphiScript
procedure PageToURL;
var Page;
begin
…
// Get a web page test object
Page := Sys.Browser.Page('*');
// Navigate to an URL
Page.ToUrl('http://blog.smartbear.com');
end;C++Script, C#Script
function PageToURL()
{
var Page;
…
// Get a web page test object
var Page = Sys["Browser"]()["Page"]("*");
// Navigate to an URL
Page["ToUrl"]("http://blog.smartbear.com");
}
All the mentioned approaches work equally well and you can choose the one that suits your needs best.
From Keyword Tests
In keyword tests, use the Navigate operation (from the Web category) to attach to a running web browser and navigate it to the specified URL.
Note: This operation does not run a new instance of the browser. It just navigates to an existing instance of the specified browser.
The operation has the following parameters:
-
Browser - the web browser to attach to. You can set this parameter to CurrentBrowser or directly specify the name of the browser to attach to.
In cross-platform web tests, always set this parameter to CurrentBrowser.
If the parameter is set to CurrentBrowser, the operation is equal to
Browsers.CurrentBrowser.Navigate
. The operation will navigate to an URL in the web browser that is current for your test. -
Url - the URL to navigate to.
- WaitTime - the time to wait until the browser loads the page and becomes ready to accept user input. If this parameter is omitted, the timeout is specified by the project's Web page loading timeout option.
For more information on the operation’s parameters, see the description of the operation.
Web (Cross-Platform)
Classic
Alternatively, you can use the On-Screen Action, Call Object Method and Run Code Snippet keyword test operations to run the scripting methods mentioned above.
Page Load Events
This is not applicable to cross-platform web tests.
When running tests in Internet Explorer, TestComplete raises a number of events when web pages are opened in the browser:
You can handle these events in your test to perform specific operations when navigating to web pages. For more information, see Creating Event Handlers for TestComplete Events.
These events are fired only when the test is run by using the Internet Explorer or Microsoft WebBrowser control. They are not raised when using other supported browsers.
See Also
How To
Connect to Device Lab and Launch Web Browser (Cross-Platform Web Tests)
Launch Web Browsers (Classic Web Tests)
Wait For Web Pages