Pages

HOME

HOME

Thursday, 4 April 2013

How to check font of control in CodedUI

Hi Friends.Today we will see how to verify font properties of control if it is visible on page.

In CodedUI we have UITestingUtilities dll that helps us a lot in finding control or verifying control existance by providing many extended methods.This utility provides methods to check color and font properties.

In below sample code we have shown how to check font of a control.
This method works fine in web application automation.

//pre-requisite : UITestingUtilities.dll, Microsoft.CSharp , System.Core
       
public void VerifyContolFont()
{
   HtmlInputButton btnHi = UIHttplocalhostDemDocument.UIHIButton;
   IHTMLCurrentStyle btnStyle = btnHi.GetCurrentStyle();
           
  //verify font is regular or bold . for regular=400 and for bold=700
   if (btnStyle.fontWeight.ToString() != "400")
     {
      throw new AssertInconclusiveException("Font is not regular");
     }
  //Verify font family
   if (btnStyle.fontFamily.ToString() != "arial")
     {
       throw new AssertInconclusiveException("Font family is not arial");
     }
          
}

GetCurrentStyle() : This methods gets all the style properties of the control.

Pre-conditions:  Along with UITestingUtilities.dll we need to add Microsoft.CSharp , System.Core reference to avoid any reference not found errors.

To download UITestingUtilities please check this link :UITestingUtilities.dll


Enjoy Coding !!!

Sunday, 24 March 2013

How to Click or find control by scrolling page in CodedUI

Hi Friends.Today we will see how to click on control if it is visible on page and we need to scroll the page to click on it.

In CodedUI we have UITestingUtilities dll that helps us a lot in finding control or verifying control existance by providing many extended methods.

In below code sample, we have one button control on page. To click on this control manually, we need to scroll the page and then we can click on control. This can be handled through code by using EnsureClickable() method. 
Here we are first making sure that the control exists by using TryFind() method and then trying to click control.

While loop added to check if more page scroll action required. Once the control is clicked the "isClickable" variable set to true, so that to break the While() loop. The exception  is thrown if the control is still hidden on blocked by some other control , To handle this condition we have to catch the exception and instead of throwing it we are scrolling the page down.

***Here we can add while loop break logic to avoid the situation like - the method will be continuously searching for control and scrolling page down. To do this we can count the Page scroll action and if it is more than certain count then we can break while loop and throw exception (like Control not found)


CLICK IMAGE TO ZOOM IN



To download UITestingUtilities please check this link :UITestingUtilities.dll

Happy Coding!!!

Wednesday, 23 January 2013

What is DrawHighlight() and when to use it ?

Using DrawHighlight()
Today we will see how/when to use DrawHighlight() method in CodedUI. The DrawHighlight method is used to highlight a control or focus on control on web page or wpf appication form i.e. User interface.
Sometime control is available on screen and even we can map it using CodedUI TestBuilder but when we try to perform any action on it then it throws exception - control not found or Cant perform click action on hidden control(if it is button control).

So in such situation we can try using the DrawHighlight method as explained below:



In above image sample demo page shown which contains a textbox and a button.
(Here it is taken for just example)

For a textbox and button control we can use Drawhighlight as below :


 public void DrawHighlightAndClick()
        {
            HtmlInputButton btnHi = this.UIDemoWindow.UIDemoDocument.UIHIButton;
            btnHi.DrawHighlight();
            Mouse.Click(btnHi);
        }

        public void DrawHighlightAndEnterInput()
        {
            HtmlEdit txtName = this.UIDemoWindow.UIDemoDocument.UITxtaNameEdit;
            txtName.DrawHighlight();
            txtName.Text = "test1234";
        }


Similarly we can use this method for any control in CodedUI, provided that control is visible on User Interface.

Enjoy Coding !!!

Friday, 18 January 2013

UITesting utility methods in CodedUI (UITestingUtilities.dll)

UITestingUtilities

There are some useful helper/ utility methods available to access more properties of a UITestControl. This will help to extend the use of CodedUI in UI testing so that we can automate more test cases. We can use these methods by adding UITestingUtilities.dll in CodedUI Testing project.

Some of these methods are as listed below:
                      MethodName          Description




Click on image to maximize

The UITestingUtilities.dll and more information on this is available at :
UITestingUtilities.dll and Helper methods in detail

Enjoy Coding!!!