Community in read only mode June 18 & 19
This community will be set in READ ONLY mode for a while on Tuesday June 18 into Wednesday June 19 while we import content and users from our Micro Focus Forums community site. MORE INFORMATION
Alice P_ Immanuel Absent Member.
Absent Member.
1032 views

Open and close browser in Silk4J

Jump to solution

Hi,

In my project, default project is launched by Base state, I want to open a new browser in the middle of the execution, could you please share the methods for opening, maximize and closing browser in the middle of the execution.

Thanks.

-Alice

0 Likes
2 Solutions

Accepted Solutions
Micro Focus Frequent Contributor
Micro Focus Frequent Contributor

RE: Open and close browser in Silk4J

Jump to solution

  @Test
  public void Foo()
  {
   BrowserBaseState baseState = new BrowserBaseState();
   baseState.execute(desktop);
   BrowserApplication app = desktop.find("//BrowserApplication");
   app.maximize();

   // do stuff
   app.close();
  }

Highlighted
AndySchott Absent Member.
Absent Member.

RE: Open and close browser in Silk4J

Jump to solution
The code that Johannes posted will use the information in the base state of the Silk4J project to construct the BaseState object. If the only thing you want to change from that is the URL, you can call BaseState.setURL() before calling BaseState.execute().

All of the values in the base state can be changed by calling the various set methods on the BaseState class. There are also multiple BaseState constructors that take different values that you can also call.

Andy
0 Likes
6 Replies
Micro Focus Frequent Contributor
Micro Focus Frequent Contributor

RE: Open and close browser in Silk4J

Jump to solution

  @Test
  public void Foo()
  {
   BrowserBaseState baseState = new BrowserBaseState();
   baseState.execute(desktop);
   BrowserApplication app = desktop.find("//BrowserApplication");
   app.maximize();

   // do stuff
   app.close();
  }

Alice P_ Immanuel Absent Member.
Absent Member.

RE: Open and close browser in Silk4J

Jump to solution
Thanks a lot. In middle of the execution, if the application needs input from another URL(a simulator), how to open a new browser with different URL, I believe base state will hold only one URL. Please suggest your inputs.
0 Likes
Highlighted
AndySchott Absent Member.
Absent Member.

RE: Open and close browser in Silk4J

Jump to solution
The code that Johannes posted will use the information in the base state of the Silk4J project to construct the BaseState object. If the only thing you want to change from that is the URL, you can call BaseState.setURL() before calling BaseState.execute().

All of the values in the base state can be changed by calling the various set methods on the BaseState class. There are also multiple BaseState constructors that take different values that you can also call.

Andy
0 Likes
Alice P_ Immanuel Absent Member.
Absent Member.

RE: Open and close browser in Silk4J

Jump to solution
Thanks Andy. If my understanding is correct, I can create object of base state in the middle of the code open another URL in another window while the older window remains open and then switch back my control.

How to switch control between windows?
0 Likes
AndySchott Absent Member.
Absent Member.

RE: Open and close browser in Silk4J

Jump to solution
Yes, I believe that should work. You can automate the two browser windows independently by using different locators for them. You can always use a different index for the second window, but that might not be very stable. I think that you can use the URL in the locator, so that might be a better option.

Andy
0 Likes
Alice P_ Immanuel Absent Member.
Absent Member.

RE: Open and close browser in Silk4J

Jump to solution
Thanks. While I am trying to open the new window, the old page is getting refreshed. I need both. How to achieve this?

My scenarios is based on the request code from window x, I get a response code in the window y(new one )which I will be passing to the window x.
0 Likes
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.