SIGN UP MEMBER LOGIN:    
ARTICLE

Perform Action on Web Application Using White Framework

Posted by Jawed MD Articles | .NET 4.5 December 08, 2011
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.
Reader Level:
Download Files:
 

Before explain this Article/tips I assume that reader is well aware with WaTiN and White Framework (refer below link to get roll your eyes with WaTin and White framework).

Being automation engineering sometimes while automating web application we have to passes the browser control from one framework to another framework to perform some additional action/task on target application.

Okay so let's talk about some real time scenario.

To automate web application I highly concentrated on WaTin framework, as I'm good in 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 comfortable doing this.

  • To know more about White you can refer my link posted on this site

           http://www.c-sharpcorner.com/UploadFile/jawedmd/white-an-automation-framework-for-windows-application/

                                                              "or"

         http://white.codeplex.com/

  • And to know more about WaTin framework you can refer 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 lines of the code to get clear picture about logic of the code written. And I think rest of things is 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(http://jawedm.blogspot.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 you valuable feedback and suggestion.

Login to add your contents and source code to this article
share this article :
post comment
 

Thank you so much!!

Posted by Jawed MD Dec 12, 2011

You are welcome!!! and thanks once again for visiting my article

Posted by Jawed MD Dec 12, 2011

well done Prashant, it's very nice explanation............

Posted by Vikas Mishra Dec 10, 2011

Dear jawed it's a great effort for doing such task, it helps a lot thanks

Posted by Michell Johnson Dec 09, 2011

Good work

Posted by Prashant Chaudhary Dec 09, 2011
Nevron Gauge for SharePoint
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
Nevron Gauge for SharePoint
Become a Sponsor