-1

I want to be able to programmatically launch the default web browser on a given web page from a WinForms notification area application. I'm currently doing this with Process.Start(url). The downside of this is that if a user action triggers the launch again, they'll have two browsers open to the same page, something I'd like to avoid. I've tried tracking the Process and bringing it to the forefront, but there's no guarantee the user hasn't navigated away or closed the relevant tab. I know I can use a WebBrowser control, but would rather use the actual browser if possible. I also need the solution to work with any of the major browsers.

Now I might be barking up the wrong tree, but I stumbled across Selenium WebDrivers, which are new to me. I know it's primarily for automated testing of web applications, but have also seen a couple of articles indicating that it can be used more generally. Is it possible to use Selenium to launch a browser window and track whether it's still on the relevant web page in a production environment?

Giles
  • 1,331
  • 1
  • 15
  • 30
  • Yes. Take a look at a few basic tutorials and what you are asking is most likely covered. – JeffC Jul 19 '16 at 13:44
  • @JeffC - Can you recommend one please? I've looked at quite a few tutorials, but they all seem to start a named browser driver. What I need is to pick the driver for the _runtime_ default browser (remembering that this code is for a WinForms client, not a testing environment). I've also been browsing the APIs, but can't find anything. – Giles Jul 19 '16 at 14:31

1 Answers1

0

If I understand correctly, you want to click something on your app that launches the user's default browser, take over control of that app using something (in this case Selenium), and then do browser testing.

Launching the browser from an app. I don't think this is possible using Selenium. When you instantiate a driver using Selenium, it opens the browser for you. Selenium is also not able to "take over" an existing instance of a browser, e.g. the one your app launched.

If all your app does is launch a browser, then you should test that your app properly launches the browser and then after that, everything should be default browser behavior. You shouldn't need to test the specific browser that your app launched, you should be able to just test your site in the different browsers which is where Selenium can come into play. Write some test scenarios that run on the various browsers that test your site, etc.

If you want to determine what browser is the default, read here.

Community
  • 1
  • 1
JeffC
  • 22,180
  • 5
  • 32
  • 55
  • Thanks @JeffC. I'm not trying to test a web application at all. I have a WinForms app that allows the user to launch a third party web application in the default browser. I was wondering if I could use Selenium to make the UX better for the situation where the user launches the web page a second time. Instead of opening another browser window, I'd like it to focus the existing one, if still present. I'm not sure whether Selenium is even appropriate for a production environment. I was hoping it provided a general purpose browser API, not just one for testing. – Giles Jul 19 '16 at 15:18