private bool DoCheckElementPresent(ObjectLocator locator, bool stopOnFailure, Object customErrorMessage = null)
 {
     string objectId = locator.ActualLocator;
     bool elementFound = false;
     try
     {
         UITestControl element = FindCodedUIElement(objectId);
         elementFound = element.WaitForControlExist(1000); // wait for 1 sec
         if (elementFound)
         {
              reportResults("Check Element Present",
                        "Check Element Present command passed. Object "
                        + locator.LogicalName, LogLevel.Success);
         }
         else
         {
             throw new Exception(" Element not found");
         }
     }
     catch (Exception e)
     {
         log.Error(e);
         reportResults(stopOnFailure,
            "Check Element Present",
            "Check Element Present command failed. Object " + locator.LogicalName
            + " cannot be found in the webpage. Actual Error :  " + e.Message, LogLevel.VerificationError,
            e.StackTrace,
            customErrorMessage);
     }
     return elementFound;
 }
        public void DoMouseOver(ObjectLocator locator)
        {
            //IWebDriver driver = Driver;
            string objectId = locator.ActualLocator;
            int counter = retry;
            try
            {

                //IWebElement element = FindWebElement(objectId);
                UITestControl element = FindCodedUIElement(objectId);

                while (counter > 0)
                {
                    try
                    {
                        counter--;
                        Mouse.Hover(element);
                        //Actions builder = new Actions(driver);
                        //// call for CodedUI web driver command
                        //builder.MoveToElement(element).Build().Perform();
                        // if not exception is called consider and report the result
                        // as passed
                        reportResults(
                             "Mouse Over",
                             "Mouse Over command passed. " + locator.LogicalName,
                             LogLevel.Success
                        );
                        // if the testcase passed move out from the loop
                        break;
                    }
                    /*  catch (AssertFailedException e)
                      {
                          throw e;
                      }*/
                    catch (StaleElementReferenceException staleElementException)
                    {
                        element = FindCodedUIElement(objectId);
                        log.Warn(staleElementException);
                    }

                    catch (Exception e)
                    {
                        sleep(retryInterval);
                        if (!(counter > 0))
                        {
                            reportResults(
                             true,
                             "Mouse Over",
                             "Mouse Over command failed. Cannot access element : " + locator.LogicalName + " [" + locator.ActualLocator + "]. Actual Error: " + e.Message,
                             LogLevel.Error,
                             e.StackTrace
                             );
                        }
                    }
                }
            }
            /*catch (AssertFailedException e)
            {
                throw e;
            }*/
            catch (Exception e)
            {
                reportResults(
                          true,
                          "Mouse Over",
                          "Mouse Over command failed. Element : " + locator.LogicalName + " [" + locator.ActualLocator + "] not present. Actual Error: " + e.Message,
                          LogLevel.Error,
                          e.StackTrace
                );

            }
        }
 public void DoubleClickAt(string objectName, string identifier, string coordinateString)
 {
     String actualLocator = objectMapParser.getResolvedObjectSearchPath(objectName, identifier);
     ObjectLocator locator = new ObjectLocator(objectName, identifier, actualLocator);
     DoDoubleClickAt(locator, coordinateString);
 }
 public void CheckTable(string objectName, string identifier, string validationTypes, Object expectedValue, bool stopOnFaliure, Object customErrorMessage = null)
 {
     String actualLocator = objectMapParser.getResolvedObjectSearchPath(objectName, identifier);
     ObjectLocator locator = new ObjectLocator(objectName, identifier, actualLocator);
     DoCheckTable(locator, validationTypes, expectedValue, stopOnFaliure, customErrorMessage);
 }
 public void CheckWindowProperty(string objectName, string identifier, string propertyname, Object objExpectedvale, bool stopOnFailure, Object customErrorMessage = null)
 {
     string actualLocator = objectMapParser.getResolvedObjectSearchPath(objectName, identifier);
     ObjectLocator locator = new ObjectLocator(objectName, identifier, actualLocator);
     DoCheckWindowProperty(locator, propertyname, objExpectedvale, stopOnFailure, customErrorMessage);
 }
        private void DoSelectFrame(ObjectLocator locator)
        {
            //IWebDriver driver = Driver;
            string objectId = locator.ActualLocator;
            string objectIdValue = objectId.ToLower(CultureInfo.CurrentCulture).Trim();
            int counter = retry;
            int frameIndex = -1;
            UITestControl element = FindCodedUIElement(objectId);
            string paradigm = element.TechnologyName;

            while (counter > 0)
            {
                try
                {
                    counter--;

                    if (paradigm.Equals("Web", StringComparison.OrdinalIgnoreCase))
                    {
                        HtmlIFrame frame = new HtmlIFrame(qWin);
                        if (objectIdValue.StartsWith("index="))
                        {
                            frameIndex = int.Parse(objectId.Substring(objectId.IndexOf("=") + 1, objectId.Length).Trim());
                            frame.SetProperty(HtmlIFrame.PropertyNames.TagInstance, frameIndex);
                            frame.SetFocus();
                        }
                        else if ("parent".Equals(objectIdValue, StringComparison.OrdinalIgnoreCase) || ("null".Equals(objectIdValue, StringComparison.OrdinalIgnoreCase)))
                        {
                            //frame.
                        }
                        else
                        {
                            //check for new windows method should implement

                        }

                    }

                    /*
                    ITargetLocator target;
                    if (objectIdValue.StartsWith("index="))
                    {
                        //Should use extensions class substring
                        frameIndex = int.Parse(objectId.Substring(objectId.IndexOf("=") + 1, objectId.Length).Trim());

                        target = driver.SwitchTo();
                        target.DefaultContent();
                        target.Frame(frameIndex);
                    }
                    else if ("parent".Equals(objectIdValue, StringComparison.OrdinalIgnoreCase) || ("null".Equals(objectIdValue, StringComparison.OrdinalIgnoreCase)))
                    {
                        target = driver.SwitchTo();
                        target.DefaultContent();
                    }
                    else
                    {
                        //check for new windows method should implement
                        IWebElement element = FindWebElement(objectId);
                        target = driver.SwitchTo();
                        target.Frame(element);

                    }*/
                    reportResults("Select Frame", "Select Frame command passed. Object " + locator.LogicalName, LogLevel.Success);
                    break;
                }
                catch (Exception e)
                {
                    sleep(retryInterval);
                    if (!(counter > 0))
                    {
                        log.Error(e);
                        if (e.GetType().Equals(typeof(TimeoutException)))
                        {
                            reportResults(true, "Select Frame", "Select Frame command failed. Object " + locator.LogicalName + " cannot be found in the webpage. Actual Error :  " + e.Message, LogLevel.Error, e.StackTrace);
                        }
                        else
                        {
                            reportResults(true, "Select Frame", "Select Frame command cannot access. Object  " + locator.LogicalName + ". Actual Error :  " + e.Message, LogLevel.Error, e.StackTrace);
                        }
                    }
                }
            }
        }
        private string GetVarPropertyAttributeValue(ObjectLocator locator, UITestControl webElement, string component)
        {
            int counter = retry;
            UITestControl element = webElement;
            string returnValue = null;

            while (counter > 0) {
                try {
                    counter--;

                    returnValue = ValidateObjectProperty(element,component);

                    reportResults(
                              "Set Variable Property",
                              "Set Variable Property command passed. " + locator.LogicalName + "." + component
                              + "] ",
                              LogLevel.Success);
                    break;
                }
                catch (StaleElementReferenceException StaleElementException)
                {
                    element = FindCodedUIElement(locator.ActualLocator);
                    log.Warn(StaleElementException);
                }
                catch (Exception e)
                {
                    sleep(retryInterval);
                    /*
                     * after the retry amout, if still the object is not found,
                     * report the failure error will be based on the exception
                     * message, if e contains attribute report attribute failure
                     * else if e contains element, report object not found
                     */
                    if (!(counter > 0))
                    {
                        throw e;
                    }
                }
            }

            return returnValue;
        }
 private void DoDoubleClickAt(ObjectLocator locator, string coordinateString)
 {
     //IWebDriver driver = Driver;
     string objectId = locator.ActualLocator;
     int counter = retry;
     int xOffset = 0;
     int yOffset = 0;
     try
     {
         //IWebElement element = FindWebElement(objectId);
         UITestControl element = FindCodedUIElement(objectId);
         try
         {
             xOffset = Convert.ToInt32(coordinateString.Split(new char[] { ',' })[0]);
             yOffset = Convert.ToInt32(coordinateString.Split(new char[] { ',' })[1]);
         }
         catch (Exception e)
         {
             reportResults(true, "Double Click At", "Double Click At command failed. Object " + locator.LogicalName + ". Actual Error : Invalid coordinate string provided for the command ", LogLevel.Error, e.StackTrace);
         }
         while (counter > 0)
         {
             try
             {
                 counter--;
                 Mouse.DoubleClick(element, new Point(xOffset, yOffset));
                 //Actions doubleClickAt = new Actions(driver);
                 //doubleClickAt.MoveToElement(element, xOffset, yOffset).DoubleClick();
                 //doubleClickAt.Build().Perform();
                 reportResults("Double Click At", "Double Click At command passed. Object " + locator.LogicalName, LogLevel.Success);
                 break;
             }
             catch (Exception e)
             {
                 sleep(retryInterval);
                 if (!(counter > 0))
                 {
                     log.Error(e);
                     reportResults(true, "Double Click At", "Double Click At command failed. Object " + locator.LogicalName + ". Actual Error :  " + e.Message, LogLevel.Error, e.StackTrace);
                 }
             }
         }
     }
     catch (AssertFailedException e)
     {
         throw e;
     }
     catch (Exception e)
     {
         log.Error(e);
         reportResults(true, "Double Click At", "Double Click At command failed. Object " + locator.LogicalName + " cannot be found in the webpage. Actual Error :  " + e.Message, LogLevel.Error, e.StackTrace);
     }
 }
        private bool DoGetBooleanProperty(ObjectLocator locator, string component)
        {
            string returnValue = "";
            // retrieve the actual object ID from object repository
            string objectId = locator.ActualLocator;

            try {
                // Checking whether the element is present
                UITestControl element = FindCodedUIElement(objectId);
                returnValue = GetVarPropertyAttributeValue(locator, element, component);

            } catch (Exception e) {
                /*
                 * after the retry amout, if still the object is not found, report
                 * the failure error will be based on the exception message, if e
                 * contains attribute report attribute failure else if e contains
                 * element, report object not found
                 */

                if (e.Message.StartsWith("Attribute"))
                {

                    reportResults(
                        true,
                        "Set Variable Property",
                        "Set Variable Property command failed. Attribute : " + locator.LogicalName + "." + component
                        + " not present. Actual Error : " + e.Message,
                        LogLevel.Error,
                        e.StackTrace);

                } else if (e.Message.StartsWith("Element")) {

                    reportResults(
                        true,
                        "Set Variable Property",
                        "Set Variable Property command failed. Element : " + locator.LogicalName + "." + locator.LogicalName
                        + " not present. Actual Error : " + e.Message,
                        LogLevel.Error,
                        e.StackTrace);
                }
            }

            if ("true".Equals(returnValue,StringComparison.OrdinalIgnoreCase)  ||  "false".Equals(returnValue,StringComparison.OrdinalIgnoreCase)) {

                reportResults(
                    "Set Variable Property",
                    "Set Variable Property command passed. " + locator + " Object Value : " + returnValue,
                    LogLevel.Success);

            } else {
                reportResults(
                    true,
                    "Set Variable Property",
                    "Set Variable Property command failed. " + locator.LogicalName
                    + " Input value mismatch with boolean. User Input : " + returnValue,
                    LogLevel.Error,
                    "");
            }
            return Boolean.Parse(returnValue);
        }
        private void DoCheckTextPresent(ObjectLocator locator, bool stopOnFailure, Object customErrorMessage = null)
        {
            //IWebDriver driver = Driver;
            string objectId = locator.ActualLocator;
            int counter = retry;
            bool isTextFound = false;

            if (String.IsNullOrEmpty(objectId))
            {
                objectId = locator.LogicalName;
            }

            while (counter > 0)
            {
                try
                {
                    counter--;
                    UITestControlCollection controlCollection = qWin.CurrentDocumentWindow.GetChildren();
                    string pageSource = (string)controlCollection[0].GetProperty("OuterHtml");
                    //string pageSource = driver.PageSource;
                    if (pageSource.Contains(objectId))
                    {
                        reportResults("Check Text Present", "Check text present command passed. Text : " + objectId + ".", LogLevel.Success);
                        isTextFound = true;
                        break;
                    }

                }
                catch (Exception e)
                {
                    sleep(retryInterval);
                    if (!(counter > 0))
                    {
                        log.Error(e);
                        reportResults(stopOnFailure, "Check Text Present", "Check text present command failed. Text : " + objectId + " was not found in the webpage. Actual Error :  " + e.Message, LogLevel.Error, e.StackTrace, customErrorMessage);
                    }
                }
            }

            if(!isTextFound)
            {
                reportResults(stopOnFailure, "Check Text Present", "Check text present command failed. Text : " + objectId + " was not found in the webpage.", LogLevel.Error, "", customErrorMessage);
            }
        }
 private void DoCheckWindowProperty(ObjectLocator locator, string propertyname, Object expectedValueObj, bool stopOnFailure, Object customErrorMessage = null)
 {
     string expectedValue = CheckNullValue(expectedValueObj, "Check Window Property", stopOnFailure);
     if (propertyname.Equals(WindowValidationType.WINDOWPRESENT.ToString()))
     {
         CheckWindowPresent(locator, propertyname, expectedValue, stopOnFailure, customErrorMessage);
     }
 }
        private void DoCheckTable(ObjectLocator locator, string validationTypes, Object checkExpValueObj, bool stopOnFaliure, Object customErrorMessage = null)
        {
            string checkExpValue = CheckNullValue(checkExpValueObj, "Check Table", stopOnFaliure);
            TableValidationType validationType = (TableValidationType)Enum.Parse(typeof(TableValidationType), validationTypes, true);

            string expectedValue = CheckNullObject(checkExpValue, "CHECK TABLE");
            string objectId = locator.ActualLocator;

            //string actualLocator = objectMapParser.getResolvedObjectSearchPath(locator.LogicalName, locator.ActualLocator);

            try
            {
                //IWebElement element = FindWebElement(locator.ActualLocator);
                UITestControl element = FindCodedUIElement(objectId);

                // Call the relavant internal method based on the
                // TableValidationType provided by the user
                try
                {
                    if (validationType == TableValidationType.ROWCOUNT)
                    {
                        ValidateTableRowCount(element, locator.ActualLocator, expectedValue, stopOnFaliure);
                    }
                    else if (validationType == TableValidationType.COLCOUNT)
                    {
                        ValidateTableColCount(element, locator.ActualLocator, expectedValue, stopOnFaliure);
                    }
                    else if (validationType == TableValidationType.TABLEDATA)
                    {

                        CompareTableData(element, locator.ActualLocator, expectedValue, stopOnFaliure);
                    }
                    else if (validationType == TableValidationType.RELATIVE)
                    {

                        ValidateTableOffset(element, locator.ActualLocator, expectedValue, stopOnFaliure);
                    }
                    else if (validationType == TableValidationType.TABLECELL)
                    {

                        ValidateCellValue(element, locator.ActualLocator, expectedValue, stopOnFaliure);
                    }
                }
                catch (AssertFailedException e)
                {
                    throw e;
                }
                //catch (Exception e)
                //{
                //    // waiting for the maximum amount of waiting time before
                //    // failing the test case
                //    // Several checks were introduced to narrow down to the
                //    // failure to the exact cause.

                //    reportResults(
                //        false,
                //        "Check Table " + validationType,
                //        "Check Table command failed. Element : " + locator.LogicalName + " [" + locator.ActualLocator + "] is not accessible.",
                //        LogLevel.Error,
                //        e.StackTrace
                //    );
                //}
            }
            catch (AssertFailedException e)
            {
                throw e;
            }
            catch (Exception e)
            {
                // if object is not present catch the exception and repor the
                // error
                log.Warn(e);

                reportResults(
                      stopOnFaliure,
                      "Check Table " + validationType,
                      "Check Table command failed. Element : " + locator.LogicalName + " [" + locator.ActualLocator + "] not present. Actual Error : " + e.Message,
                      LogLevel.Error,
                      e.StackTrace,
                      customErrorMessage
                );
            }
        }
        private void DoCheckPattern(ObjectLocator locator, Object patternObj, bool stopOnFailure, Object customErrorMessage = null)
        {
            string pattern = CheckNullValue(patternObj, "Check Pattern", stopOnFailure);
            int counter = retry;
            string returnValue = "";

            string regex = GetRegexPattern(pattern);

            string objectId = locator.ActualLocator;
            try
            {

                //IWebElement element = FindWebElement(objectID);
                UITestControl element = FindCodedUIElement(objectId);

                while (counter > 0)
                {

                    try
                    {
                        counter--;

                        returnValue = element.GetProperty("Text").ToString().Trim();

                        Match match = Regex.Match(returnValue, @regex, RegexOptions.IgnoreCase);
                        if (match.Success)
                        {
                            reportResults(
                                "Check Pattern",
                                "Check Pattern command passed. " + locator.LogicalName + " : Input Pattern : " + pattern,
                                LogLevel.Success
                            );
                            break;
                        }
                        else
                        {
                            reportResults(stopOnFailure,
                              "Check Pattern",
                              "Check Pattern command failed. " + locator.LogicalName + " : Input Pattern : [" + pattern
                              + "] is different from the actual value (" + returnValue + ")",
                              LogLevel.Error,
                              "",
                              customErrorMessage
                            );
                            break;
                        }
                    }
                    catch (AssertFailedException e)
                    {
                        throw e;
                    }
                    catch (StaleElementReferenceException staleElementException)
                    {
                        element = FindCodedUIElement(objectId);
                    }
                    catch (Exception e)
                    {
                        sleep(retryInterval);

                        if (!(counter > 0))
                        {
                            string objectLogicalName = locator.LogicalName;

                            reportResults(stopOnFailure,
                               "Check Pattern",
                               "Check Pattern command failed. Cannot access element (" + locator.LogicalName + ") [" + locator.ActualLocator + "] Actual Error : " + e.Message,
                               LogLevel.Error,
                               e.StackTrace,
                               customErrorMessage
                            );
                        }
                    }
                }
            }
            catch (AssertFailedException e)
            {
                throw e;
            }
            catch (Exception e)
            {
                string objectLogicalName = locator.LogicalName;

                reportResults(stopOnFailure,
                    "Check Pattern",
                    "Check Pattern command failed. Element (" + locator.LogicalName + ") [" + locator.ActualLocator + "] not present. Actual Error : " + e.Message,
                    LogLevel.Error,
                    e.StackTrace,
                    customErrorMessage
                );
            }
        }
        private void DoCheckObjectProperty(ObjectLocator locator, string propertyName, string expectedValue, bool stopOnFailure, Object customErrorMessage = null)
        {
            //IWebDriver driver = Driver;
            string objectId = locator.ActualLocator;
            int counter = retry;
            try
            {
                UITestControl element = FindCodedUIElement(objectId);
                while (counter > 0)
                {
                    try
                    {
                        counter--;
                        string attributeValue = ValidateObjectProperty(element,
                            propertyName);

                        if (attributeValue.Trim().Equals(expectedValue.Trim()))
                        {
                            reportResults(
                                    "Check Object Property",
                                    "Check Object Property command passed" + locator.LogicalName + ". Input Value " + propertyName + expectedValue, LogLevel.Success);
                            break;
                        }
                        else
                        {
                            reportResults(
                                    stopOnFailure,
                                    "Check Object Property",
                                    "Check Object Property command failed" + locator.LogicalName + "."
                                    + propertyName + " Object property value match expected. Expected value : "
                                    + expectedValue + " is not equal to the Actual value : " + attributeValue,
                                    LogLevel.VerificationError,
                                    "",
                                    customErrorMessage);

                            break;
                        }

                    }
                    catch (AssertFailedException e)
                    {
                        throw e;
                    }
                    catch (Exception e)
                    {
                        sleep(retryInterval);
                        if (!(counter > 0))
                        {
                            log.Error(e);
                            // reportResults(false, "Type", "Type command faied. Object " + locator.LogicalName + ". Input value : " + value + ". Actual Error :  " + e.Message, LogLevel.Error, e.StackTrace);
                        }
                    }
                }
            }
            catch (AssertFailedException e)
            {
                throw e;
            }
            catch (Exception e)
            {
                log.Error(e);
                reportResults(stopOnFailure,
                            "Check Object Property",
                            "Check Object Property command failed. Object " + locator.LogicalName
                            + " cannot be found in the webpage. Actual Error :  " + e.Message,
                            LogLevel.Error,
                            e.StackTrace,
                            customErrorMessage);
            }
        }
        private void DoRightClick(ObjectLocator locator)
        {
            //IWebDriver driver = Driver;
            string objectId = locator.ActualLocator;
            int counter = retry;
            try
            {
                //IWebElement element = FindWebElement(objectId);
                UITestControl element = FindCodedUIElement(objectId);

                while (counter > 0)
                {
                    try
                    {
                        counter--;
                        Mouse.Click(element, MouseButtons.Right);
                        //Actions rightClick = new Actions(driver);
                        //rightClick.MoveToElement(element).ContextClick(element);
                        //rightClick.Build().Perform();
                        reportResults("Right Click", "Right Click command passed. Object " + locator.LogicalName, LogLevel.Success);
                        break;
                    }
                    catch (Exception e)
                    {
                        sleep(retryInterval);
                        if (!(counter > 0))
                        {
                            log.Error(e);
                            reportResults(true, "Right Click", "Right Click command failed. Object " + locator.LogicalName + ". Actual Error :  " + e.Message, LogLevel.Error, e.StackTrace);
                        }
                    }
                }
            }
            catch (AssertFailedException e)
            {
                throw e;
            }
            catch (Exception e)
            {
                log.Error(e);
                reportResults(true, "Right Click", "Right Click command failed. Object " + locator.LogicalName + " cannot be found in the webpage. Actual Error :  " + e.Message, LogLevel.Error, e.StackTrace);
            }
        }
        private double DoGetDoubleProperty(ObjectLocator locator, string component)
        {
            string returnValue = "";
            // retrieve the actual object ID from object repository

            try {
                // Checking whether the element is present
                UITestControl element = FindCodedUIElement(locator.ActualLocator);

                returnValue = GetVarPropertyAttributeValue(locator, element, component);
            }
            //put test terminated
            catch (AssertFailedException e)
            {
                throw e;
            }
            /*catch (Exception e)
            {
                if (e.Message.StartsWith("Attribute"))
                {
                    reportResults(
                     true,
                     "Set Variable Property",
                     "Set Variable Property command failed. " + locator.LogicalName + "." + component
                     + "] not present. ",
                     LogLevel.Error,
                     e.StackTrace);

                } else if (e.Message.StartsWith("Element"))
                {

                    reportResults(
                         true,
                         "Set Variable Property",
                         "Set Variable Property command failed. " + locator.LogicalName + "." + component
                         + "] not present. ",
                         LogLevel.Error,
                         e.StackTrace);
                }
            }*/

            double returnval = -1;

            try {
                returnval = Double.Parse(returnValue);
            } catch (Exception e)
            {
                reportResults(
                      true,
                      "Set Variable Property",
                      "Set Variable Property command failed. " + locator.LogicalName + "." + component
                      + ". Input value mismatch with double. User Input : " + returnValue,
                      LogLevel.Error,
                      e.StackTrace);
            }
            return returnval;
        }
        private void DoSelect(ObjectLocator locator, Object objValue)
        {
            string value = CheckNullObject(objValue, "SELECT");
            int counter = retry;
            string objectId = locator.ActualLocator;

            try
            {
                UITestControl element = FindCodedUIElement(objectId);

                while (counter > 0)
                {
                    try
                    {
                        counter--;
                        string paradigm = element.TechnologyName;
                        if (paradigm.Equals("Web", StringComparison.OrdinalIgnoreCase))
                        {
                            HtmlComboBox selectElement = (HtmlComboBox)element;
                            selectElement.SelectedItem = value;
                        }
                        else
                        {
                            WinComboBox selectElement = (WinComboBox)element;
                            selectElement.SelectedItem = value;
                        }

                        reportResults("Select", "Select command passed. Input value : "+value, LogLevel.Success);
                        break;
                    }
                    catch (Exception e)
                    {
                        sleep(retryInterval);
                        if (!(counter > 0))
                        {
                            reportResults(true, "Select", "Select command cannot access. Object " + locator.LogicalName + " . Actual Error :  " + e.Message, LogLevel.Error, e.StackTrace);
                        }
                    }

                }

            }
            catch (AssertFailedException e)
            {
                throw e;
            }
            catch (Exception e)
            {
                reportResults(true, "Select", "Select command failed. Object " + locator.LogicalName + " cannot be found in the webpage. Actual Error :  " + e.Message, LogLevel.Error, e.StackTrace);
            }
        }
        private int DoGetIntegerProperty(ObjectLocator locator, string component)
        {
            string returnValue = "";
            // retrieve the actual object ID from object repository
            string objectID = locator.ActualLocator;

            try
            {
                UITestControl element = FindCodedUIElement(objectID);
                returnValue = GetVarPropertyAttributeValue(locator, element, component);
            }
            catch (Exception e)
            {
                /*
                 * after the retry amout, if still the object is not found, report
                 * the failure error will be based on the exception message, if e
                 * contains attribute report attribute failure else if e contains
                 * element, report object not found
                 */
                if (e.Message.StartsWith("Attribute", StringComparison.OrdinalIgnoreCase))
                {
                    reportResults(
                          true,
                          "Set Variable Property",
                          "Set Variable Property command failed. Attribute : " + component + " not present."
                          + " Actual Error : " + e.Message,
                          LogLevel.Error,
                          e.StackTrace);
                }
                else if (e.Message.StartsWith("Element", StringComparison.OrdinalIgnoreCase))
                {
                    reportResults(
                          true,
                          "Set Variable Property",
                          "Set Variable Property command failed. Element : " + locator.LogicalName + " not present."
                          + " Actual Error : " + e.Message,
                          LogLevel.Error,
                          e.StackTrace);
                }
            }
            int returnval = 0;
            try
            {
                returnval = Int32.Parse(returnValue);
            } catch (Exception e)
            {
                    reportResults(
                          true,
                          "Set Variable Property",
                          "Set Variable Property command failed. " + locator.LogicalName
                          + " Input value mismatch with int. User Input : " + returnValue,
                          LogLevel.Error,
                          e.StackTrace);
            }

            return returnval;
        }
        private void DoType(ObjectLocator locator, Object valueObj)
        {
            string value = CheckNullValue(valueObj, "Type", true);

            //IWebDriver driver = Driver;
            string objectId = locator.ActualLocator;
            int counter = retry;
            try
            {
                UITestControl element = FindCodedUIElement(objectId);

                while (counter > 0)
                {
                    try
                    {
                        counter--;
                        element.SetProperty("Text","");// clear the text
                        Keyboard.SendKeys(element, value);
                        reportResults("Type", "Type command passed. Object " + locator.LogicalName + ". Input value : " + value, LogLevel.Success);
                        break;
                    }
                    catch (Exception e)
                    {
                        sleep(retryInterval);
                        if (!(counter > 0))
                        {
                            log.Error(e);
                            reportResults(true,
                                          "Type", "Type command failed. Object " + locator.LogicalName
                                          + ". Input value : " + value +
                                          ". Actual Error :  " + e.Message,
                                          LogLevel.Error,
                                          e.StackTrace);
                        }
                    }
                }
            }
            catch (AssertFailedException e)
            {
                throw e;
            }
            catch (Exception e)
            {
                log.Error(e);
                reportResults(true,
                         "Type",
                         "Type command failed. Object " + locator.LogicalName + " cannot be found in the webpage. Actual Error :  " + e.Message,
                         LogLevel.Error,
                         e.StackTrace);
            }
        }
        // Anzar
        private int DoGetObjectCount(ObjectLocator locator)
        {
            string objectId = locator.ActualLocator;
            int count = 0;
            try
            {
                UITestControl element = FindCodedUIElement(objectId);
                UITestControlCollection allMatchingUiContolCollection = element.FindMatchingControls();
                count = allMatchingUiContolCollection.Count;
                System.Diagnostics.Debug.WriteLine("GetObjectCount Result: " + count);
            }
            catch (AssertFailedException e)
            {
                throw e;
            }
            catch (Exception e)
            {
                log.Error(e);
                reportResults(true, "Get Object Count", "Get object count command failed. Actual Error :  " + e.Message, LogLevel.Error, e.StackTrace);
            }

            return count;
        }
        //-----------------------------------------------------
        private void IsElementPresent(ObjectLocator locator, string expectedValue, bool stopOnFailure, Object customErrorMessage = null)
        {
            string objectId = locator.ActualLocator;
            int counter = retry;

            while (counter > 0)
            {
                try
                {
                    counter--;

                    bool isObjectFound = DoCheckElementPresent(locator, stopOnFailure);

                    if (String.Equals(isObjectFound.ToString(), expectedValue, StringComparison.OrdinalIgnoreCase))
                    {
                        reportResults(
                            "Check Element Present",
                            "Check Element Present passed. Element : " + locator.LogicalName + ". Actual same as expected : " + expectedValue,
                            LogLevel.Success);
                        break;
                    }
                    else
                    {
                        if (counter < 1)
                        {
                            reportResults(stopOnFailure,
                            "Check Element Present",
                            "Check Element Present failed. Element : " + locator.LogicalName + ". Expected : " + expectedValue
                            + ", Actual : " + isObjectFound,
                            LogLevel.Error,
                            "",
                            customErrorMessage);
                            break;
                        }
                    }

                }
                catch (AssertFailedException e)
                {
                    throw e;
                }
                catch (Exception e)
                {
                    sleep(retryInterval);

                    reportResults(stopOnFailure,
                    "Check Element Present",
                    "Check Element Present failed. Element : " + locator.LogicalName + " is not accessible. Actual Error : " + e.Message,
                    LogLevel.Error,
                    e.StackTrace,
                    customErrorMessage);
                    break;
                }
            }
        }
        private String DoGetStringProperty(ObjectLocator locator, string component)
        {
            String returnValue = "";
            // retrieve the actual object ID from object repository
            String objectID = locator.ActualLocator;

            try
            {
                // Checking whether the element is present
                UITestControl element = FindCodedUIElement(locator.ActualLocator);

                returnValue = GetVarPropertyAttributeValue(locator, element, component);

            }
            catch (Exception e)
            {
                if (e.Message.StartsWith("Attribute",StringComparison.OrdinalIgnoreCase))
                {
                    reportResults(
                         true,
                         "Set Variable Property",
                         "Set Variable Property command failed. Atrribute (" + component + ") of  [" + locator.LogicalName
                         + "] not present. " + "Actual Error : " + e.Message,
                         LogLevel.Error,
                         e.StackTrace);
                }
                else //if (e.Message.StartsWith("Element"))
                {
                    reportResults(
                        true,
                        "Set Variable Property",
                        "Set Variable Property command failed. Element : " + locator.LogicalName
                        + " not present. " + "Actual Error : " + e.Message,
                        LogLevel.Error,
                        e.StackTrace);
                }
            }
            return returnValue;
        }
 public void CheckTextPresent(string objectName, string identifier, bool stopOnFailure, Object customErrorMessage = null)
 {
     String actualLocator = objectMapParser.getResolvedObjectSearchPath(objectName, identifier);
     ObjectLocator locator = new ObjectLocator(objectName, identifier, actualLocator);
     DoCheckTextPresent(locator, stopOnFailure, customErrorMessage);
 }
        private void DoKeyPress(ObjectLocator locator, string value)
        {
            //IWebDriver driver = Driver;
            string objectId = locator.ActualLocator;
            int counter = retry;
            try
            {
             if (value.Contains('|'))
                {
                    reportResults(true,
                        "Key Press",
                        "Key Press command failed. Input value cannot contain a pipeline symbol '|'. Object " + locator.LogicalName + ". Input value : " + value,
                        LogLevel.Error,
                        "");
                }
                char[] delemeters = { '|' };
                String[] valueStringsArr = value.Split(delemeters);
                //IWebElement element = FindWebElement(objectId);
                UITestControl element = FindCodedUIElement(objectId);

                while (counter > 0)
                {
                    try
                    {
                        counter--;

                        //Keyboard.SendKeys(element, "");

                        //element.SendKeys("");
                        //Actions focusAction = new Actions(driver);
                        //focusAction.MoveToElement(element).Build().Perform();

                        element.SetFocus();

                        for (int i = 0; i < valueStringsArr.Length; i++)
                        {
                            sleep(500);
                            List<VirtualKeyCode> list = CreateCombinationKeys(valueStringsArr[i]);
                            InputSimulator.SimulateModifiedKeyStroke(list, null);
                        }

                        reportResults("Key Press", "Key press command passed. Object " + locator.LogicalName + ". Input value : " + value, LogLevel.Success);
                        break;
                    }
                    catch (Exception e)
                    {
                        sleep(retryInterval);
                        if (!(counter > 0))
                        {
                            log.Error(e);
                            reportResults(true, "Key Press", "Key press command failed. Object " + locator.LogicalName + ". Input value : " + value + ". Actual Error :  " + e.Message, LogLevel.Error, e.StackTrace);
                        }
                    }
                }
            }
            catch (AssertFailedException e)
            {
                throw e;
            }
            catch (Exception e)
            {
                log.Error(e);
                reportResults(true, "Key Press", "Key press command failed. Object " + locator.LogicalName + " cannot be found in the webpage. Actual Error :  " + e.Message, LogLevel.Error, e.StackTrace);
            }
        }
 public void Click(string objectName, string identifier)
 {
     String actualLocator = objectMapParser.getResolvedObjectSearchPath(objectName, identifier);
     ObjectLocator locator = new ObjectLocator(objectName, identifier, actualLocator);
     DoClick(locator);
 }
        private void DoOpen(ObjectLocator locator, string waitTime)
        {
            string url = locator.ActualLocator;

            try
            {
                try
                {
                    // Resetting static values
                    qWin = null;
                    application = null;
                    if (url.ToLower().StartsWith("http://") || url.ToLower().StartsWith("https://"))
                    {
                        qWin = BrowserWindow.Launch(new System.Uri(url));
                        //qWin.WaitForControlReady(Int32.Parse(waitTime));
                    }
                    else
                    {
                        application = ApplicationUnderTest.Launch(url);
                    }
                }
                catch (Exception e)
                {
                    log.Error(e);
                }
                reportResults("Open", "Open URL : " + url, LogLevel.Success);
            }
            catch (AssertFailedException e)
            {
                throw e;
            }
            catch (Exception e)
            {
                log.Error(e);
                reportResults(true,
                         "Open",
                         "Open URL : " + url + " Failed. Actual error : " + e.Message,
                         LogLevel.Error,
                         e.StackTrace);
            }
        }
        public void DoNavigateToURL(ObjectLocator locator, Object waitTimeObj)
        {
            string waitTime = CheckNullValue(waitTimeObj, "Navigate To URL", true);
            string url = "";
            //IWebDriver driver = Driver;
            try
            {
                url = locator.ActualLocator;
                //command start time
                if (url.ToLower(CultureInfo.CurrentCulture).StartsWith("openwindow="))
                {
                    String actualUrl = url.Substring("=", url.Length);
                    BrowserWindow.Launch(new System.Uri(actualUrl));

                    /*
                    IList<String> oldWindowHandles = driver.WindowHandles;
                    String actualUrl = url.Substring("=", url.Length);
                    IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
                    js.ExecuteScript("window.open('" + actualUrl + "', '_newWindow');");
                    sleep(Convert.ToInt32(waitTime));
                    IList<String> newWindowHandles = driver.WindowHandles;
                    IList<String> newWindows = newWindowHandles.Except(oldWindowHandles).ToList();
                    driver.SwitchTo().Window(newWindows[0]);*/
                }
                else
                {
                   qWin.NavigateToUrl(new System.Uri(url));
                    /*
                    INavigation navigation = driver.Navigate();
                    navigation.GoToUrl(url);*/
                }
                reportResults("Navigate To URL", "Navigate To URL command passed. ", LogLevel.Success);

            }
            catch (Exception e)
            {
                reportResults(true, "Navigate To URL", "Navigate To URL command failed. Actual Error :  " + e.Message, LogLevel.Error, e.StackTrace);
            }
        }
        public void CheckObjectProperty(string objectName, string identifier, string propertyName, Object expectedValueObj, bool stopOnFailure, Object customErrorMessage = null)
        {
            string expectedValue = CheckNullValue(expectedValueObj, "Check Object Property", stopOnFailure);

            string actualLocator = objectMapParser.getResolvedObjectSearchPath(objectName, identifier);
            ObjectLocator locator = new ObjectLocator(objectName, identifier, actualLocator);

            if (propertyName.Equals(ValidationType.ALLOPTIONS.ToString()))
            {
                CheckAllSelections(locator, propertyName, expectedValue, stopOnFailure, customErrorMessage);
            }
            else if (propertyName.Equals(ValidationType.ELEMENTPRESENT.ToString()))
            {
                IsElementPresent(locator, expectedValue, stopOnFailure, customErrorMessage);
            }
            else if (propertyName.Equals(ValidationType.MISSINGOPTION.ToString()))
            {
                CheckMissingOption(locator, propertyName, expectedValue, stopOnFailure, customErrorMessage);
            }
            else if (propertyName.Equals(ValidationType.PROPERTYPRESENT.ToString()))
            {
                CheckPropertyPresent(locator, propertyName, expectedValue, stopOnFailure, customErrorMessage);
            }
            else if (propertyName.Equals(ValidationType.SELECTEDOPTION.ToString()))
            {
                CheckSelectedOption(locator, propertyName, expectedValue, stopOnFailure, customErrorMessage);
            }
            else
            {
                DoCheckObjectProperty(locator, propertyName, expectedValue, stopOnFailure, customErrorMessage);
            }
        }
 public bool GetBooleanProperty(string objectName, string identifier, string component)
 {
     string actualLocator = objectMapParser.getResolvedObjectSearchPath(objectName, identifier);
     ObjectLocator locator = new ObjectLocator(objectName, identifier, actualLocator);
     return DoGetBooleanProperty(locator, component);
 }
        private void CheckWindowPresent(ObjectLocator locator, string propertyname, object objExpectedValue, bool stopOnFailure, Object customErrorMessage)
        {
            //IWebDriver driver = Driver;
            string objectId = locator.ActualLocator;
            UITestControl element = FindCodedUIElement(objectId);
            int counter = retry;
            //while (counter > 0)
            //{
                try
                {
                    counter--;
                    WinWindow windowControl = element as WinWindow;
                    if (windowControl.WaitForControlExist(2000)) // 2 seconds
                    {
                        reportResults("Check Window Property", "Check window property : WindowPresent command passed"
                                                        + locator.LogicalName + ". Window " + objExpectedValue, LogLevel.Success);
                    }
                    else
                    {
                        reportResults(
                                stopOnFailure, "Check Window Property",
                                "Check window property : WindowPresent command failed. Window object " + locator.LogicalName + " with locator "
                                        + objectId + " does not match the expected condition " + objExpectedValue,
                                LogLevel.VerificationError, "", customErrorMessage);
                    }
                    /*
                    string currentWindowHandle = driver.CurrentWindowHandle;
                    string targetWindow = GetMatchingWindowFromCurrentWindowHandles(driver, objectId);
                    driver.SwitchTo().Window(currentWindowHandle);
                    string targetWindowPresentString = (!String.IsNullOrEmpty(targetWindow)).ToString();
                    if (objExpectedValue.ToString().Equals(targetWindowPresentString, StringComparison.OrdinalIgnoreCase))
                    {
                        reportResults("Check Window Property", "Check window property : WindowPresent command passed"
                                + locator.LogicalName + ". Window " + objExpectedValue, LogLevel.Success);

                        break;
                    }
                    else
                    {
                        reportResults(
                                stopOnFailure, "Check Window Property",
                                "Check window property : WindowPresent command failed. Window object " + locator.LogicalName + " with locator "
                                        + objectId + " does not match the expected condition " + objExpectedValue,
                                LogLevel.VerificationError, "", customErrorMessage);

                        break;
                    }*/

                }
                catch (AssertFailedException e)
                {
                    throw e;
                }
                catch (Exception e)
                {
                    sleep(retryInterval);
                    if (!(counter > 0))
                    {
                        log.Error(e);
                        reportResults(
                                stopOnFailure, "Check Window Property",
                                "Check window property : WindowPresent command failed. Window object " + locator.LogicalName + " with locator "
                                        + objectId + " cannot be accessed. Actual Error : " + e.Message,
                                LogLevel.VerificationError, e.StackTrace, customErrorMessage);
                    }
                }
               // }
        }