Search code examples
c#testingcoded-ui-testswindows-media-player

Coded UI Test checking for an open Windows Media Player file


I am trying to create a Coded UI property that checks for an open WMP file.

   public BrowserWindow VideoWindow
    {
        get
        {
            if (this._videoWindow == null || !this._videoWindow.Exists)
            {
                this._videoWindow = new BrowserWindow();
                this._videoWindow.SearchProperties["Name"] = "Windows Media Player";
                this._videoWindow.SearchProperties["ControlType"] = "Window";
            }

            return this._videoWindow;
        }
    }

Obviously, this will not work. Originally, the application opened a link to a video site. So this worked, but since it is quite a bit different than a BrowserWindow I am not sure how to do it. How can I use Coded UI to "grab" it?


Solution

  • The only real difference for windows media player from the video site you've been dealing with is that windows media player will be a WpfWindow instead of a BrowserWindow -

    public WpfWindow VideoWindow
    {
        get
        {
            if (this._videoWindow == null || !this._videoWindow.Exists)
            {
                this._videoWindow = new WpfWindow();
                this._videoWindow.SearchProperties["Name"] = "Windows Media Player";
                this._videoWindow.WindowTitles.Add("Windows Media Player");
            }
    
            return this._videoWindow;
        }
    }
    

    After that, you just have to get the controls inside of the media player window(WpfControls instead of HtmlControls) to determine which file is open.