0

I'm automating a windows based desktop application(C#, LeanFT).
Clicking on a button, opens a web page in the browser.
How can I verify the web page is opened?

Adelin
  • 7,809
  • 5
  • 37
  • 65
  • Are you doing something equivalent to `Process.Run(url);`? If so, it's the **OS**es job to see that it's processed according to the url schemes registered with the OS and launching the appropriate URL handler. In turn, it's up to the registered handler (e.g.a browser) to decide how to handle the URL which may include opening a new window. Assuming that your job *isn't* to test the OS, *nor* to test a browser, then just don't. It's not usually your job to test code written by third parties. – Damien_The_Unbeliever Apr 02 '19 at 07:43

1 Answers1

0

Two ways:

  1. Brute force
    By describing the browser that was opened, which has a title, a url and other attributes, and then attaching to it.
    The problem with this approach is that, if the browser was not opened, it will throw an error, so you'll have to try..catch that error

    For example:

    /* 
     * Desktop related logic that opens a browser 
     */
    
    // Use "Attach" to connect a new (or replacement) browser tab with the LeanFT test.
    try {
        IBrowser yourPage = BrowserFactory.Attach(new BrowserDescription
        {
            Title = "The title of the page",
            Url = "https://thesitethatwasopened.com"
        });
    } catch (Exception ex) {
        // the browser was not opened
    }
    
    /* 
     * Rest of the desktop app actions 
     */
    
  2. Iterating over all opened browsers
    You'd still need the same description, but this way you can either get no browsers at all, which means that the page was not opened, or one or more browsers - in either case, this doesn't throw an error, so you can call it a "cleaner" way:

    For example:

    /* 
     * Desktop related logic that opens a browser 
     */
    
    // Use "GetAllOpenBrowsers" to get a collection of IBrowser instances that matches the description
    IBrowser[] yourPages = BrowserFactory. GetAllOpenBrowsers(new BrowserDescription
    {
        Title = "The title of the page",
        Url = "https://thesitethatwasopened.com"
    });
    
    /* 
     * Rest of the desktop app actions (maybe by making use of yourPages.Count
     */
    
Adelin
  • 7,809
  • 5
  • 37
  • 65