Tuesday, August 28, 2018

CodedUI - Generic method for identify control




using Microsoft.VisualStudio.TestTools.UITesting;
using Microsoft.VisualStudio.TestTools.UITesting.HtmlControls;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
public HtmlEdit txtProgramCodeEdit
        {
            get
            {

                {
                    if ((this.mtxtProgramCodeEdit == null))
                    {
                        this.mtxtProgramCodeEdit = new HtmlEdit(this);
                    }

                    return mtxtProgramCodeEdit;
                }
            }
        }

        private BrowserWindow mParentWindow { get; set; }

        public enum PropertyType
        {
            Name,
            Id,
            ClassName,
            ControlType
        }



        public UITestControl ParentBrowserWindowInstance { get; private set; }

  public void EnterText<T>(PropertyType type, string propertyvalue, string text) where T : HtmlControl
        {
         //   HtmlEdit ht = new HtmlEdit(ParentWindow);

            HtmlControl genericControl = (T)Activator.CreateInstance(typeof(T), new object[] { ParentWindow });
            if (type == PropertyType.Name)
                genericControl.SearchProperties[HtmlControl.PropertyNames.Name] = propertyvalue;
            else if (type == PropertyType.Id)
                genericControl.SearchProperties[HtmlControl.PropertyNames.Id] = propertyvalue;
            //Type in the UI
            Keyboard.SendKeys(genericControl, text);
        }

        public void Click(object controlType, PropertyType type, string propertyvalue)
        {
            if (controlType is HtmlButton)
            {
                HtmlButton hbtn = new HtmlButton(ParentWindow);

                if (type == PropertyType.Name)
                {
                    hbtn.SearchProperties[HtmlButton.PropertyNames.Name] = propertyvalue;
                }
                else if (type == PropertyType.Id)
                {
                    hbtn.SearchProperties[HtmlButton.PropertyNames.Id] = propertyvalue;
                    hbtn.DrawHighlight();

                   
                }
                hbtn.DrawHighlight();
                Mouse.Click(hbtn);
            }
        }

        public BrowserWindow TopParentWindow()
        {
            BrowserWindow br = new BrowserWindow();
            //br.SearchProperties[UITestControl.PropertyNames.Name] = BrowserWindow.CurrentBrowser.ToString();
            br.SearchProperties[UITestControl.PropertyNames.Name] = "CUSTOMER CONTRACT MAINTENANCE";
            return br;
        }

        public BrowserWindow ParentWindow
        {
            get
            {
                if (this.mParentWindow == null)
                {
                    this.mParentWindow = TopParentWindow();
                }
                return this.mParentWindow;
            }
        }
=================
 cr.EnterText(PropertyType.Id, "txtCustomerNo", "12345");
                cr.Click(new HtmlButton(), PropertyType.Id, "btnSave110");

Thursday, August 9, 2018

CodedUI Visual Studio: How to wait for browser load



Playback.PlaybackSettings.WaitForReadyLevel = WaitForReadyLevel.AllThreads;












for control : WaitForControlEnabled()) or

Friday, August 3, 2018

What is close and quit commands in Selenium

close( ) WebDriver command closes the Browser window which is in focus.

 quit( ) WebDriver command is generally used to shut down the WebDrivers instance

Difference between Regression Testing and Retesting?



Regression Testing
Re-Testing
Regression testing is to ensure that changes have not affected unchanged part.Retesting is done to make sure that the tests cases which failed in last execution are passed after the defects are fixed.
Regression testing is not carried out for specific defect fixes.Retesting is carried out based on the defect fixes.
In Regression testing, the test cases which passed earlier can be included to check the functionality which was working earlier.In Retesting, the cases which are failed earlier can be included to check if the functionality failure in an earlier build.
Regression test cases are derived from the functional specification, the user manuals, user tutorials, and defect reports in relation to corrected problems.Test cases for Retesting cannot be prepared before start testing. In Retesting, test cases that are failed in the prior execution are only re-executed.
Automation is the key for regression testing. Manual regression testing tends to get more expensive with each new release. Automation always complements the regression test process.Test cases for re-testing cannot be automated due to uncertainty
Defect verification doesn’t fall under Regression testing.Defect verification is coming under Retesting.
Based on the resource availability the Regression testing can be carried out in parallel with Retesting.Priority of Retesting over Regression testing is higher, so it is carried out before regression testing.

Thursday, August 2, 2018

Total number of i frames in Selenium



We can even identify total number of iframes by using below snippet.
Int size = driver.findElements(By.tagName("iframe")).size();

check if an image is displayed on page -- Selenium


string image = "";
            js.ExecuteScript("arguments[0].naturalWidth != \"undefined\" && " + "arguments[0].naturalWidth > 0", image);

---------------

second way :