Instead of hard-coding the browser name in a web test, you can modify it so that it accepts the desired browser as an external parameter.
The Run Browser and Navigate keyword operations, as well as the Browsers.Item
scripting property, allow specifying the desired browser indirectly: as an input test parameter, project variable, value retrieved from the data-driven engine and so on.
In this case, the browser that should be used in the test is specified programmatically, so, you can easily command TestComplete to perform the same test in more than one browser by passing different browser IDs (process names, constants, indexes) as test parameters.
Parameterizing Keyword Tests
-
Suppose you have recorded a keyword test that starts Internet Explorer, performs the needed test actions and then closes the browser. In this test, the browser name is assigned explicitly.
-
Now you can add test parameters. Click the Add Parameter button on the toolbar of the Keyword Test editor. In the ensuing Add Parameter wizard, create a string parameter and name it BrowserName.
-
And finally, you need to replace the hard-coded browser name in the Run Browser operation with the created BrowserName parameter.
-
That's it. Now you can call this parameterized test from another keyword test:
To call another test from keyword tests, you can use the Run Test , Run Keyword Test and Run Script Routine operations.
Also, you can call a parameterized test as a test item:
Parameterizing Script Tests
-
The recorded script test that starts Internet Explorer, performs the needed test actions and then closes the browser looks like this (note that the browser is specified as a hard-coded constant):
JavaScript, JScript
function TestControlsAndDialogs1()
{
// Launch the browser
Browsers.Item(btIExplorer).Run("http://smartbear.com");
// Test the web site
...
// Close the browser
Aliases.browser.BrowserWindow.Close();
}Python
def TestControlsAndDialogs1(): # Launch browser Browsers.Item[btIExplorer].Run('http://smartbear.com'); # Test the web site # ... # Close browser Aliases.browser.BrowserWindow.Close();
VBScript
Sub TestControlsAndDialogs1
' Launch the browser
Browsers.Item(btIExplorer).Run "http://smartbear.com"
' Test the web site
...
' Close the browser
Aliases.browser.BrowserWindow.Close
End SubDelphiScript
procedure TestControlsAndDialogs1();
begin
// Launch browser
Browsers.Item(btIExplorer).Run('http://smartbear.com');
// Test the web site
...
// Close browser
Aliases.browser.BrowserWindow.Close();
end;C++Script, C#Script
function TestControlsAndDialogs1()
{
// Launch the browser
Browsers["Item"](btIExplorer)["Run"]("http://smartbear.com");
// Test the web site
...
// Close the browser
Aliases["browser"]["BrowserWindow"]["Close"]();
} -
Transforming the recorded test into a parameterized test is as easy as adding an input parameter to a routine and replacing a hard-coded constant with a parameter name:
JavaScript, JScript
function TestControlsAndDialogs(BrowserName)
{
// Launch the browser
Browsers.Item(BrowserName).Run("http://smartbear.com");
// Test the web site
...
// Close the browser
Aliases.browser.BrowserWindow.Close();
}Python
def TestControlsAndDialogs(BrowserName): # Launch the browser Browsers.Item[BrowserName].Run("http://smartbear.com"); # Test the web site # ... # Close the browser Aliases.browser.BrowserWindow.Close();
VBScript
Sub TestControlsAndDialogs(BrowserName)
' Launch the browser
Browsers.Item(BrowserName).Run "http://smartbear.com"
' Test the web site
...
' Close the browser
Aliases.browser.BrowserWindow.Close
End SubDelphiScript
procedure TestControlsAndDialogs(BrowserName);
begin
// Launch browser
Browsers.Item(BrowserName).Run('http://smartbear.com');
// Test the web site
...
// Close browser
Aliases.browser.BrowserWindow.Close();
end;C++Script, C#Script
function TestControlsAndDialogs(BrowserName)
{
// Launch the browser
Browsers["Item"](BrowserName)["Run"]("http://smartbear.com");
// Test the web site
...
// Close the browser
Aliases["browser"]["BrowserWindow"]["Close"]();
} -
Now you can call this parameterized routine from another script test:
JavaScript, JScript
function TestSite()
{
//Test Controls and Dialogs
TestControlsAndDialogs(Browsers.btIExplorer);
TestControlsAndDialogs(Browsers.btFirefox);
TestControlsAndDialogs(Browsers.btChrome);
TestControlsAndDialogs(Browsers.btEdge);
}Python
def TestSite(): # Test Controls and Dialogs TestControlsAndDialogs(Browsers.btIExplorer); TestControlsAndDialogs(Browsers.btFirefox); TestControlsAndDialogs(Browsers.btChrome); TestControlsAndDialogs(Browsers.btOpera); TestControlsAndDialogs(Browsers.btEdge);
VBScript
Sub TestSite
'Test Controls and Dialogs
TestControlsAndDialogs(Browsers.btIExplorer)
TestControlsAndDialogs(Browsers.btFirefox)
TestControlsAndDialogs(Browsers.btChrome)
TestControlsAndDialogs(Browsers.btEdge)
End SubDelphiScript
procedure TestSite;
begin
//Test Controls and Dialogs
TestControlsAndDialogs(Browsers.btIExplorer);
TestControlsAndDialogs(Browsers.btFirefox);
TestControlsAndDialogs(Browsers.btChrome);
TestControlsAndDialogs(Browsers.btEdge);
end;C++Script, C#Script
function TestSite()
{
//Test Controls and Dialogs
TestControlsAndDialogs(Browsers["btIExplorer"]);
TestControlsAndDialogs(Browsers["btFirefox"]);
TestControlsAndDialogs(Browsers["btChrome"]);
TestControlsAndDialogs(Browsers["btEdge"]);
}-- or as a test item:
See Also
About Cross-Browser Testing in TestComplete
Running Tests in Multiple Browsers
Handling Browser Differences