Pages

HOME

HOME

Tuesday, 30 October 2012

How to increase the test result file storage limit in CodedUI

In CodedUI the Test Result folder is created automatically. The "Test Result" is in a folder in which the solution file is located(by default).

The default file storage limit is 25 files. The files are stored in .trx format which is nothing but an XML file.

We can increase the limit as described below in 5 steps:
1. Click on "Tools". Select "Options" menu item.



 

2. "Options" pop up will be shown. Click on "Test Tools" menu item from the list.
3.  Click on "Test execution" sub menu-item.




4. Enter the integer value i.e. the number of files you want to save in Test result folder.



5. If you want to see the detail reason (if script fails) on double click on test result we need to check the checkbox.



That's it.

Enjoy Coding!!!

Saturday, 27 October 2012

How to add Timeout test settings in CodedUI

Today we will see how to add Timeout settings in CodedUI test project. It's simple just 5 steps procedure.

1. Right click on "Solution Items" folder. Select "Add" >> New Item.



2. Click on "Test Settings" templates.And click on Add button.



3. The Test settings template will be loaded. In this click on "Test Timeouts". 


4. In Test Timeouts settings we can set the timeouts for:
 a) Abort test if it exceeds the given time limit.
 b) Mark test as Failed if it exceeds the given time limit.

Enter the timeout values.



5. Click on Apply button and then Click on Close button.

The settings will be applied to the all test cases. In this way we can add Timeout settings in Test project.
# If you want to edit the timeout again then double click on "*---.testsettings" file available in "Solution Items" folder and follow the steps 3,4,5.



Enjoy Coding!!!








Tuesday, 23 October 2012

How to check Visibility of a Control (UITestControl) in CodedUI


Today we will see how to check if control is Visible or not on the User Interface. In CodedUI the UITestControl does not provide "Visible" property directly but it has some very useful methods.By using these methods we can determine/find the existence of the control on the User Interface.This method we have write in UIMap.cs file.
This is explained as below:

    using System;
    using System.Collections.Generic;
    using System.Drawing;
    using System.Windows.Input;
    using System.CodeDom.Compiler;
    using System.Text.RegularExpressions;
    using Microsoft.VisualStudio.TestTools.UITest.Extension;
    using Microsoft.VisualStudio.TestTools.UITesting;
    using Microsoft.VisualStudio.TestTools.UITesting;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using Keyboard = Microsoft.VisualStudio.TestTools.UITesting.Keyboard;
    using Mouse = Microsoft.VisualStudio.TestTools.UITesting.Mouse;
    using MouseButtons = System.Windows.Forms.MouseButtons;
    using Microsoft.VisualStudio.TestTools.UITesting.WinControls;
    
    
public partial class UIMap
  {
        //To check if control is visible or not
        public void VerifyControlVisible()
        {
            //Namespace need to include :
            //using Microsoft.VisualStudio.TestTools.UITesting;
            //using Microsoft.VisualStudio.TestTools.UITest.Extension;          

            WinText ctrlToTest = this.UICalculatorWindow.UIItem0Window.UIItem0Text;
            
//UITestControl.Exists-- METHOD CHECKS IF THE CONTROL EXIST OR NOT on User Interface.
          
          if (!ctrlToTest.Exists)
            {
                //If control is not visible or does not exist then throw exeception
                throw new AssertInconclusiveException("The given control is not visible or does not exist.");
            }

            //****UITestControl.TryFind()-- METHOD CHECKS IF THE CONTROL 
            //EXIST OR NOT on User Interface.
            //This method is MORE RELIABLE as compared to ctrlToTest.Exists . 
            //So we can get more reliable result from TryFind method 
           
           if(!ctrlToTest.TryFind())
            {
                //If control is not visible or does not exist then TryFind() will return false 
                //hence we can throw exeception
                throw new AssertInconclusiveException("The given control is not visible or does not exist.");
            }

            //Another alternative approach is using UITestControl.TryGetClickablePoint
            //This method finds the control on the User Interface and get the Clickable
            //point(i.e. position or the co-ordinates of the control)
            //Hence TryGetClickablePoint method also more reliable than the  
           //UITestControl.Exists method.
            
            Point tmpPoint;
            
            if(!ctrlToTest.TryGetClickablePoint(out tmpPoint))
            {
                //If control is not visible or does not exist then TryGetClickablePoint()
               //will return false hence we can throw exeception
                throw new AssertInconclusiveException("The given control is not visible or does not exist.");
            }

        }
    }

These are very helpful methods to find the control existence.


Enjoy Coding!!!




Monday, 15 October 2012

Creating Ordered Test in codedUI (How to create Ordered test)

Today we will see how to execute the automated test scripts in Batch. In CodedUI  we can create and execute the batch of Unit tests using Ordered test.

To create ordered test please follow the below steps:

1. Open CodedUI TestProject.
2. Click on Test tab >> New test.





3. Select Ordered Test 

-- We can give name to ordered test in Test name text box and click on OK button.

4.Then we need to select the unit test from list of available tests in the project.



5. In the Left side pane we can see the available tests.Either by double click on individual test or by selecting test and then click on ">" button will add the test to the ordered test list.To remove the test from "selected tests"- select the test from "selected tests"  list click on "<".



6.Now the very important point is to check the "continue after failure" checkbox.This ensures that if any test get failed during the ordered test execution, then the next test will be executed from the selected list.e.g In given example if "checkAddition.." test fails then the "CheckMultiplication.." will be executed. 



7. Now click on Save icon to Save the ordered test.


8. Now click on Run test and then results will be generated.
To Execute ordered test click on Test >>Windows>>Test List Editor



9. select the ordered test from the list and click on Run ordered test icon. OR by right click on the selected ordered test and select "Run checked tests"




10. The result will be shown as below:




That's it!!! .