Invoking supported Web Browsers via Silk4J

Invoking supported Web Browsers via Silk4J

To invoke a supported Web Browser via Silk4J, the BrowserBaseState class can used. The said class provides the method "setBrowserType" for specifying the desired browser that must be started from the test method in question, for example:

BrowserBaseState startIE = new BrowserBaseState();
startIE.setBrowserType(BrowserType.InternetExplorer);

To successfully invoke an instance of Internet Explorer, we must execute the BrowserBaseState as follows:

startIE.execute(desktop);

Therefore using the above information, to invoke all supported Browser types via Silk4J the following code can be used:

//Start Internet Explorer
BrowserBaseState ieBase = new BrowserBaseState();
ieBase.setBrowserType(BrowserType.InternetExplorer);
BrowserApplication bIE = (BrowserApplication)ieBase.execute(desktop);

//Start Firefox
BrowserBaseState ffBase = new BrowserBaseState();
ffBase.setBrowserType(BrowserType.Firefox);
BrowserApplication bFF = (BrowserApplication)ffBase.execute(desktop);

//Start Chrome
BrowserBaseState gcBase = new BrowserBaseState();
gcBase.setBrowserType(BrowserType.GoogleChrome);
BrowserApplication bGC = (BrowserApplication)gcBase.execute(desktop);

In the code above, a reference to each browser that has been invoked has been stored in the following variables:

  • bIE
  • bFF
  • bGC

These variables could be used to target automation code to execute against each running browser, via re-usable automation methods that perform common functionality across the browsers. For example, to navigate each browser to a specified URL, the following re-usable automation method that performs this functionality could be used:

public void navigateToURL(BrowserApplication browserType, String sURL){
     browserType.setActive();
     browserType.<BrowserWindow>find("/BrowserWindow").navigate(sURL);
}

To then navigate each browser to a specified URL using the above method, the following statements can be executed from the test method:

navigateToURL(bIE, "http://www.microfocus.com");
navigateToURL(bFF, "http://www.microfocus.com");
navigateToURL(bGC, "http://www.microfocus.com");

DISCLAIMER:

Some content on Community Tips & Information pages is not officially supported by Micro Focus. Please refer to our Terms of Use for more detail.
Top Contributors
Version history
Revision #:
1 of 1
Last update:
‎2013-03-13 08:22
Updated by:
 
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.