Click here to Skip to main content
Click here to Skip to main content

Perform action on web application using White framework.

, 8 Dec 2011
Rate this:
Please Sign up or sign in to vote.
Using this, user would be able to transfer control from WaTiN framework to White Framework to perform action on target web site which is not provided by WaTin
Before explaining this article/tip, I assume that the reader is well aware of WaTiN and White Framework (refer to the below link to roll your eyes with WaTin and White framework).
 
Being automation engineers sometimes while automating web applications, we have to pass the browser control from one framework to another to perform some additional action/task on the target application.
 
Okay, so let's talk about some real time scenario.
 
To automate web applications, I highly concentrated on WaTin framework, as I'm good at that. But sometimes, I have to pass browser control from WaTin to White (framework for Windows application) to get focus of open browser or to bring the Browser on User Focus and/or user wants to Click at some particular coordination of browser. For that the white framework is much more comfortable for doing this.
 
To know more about White, you can refer to my link posted on this site:
White: An UI Automation tool for windows application[^]
"or"
http://white.codeplex.com/[^]
 
And to know more about WaTin framework, you can refer to the below link.
http://watin.org/[^]
 
Okay, so now come to the coding part. To achieve this, below is the piece of code doing the same.
 
I have commented each line of the code to get a clear picture about the logic of the code written. And I think rest of the things are self-explanatory.
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WatiN.Core;
using WatiN.Core.Logging;
using WatiN.Core.Native.Windows;
using White.Core;
using White.Core.UIItems;
    /// <summary>

    ///Pass the Browser control from Watin to White
    /// </summary>
    class BrowserFocus
    {
        //Instance of Internet explorer using watin
        readonly IE _browser = new IE();
        /// <summary>
        /// Method to open browser using watin
        /// </summary>
        public void AutomationUsingWaTin()
        {
            //open browser
            _browser.GoTo("www.google.com");
            _browser.WaitForComplete();
            //call white method to pass control from watin to white
            PerformActionUsingWhite();
 
        }
        /// <summary>
        /// Perform Operation on Web application using White, by passing control from WaTin To White
        /// </summary>
        private void PerformActionUsingWhite()
        {
            try
            {
                //Get the application from watin using processId
                var app = White.Core.Application.Attach(_browser.ProcessID);
                //get the open browser by watin for white
                var windows = app.GetWindows();
                White.Core.UIItems.WindowItems.Window window;
                //check whether its having browser control or not
                if (windows.Count == 1)
                {
                    window = windows[0];
                }
                else
                {//get the browser control using desktop instance
                    window = White.Core.Desktop.Instance.Windows().Find(w => w.Title.Contains(_browser.Title));
                }
                //bring the focus on Browser using white
                window.Focus();
                //Coordination of point where we want to perform right click
                var point = new System.Windows.Point(400, 500);
                //Right click on the browser using white.
                window.RightClickAt(point);
            }
            catch (Exception ex)
            {
                // This happens when one of the open windows doea not respond.
               // Logger.TraceException("White caused an exception", ex);
            }
         }
    }
 
Feel free to provide your valuable feedback and suggestions.
Thanks,
Md. Jawed
http://jawedm.blogspot.com

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

jawed.ace
Technical Lead
India India
http://jawedm.blogspot.com
 
Contact me for Freelancing at jawed.ace@gmail.com
Free to go anywhere,ready to learn anything...

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web03 | 2.8.140709.1 | Last Updated 8 Dec 2011
Article Copyright 2011 by jawed.ace
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid