Wednesday, 17 June 2020

key value pair

private static KeyValuePair<ArrayList, ArrayList> GetXmlKeyValuePairForRiva(string XmlFile)
        {
            ArrayList node = new ArrayList();
            ArrayList value = new ArrayList();
            try
            {
                Int32 count = 500;

                String[] spearator = { "</InputXml>" };
                String[] nodeValueSpearator = { "<CosemObject Name=" };
                String[] nodeSpearator = { "\" " };
                String[] valuesSeparator = { ">" };
                String[] valueSeparator = { "</" };
                XmlFile = File.ReadAllText(@"C:\Users\asamantr\OneDrive - Itron\Desktop\Automation\DeviceCommandExport.txt");

                String[] strList = XmlFile.Split(spearator, count, StringSplitOptions.RemoveEmptyEntries);
                String[] strNodeValueDetails = strList[1].Split(nodeValueSpearator, count, StringSplitOptions.RemoveEmptyEntries);
                node.Clear();
                value.Clear();
                for (int i = 1; i < strNodeValueDetails.Length; i++)
                {
                    string xmlNode = (strNodeValueDetails[i].Split(nodeSpearator, count, StringSplitOptions.RemoveEmptyEntries))[0].Replace("\"", string.Empty);

                    string stringValueDetails = (strNodeValueDetails[i].Split(nodeSpearator, count, StringSplitOptions.RemoveEmptyEntries))[3];
                    string stringValue = (stringValueDetails.Split(valuesSeparator, count, StringSplitOptions.RemoveEmptyEntries)).Length <= 3 ? "" : stringValueDetails.Split(valuesSeparator, count, StringSplitOptions.RemoveEmptyEntries)[3];

                    string xmlNodeValue = xmlNode == string.Empty || (stringValue.StartsWith("\r\n") || stringValue == string.Empty) ? "" : stringValue.Split(valueSeparator, count, StringSplitOptions.RemoveEmptyEntries)[0];

                    node.Add(xmlNode);
                    value.Add(xmlNodeValue);
                }
            }
            catch (Exception ex)
            {

            }
            return new KeyValuePair<ArrayList, ArrayList>(node, value);
        }

xml merge file

private static void MergeTwoXmlFile(string xmlFile1, string xmlFile2, string mergeFileNameLocation)
        {
            try
            {
                IList<string> duplicateNodes = new List<string>();

                xmlFile1 = @"C:\Ashutosh\Automation\xml files\CellularCheck_BaseLine.xml";
                xmlFile2 = @"C:\Ashutosh\Automation\xml files\CellularCheck_BaseLine_File.xml";
                mergeFileNameLocation = @"C:\Users\asamantr\Source\Repos\ConsoleApp4\ConsoleApp4\Temp";

                XmlDocument doc1 = new XmlDocument();
                XmlDocument doc2 = new XmlDocument();

                XElement rootFile1 = XElement.Load(xmlFile1);
                XElement rootFile2 = XElement.Load(xmlFile2);

                if (File.Exists("" + mergeFileNameLocation + "\\" + "Test_CellularCheck_BaseLine.xml"))
                    File.Delete("" + mergeFileNameLocation + "\\" + "Test_CellularCheck_BaseLine.xml");
                if (!Directory.Exists(mergeFileNameLocation))
                    Directory.CreateDirectory(mergeFileNameLocation);


                doc1.LoadXml(rootFile1.ToString());
                doc2.LoadXml(rootFile2.ToString());
                XmlNodeList list1 = doc1.GetElementsByTagName("root");
                XmlNodeList list2 = doc2.GetElementsByTagName("root");

                foreach (XmlNode node1 in list1)
                {
                    foreach (XmlNode childNode1 in node1.ChildNodes)
                    {
                        foreach (XmlNode node2 in list2)
                        {
                            foreach (XmlNode childNode2 in node2.ChildNodes)
                            {
                                if (childNode1.Name == childNode2.Name)
                                {
                                    duplicateNodes.Add(childNode1.Name);
                                }
                            }
                        }
                    }
                }

                for (int i = 0; i < duplicateNodes.Count(); i++)
                    rootFile2.Element(duplicateNodes[i]).Remove();

                rootFile1.Add(rootFile2.Elements());
                rootFile1.Save(@"C:\Users\asamantr\Source\Repos\ConsoleApp4\ConsoleApp4\Temp\Test_CellularCheck_BaseLine.xml");
            }
            catch (Exception ex)
            {
                //return false;
                //throw;
            }
        }

xml compare file

public bool CompareXml(string SourceFile, string DestinationFile, string[] SkipValues = null, string DiffFileNameWithPath = null)
        {
            try
            {
                bool bIdentical = false;
                //SourceFile = @"C:\FDMXml\NewFile\100W_CheckEndpointOperation_13_27_38.xml";
                //DestinationFile = @"C:\FDMXml\OldFile\100W_CheckEndpointOperation_13_27_38.xml";
                //SkipValues = XmlSkipValues.XmlSkipValues100W;

                string tempFile1 = @"C:\temp\tempfile1.xml";
                string tempFile2 = @"C:\temp\tempfile2.xml";

                XElement rootFile1 = XElement.Load(SourceFile);
                XElement rootFile2 = XElement.Load(DestinationFile);

                for (int i = 0; i < SkipValues.Length; i++)//only hot fix operations
                {
                    rootFile1.Element(SkipValues[i]).Remove();
                    rootFile2.Element(SkipValues[i]).Remove();
                }
                if (File.Exists(@"C:\temp\tempfile1.xml"))
                    File.Delete(tempFile1);
                if (File.Exists(@"C:\temp\tempfile2.xml"))
                    File.Delete(tempFile2);

                rootFile1.Save(tempFile1);
                rootFile2.Save(tempFile2);

                if (String.IsNullOrEmpty(DiffFileNameWithPath))
                    DiffFileNameWithPath = "Diff";
                string diffPath = @"C:\FDMXml\" + DiffFileNameWithPath + ".xml";
                if (!Directory.Exists(DiffFileNameWithPath))
                    Directory.CreateDirectory(DiffFileNameWithPath);

                StringBuilder differenceStringBuilder = new StringBuilder();

                using (FileStream fs = new FileStream(diffPath, FileMode.Create))
                {
                    XmlWriter diffGramWriter = XmlWriter.Create(fs);
                    //XmlDiff diff = new XmlDiff();
                    XmlDiff xmldiff = new XmlDiff(XmlDiffOptions.IgnoreChildOrder |
                                            XmlDiffOptions.IgnoreNamespaces |
                                            XmlDiffOptions.IgnorePrefixes);
                    bIdentical = xmldiff.Compare(tempFile1, tempFile2, false, diffGramWriter);

                    diffGramWriter.Close();
                }

                File.Delete(tempFile1);
                File.Delete(tempFile2);

                StaticTestData.xmlSourceFileName = string.Empty;
                return bIdentical;
            }
            catch (Exception ex)
            {
                return false;
                //throw;
            }
        }

Friday, 17 April 2020

string split

Int32 count = 500;
            String[] spearator = { "=","\""};
            String[] strlist = strMyXml.Split(spearator, count,StringSplitOptions.RemoveEmptyEntries);

Thursday, 16 April 2020

xml Create xml file


public static void CreateXmlFile(string FolderName, string FileName, string strMyXml)
        {
            FolderName = "100G";
            FileName = "GridData";
            strMyXml = "<Employee>" +
                                   "<firstName>" + "Santosh" + "</firstName>" +
                                   "<lastName>" + "Sahoo" + "</lastName>" +
                        "</Employee>";

            string path = @"C:\FDMXml\" + FolderName + "";
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            XmlDocument doc = new XmlDocument();
            doc.LoadXml(strMyXml);
            doc.Save(path + "\\" + "" + FileName + "" + ".xml");
        }

Friday, 23 August 2019

Automation Selenium Take a Screen Shot

 public void TakeScreenshot(string fileName, string screenshotPath = null, IWebDriver driver = null)
        {
            Screenshot s = ((ITakesScreenshot)driver).GetScreenshot();//driver = new ChromeDriver();
            var path = @"C:\Ashutosh";

            if (!string.IsNullOrEmpty(screenshotPath))
            {
                path = screenshotPath;
            }

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            s.SaveAsFile(Path.Combine(screenshotPath, fileName + DateTime.Now.ToString("MM-dd-yyyy-HHmmss")), ScreenshotImageFormat.Png);
        }

Wednesday, 14 August 2019

Automation Selenium

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Threading;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.UI;

namespace AshuPractice
{
    [TestClass]
    public class FirstTestClass
    {
        IWebDriver driver;

        [TestMethod]
        public void ChromeMethod()
        {
            string actualResult;
            string expectedResult = "Google";
            driver = new ChromeDriver();
            driver.Navigate().GoToUrl("https://google.co.in/");
            driver.Manage().Window.Maximize();
            actualResult = driver.Title;
            if (actualResult.Contains(expectedResult))
            {
                Debug.WriteLine("Test Case Passed");
                Assert.IsTrue(true, "Test Case Passed");
            }
            else
            {
                Debug.WriteLine("Test Case Failed");
            }
            Thread.Sleep(2000);
            driver.Close();
            driver.Quit();
        }
        [TestMethod]
        public void WikiSearch()
        {
            driver = new ChromeDriver();
            driver.Navigate().GoToUrl("https://www.wikipedia.org/");
            driver.Manage().Window.Maximize();
            driver.FindElement(By.XPath("//*[@id='searchInput']")).SendKeys("selenuim");
            driver.FindElement(By.XPath("//*[@id='search-form']/fieldset/button/i")).Click();
            Thread.Sleep(2000);
            driver.Close();
            driver.Quit();
        }
        [TestMethod]
        public void ReadOnlyCollection()
        {
            driver = new ChromeDriver();
            driver.Navigate().GoToUrl("https://www.wikipedia.org/");
            driver.Manage().Window.Maximize();

            //ReadOnlyCollection<IWebElement> anchorLists = driver.FindElements(By.TagName("a"));
            IList<IWebElement> anchorLists = driver.FindElements(By.TagName("a"));
            foreach (var item in anchorLists)
            {
                if (item.Text != "")
                    if (item.Text.Contains("English"))
                    {
                        item.Click();
                        break;
                    }
            }

            Thread.Sleep(2000);
            driver.Close();
            driver.Quit();
        }
        [TestMethod]
        public void GetDropDownValue()
        {
            driver = new ChromeDriver();
            driver.Navigate().GoToUrl("https://www.wikipedia.org/");
            driver.Manage().Window.Maximize();

            IList<IWebElement> languages = new List<IWebElement>();
            languages = (driver.FindElement(By.XPath("//*[@id='searchLanguage']"))).FindElements(By.TagName("option"));
            foreach (var language in languages)
            {
                if (language.Text == "Dansk")
                {
                    SelectElement selectElement = new SelectElement(driver.FindElement(By.XPath("//*[@id='searchLanguage']")));
                    selectElement.SelectByText(language.Text);
                    break;
                }
            }
            Thread.Sleep(2000);
            driver.Close();
            driver.Quit();
        }
        [TestMethod]
        public void TwitterLogin()
        {

        }
    }   
}

Thursday, 8 August 2019

Automation selenium Scrolling and upload file

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
using System.Windows.Forms;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Interactions;
using OpenQA.Selenium.Support.UI;


namespace AshuPractice
{

    [TestClass]
    public class UnitTest1
    {

        IWebDriver driver1;
        [TestMethod]
        public void TestMethod1()
        {

            // Open the browser for Automation
            IWebDriver driver = new ChromeDriver();

            driver.Manage().Window.Maximize();

            // WebPage which contains a WebTable
            driver.Navigate().GoToUrl("https://www.toolsqa.com/automation-practice-form/?firstname=&lastname=&sex=Male&exp=1&photo=&continents=Asia&submit=");
            //driver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(30));
            //driver.Manage().Timeouts().
            Thread.Sleep(5000);

            // Below code is for scrolling
            var element = driver.FindElement(By.XPath("//*[@id='content']/div[1]/div/div/div/div[2]/div/form/fieldset/div[29]"));
            Actions actions = new Actions(driver);
            actions.MoveToElement(element);
            actions.Perform();         

            //Below code is for uploading
            (driver.FindElement(By.XPath("//*[@id='photo']"))).Click();
            Thread.Sleep(5000);
            SendKeys.SendWait("C:\\Users\\asamantr\\OneDrive - Itron\\Desktop\\New folder\\New Text Document.txt");
            SendKeys.SendWait(@"{Enter}"); //NameSpace using System.Windows.Forms         

            Thread.Sleep(5000);
            driver.Quit();
        }
    }
}

Monday, 5 August 2019

Automation Selenium Control Actions

using Itron.FDM.SQA.VSAutomation.Framework.Reporting;
using OpenQA.Selenium;
using OpenQA.Selenium.Appium.Windows;
using OpenQA.Selenium.Interactions;
using OpenQA.Selenium.Support.UI;
using System;
using System.Threading;

namespace Itron.FDM.SQA.VSAutomation.Framework.SeleniumUtilities
{
    public class ControlActions
    {
        private static ExtentReporter TestReport = SessionFactory.GetReport();

        public static bool IsElementExists(IWebElement element)
        {
            bool exists = false;

            try
            {
                exists = element.Displayed;
                return exists;
            }
            catch
            {
                return false;
            }
        }

        /// <summary>
        /// <param name="element"></param>
        /// <param name="intervalToWaitInMilliSecs"></param>
        /// <param name="loopCount - The total wait time will be loopcount * intervalToWaitInMilliSecs"></param>
        /// <returns></returns>
        /// </summary>
        public static bool IsElementExistsWithWait(IWebElement element, int loopCount = 20, int intervalToWaitInMilliSecs = 500)
        {
            int attempt = 0;
            bool exists = false;

            if (element != null)
            {
                do
                {
                    try
                    {
                        exists = element.Displayed;

                        if (exists)
                        {
                            break;
                        }
                        else
                        {
                            attempt++;
                            Thread.Sleep(intervalToWaitInMilliSecs);
                        }
                    }
                    catch (Exception ex)
                    {
                        var s = ex.Message;
                        attempt++;
                        Thread.Sleep(intervalToWaitInMilliSecs);
                    }
                }
                while (attempt < loopCount);
            }

            return exists;
        }

        /// <summary>
        /// <param name="element"></param>
        /// <param name="intervalToWaitInMilliSecs"></param>
        /// <param name="loopCount - The total wait time will be loopcount * intervalToWaitInMilliSecs"></param>
        /// <returns></returns>
        /// </summary>
        public static bool WaitForElementNotExists(IWebElement element, int loopCount = 20, int intervalToWaitInMilliSecs = 500)
        {
            int attempt = 0;
            bool exists = true;

            if (element != null)
            {
                do
                {
                    try
                    {
                        exists = element.Displayed;

                        if (!exists)
                        {
                            break;
                        }
                        else
                        {
                            attempt++;
                            Thread.Sleep(intervalToWaitInMilliSecs);
                        }
                    }
                    catch (Exception ex)
                    {
                        var s = ex.Message;
                        attempt++;
                        Thread.Sleep(intervalToWaitInMilliSecs);
                    }
                }
                while (attempt < loopCount);
            }

            return exists;
        }

        /// <summary>
        /// Waits for the element to be enabled
        /// </summary>
        /// <param name="element"></param>
        /// <param name="maxTimeoutInSeconds"></param>
        public static void WaitForElementEnabled(WindowsDriver<IWebElement> session, IWebElement element, int loopCount = 1, int maxTimeIntervalInSeconds = 30)
        {
            int attempt = 0;
            bool t = false;

            if (element != null)
            {
                do
                {
                    try
                    {
                        var wait = new DefaultWait<WindowsDriver<IWebElement>>(session)
                        {
                            Timeout = TimeSpan.FromSeconds(maxTimeIntervalInSeconds),
                            PollingInterval = TimeSpan.FromSeconds(2)
                        };
                        wait.IgnoreExceptionTypes(typeof(InvalidOperationException));
                        wait.IgnoreExceptionTypes(typeof(WebDriverTimeoutException));
                        wait.IgnoreExceptionTypes(typeof(WebDriverException));

                        wait.Until(driver =>
                        {
                            t = element.Enabled;
                            return t != false;
                        });

                        if (t)
                        {
                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        var s = ex.Message;
                        attempt++;
                    }
                }
                while (attempt < loopCount);
            }
        }

        public static void Click(IWebElement element, int loopCount = 20, int intervalToWaitMillSecs = 500)
        {
            try
            {
                IsElementExistsWithWait(element, loopCount, intervalToWaitMillSecs);
                TestReport.LogSuccess(string.Format("{0}{1}", "Click element ", element.GetAttribute("Name")));
                element.Click();
            }
            catch (Exception ex)
            {
                TestReport.LogFailure(string.Format("{0}{1}", "Failed Clicking element ", ex.Message));
            }
        }

        public static void Clear(IWebElement element, int loopCount = 20, int intervalToWaitMillSecs = 500)
        {
            try
            {
                IsElementExistsWithWait(element, loopCount, intervalToWaitMillSecs);
                TestReport.LogSuccess(string.Format("{0}{1}", "Clearing contents of element ", element.GetAttribute("Name")));
                element.Clear();
            }
            catch (Exception ex)
            {
                TestReport.LogFailure(string.Format("{0}{1}", "Failed Clearing contents of element ", ex.Message));
            }
        }

        public static void SendKeyBoardPressKey(WindowsDriver<IWebElement> session, string key)
        {
            try
            {
                TestReport.LogSuccess("Entering value '" + key + "' through keyboard ");
                GetActionsInstance(session).SendKeys(key);
            }
            catch (Exception ex)
            {
                TestReport.LogFailure(string.Format("{0}{1}", "Failed entering value through keyboard", ex.Message));
            }
        }

        public static void SelectAllKeyboard(WindowsDriver<IWebElement> session)
        {
            try
            {
                TestReport.LogSuccess("Performing Select All operation");
                GetActionsInstance(session).SendKeys(Keys.Control + "a" + Keys.Control);
            }
            catch (Exception ex)
            {
                TestReport.LogFailure(string.Format("{0}{1}", "Failed performing Select All operation", ex.Message));
            }
        }

        public static void SendKeysToElement(IWebElement element, string textToEnter, int loopCount = 20, int intervalToWaitMillSecs = 500)
        {
            try
            {
                IsElementExistsWithWait(element, loopCount, intervalToWaitMillSecs);
                TestReport.LogSuccess(string.Format("{0},{1}", "Entering value '" + textToEnter + "' to element ", element.GetAttribute("Name")));
                element.SendKeys(textToEnter);
            }
            catch (Exception ex)
            {
                TestReport.LogFailure(string.Format("{0},{1}", "Failed entering value to element ", ex.Message));
            }
        }

        public static void SendKeysToElementClearFirst(IWebElement element, string textToEnter, int loopCount = 20, int intervalToWaitMillSecs = 500)
        {
            try
            {
                IsElementExistsWithWait(element, loopCount, intervalToWaitMillSecs);
                TestReport.LogSuccess(string.Format("{0},{1}", "Clearing and Entering value '" + textToEnter + "' to element ", element.GetAttribute("Name")));
                element.Clear();
                element.SendKeys(textToEnter);
            }
            catch (Exception ex)
            {
                TestReport.LogFailure(string.Format("{0},{1}", "Failed clearing and entering value to element ", ex.Message));
            }
        }

        public static void ClickByMoveByOffset(WindowsDriver<IWebElement> driver, int x, int y)
        {
            try
            {
                TestReport.LogSuccess("Performing click moving by offset using coordinates " + x + " , " + y + "");
                GetActionsInstance(driver).MoveByOffset(x, y).Click().Build().Perform();
            }
            catch (Exception ex)
            {
                TestReport.LogFailure(string.Format("{0}{1}", "Performing click moving by offset using coordinates", ex.Message));
            }
        }

        public static void MovetoElement(WindowsDriver<IWebElement> driver, IWebElement element, int loopCount = 20, int intervalToWaitMillSecs = 500)
        {
            try
            {
                IsElementExistsWithWait(element, loopCount, intervalToWaitMillSecs);
                TestReport.LogSuccess(string.Format("{0}{1}", "Moving the cursor to the element ", element.GetAttribute("Name")));
                GetActionsInstance(driver).MoveToElement(element).Build().Perform();
            }
            catch (Exception ex)
            {
                TestReport.LogFailure(string.Format("{0}{1}", "Failed moving the cursor to the element", ex.Message));
            }
        }

        public static void MovetoElement(WindowsDriver<IWebElement> driver, IWebElement element, int x, int y, int loopCount = 20,
            int intervalToWaitMillSecs = 500)
        {
            try
            {
                IsElementExistsWithWait(element, loopCount, intervalToWaitMillSecs);
                TestReport.LogSuccess(string.Format("{0}{1}{2}", "Moving the cursor to the element '" + element.GetAttribute("Name") + "' using coordinates", x, y));
                GetActionsInstance(driver).MoveToElement(element, x, y).Build().Perform();
            }
            catch (Exception ex)
            {
                TestReport.LogFailure(string.Format("{0}{1}", "Failed moving the cursor to the element using coordinates", ex.Message));
            }
        }

        public static void ClickByMovetoElement(WindowsDriver<IWebElement> driver, IWebElement element, int x, int y, int loopCount = 20,
            int intervalToWaitMillSecs = 500)
        {
            try
            {
                IsElementExistsWithWait(element, loopCount, intervalToWaitMillSecs);
                TestReport.LogSuccess(string.Format("{0}{1}{2}", "performing click by moving the cursor to the element '" + element.GetAttribute("Name") + "' using coordinates", x, y));
                GetActionsInstance(driver).MoveToElement(element, x, y).Click().Build().Perform();
            }
            catch (Exception ex)
            {
                TestReport.LogFailure(string.Format("{0}{1}", "Failed performing click by moving the cursor to the element using coordinates", ex.Message));
            }
        }

        public static void ClickByMovetoElement(WindowsDriver<IWebElement> driver, IWebElement element, int loopCount = 20,
            int intervalToWaitMillSecs = 500)
        {
            try
            {
                IsElementExistsWithWait(element, loopCount, intervalToWaitMillSecs);
                TestReport.LogSuccess("performing click by moving the cursor to the element '" + element.GetAttribute("Name") + "'");
                GetActionsInstance(driver).MoveToElement(element).Click().Build().Perform();
            }
            catch (Exception ex)
            {
                TestReport.LogFailure(string.Format("{0}{1}", "Failed performing click by moving the cursor to the element '" + element.GetAttribute("Name") + "'", ex.Message));
            }
        }

        public static void SelectCheckBox(IWebElement element, int loopCount = 20, int intervalToWaitMillSecs = 500)
        {
            try
            {
                IsElementExistsWithWait(element, loopCount, intervalToWaitMillSecs);
                TestReport.LogSuccess("Selecting checkbox '" + element.GetAttribute("Name") + "'");
                if (!(element.Selected))
                    element.Click();
            }
            catch (Exception ex)
            {
                TestReport.LogFailure(string.Format("{0}{1}", "Failed selecting checkbox '" + element.GetAttribute("Name") + "'", ex.Message));
            }
        }

        public static void UnSelectCheckBox(IWebElement element, int loopCount = 20, int intervalToWaitMillSecs = 500)
        {
            try
            {
                IsElementExistsWithWait(element, loopCount, intervalToWaitMillSecs);
                TestReport.LogSuccess("UnSelecting checkbox '" + element.GetAttribute("Name") + "'");
                if (element.Selected)
                    element.Click();
            }
            catch (Exception ex)
            {
                TestReport.LogFailure(string.Format("{0}{1}", "Failed Unselecting checkbox '" + element.GetAttribute("Name") + "'", ex.Message));
            }
        }

        public static bool IsEnabled(IWebElement element, int loopCount = 20, int intervalToWaitMillSecs = 500)
        {
            bool status = false;
            try
            {
                IsElementExistsWithWait(element, loopCount, intervalToWaitMillSecs);
                TestReport.LogSuccess("Enabled status for '" + element.GetAttribute("Name") + "'");
                status = element.Enabled;
            }

            catch (Exception ex)
            {
                TestReport.LogFailure(string.Format("{0}{1}", "Failed to find element '" + element.GetAttribute("Name") + "'", ex.Message));
            }

            return status;
        }

        public static bool IsSelected(IWebElement element, int loopCount = 20, int intervalToWaitMillSecs = 500)
        {
            bool status = false;
            try
            {
                IsElementExistsWithWait(element, loopCount, intervalToWaitMillSecs);
                TestReport.LogSuccess("Selected status for '" + element.GetAttribute("Name") + "'");
                status = element.Selected;
            }

            catch (Exception ex)
            {
                TestReport.LogFailure(string.Format("{0}{1}", "Failed to find element '" + element.GetAttribute("Name") + "'", ex.Message));
            }

            return status;
        }

        public static void SelectValueInCombobox(IWebElement element, IWebElement elementToSelect, int loopCount = 20, int intervalToWaitMillSecs = 500)
        {
            try
            {
                IsElementExistsWithWait(element, loopCount, intervalToWaitMillSecs);
                TestReport.LogSuccess(string.Format("{0}{1}", "Selecting value ", elementToSelect.GetAttribute("Name"), element.GetAttribute("Name")));
                element.Click();
                elementToSelect.Click();
            }

            catch (Exception ex)
            {
                TestReport.LogSuccess(string.Format("{0}{1}{2}", "Failed selecting value ", elementToSelect.GetAttribute("Name"), element.GetAttribute("Name"), ex.Message));
            }
        }

        public static void ClickByActions(WindowsDriver<IWebElement> driver, IWebElement element, int loopCount = 20, int intervalToWaitMillSecs = 500)
        {
            try
            {
                IsElementExistsWithWait(element, loopCount, intervalToWaitMillSecs);
                TestReport.LogSuccess("Click element " + element.GetAttribute("Name") + " using action builder");
                GetActionsInstance(driver).Click(element).Build().Perform();
            }
            catch (Exception ex)
            {
                TestReport.LogFailure(string.Format("{0}{1}", "Failed to click element using action builder", ex.Message));
            }
        }

        public static void ClickByActions(WindowsDriver<IWebElement> driver)
        {
            try
            {
                TestReport.LogSuccess("perform click using action builder");
                GetActionsInstance(driver).Click().Build().Perform();
            }
            catch (Exception ex)
            {
                TestReport.LogFailure(string.Format("{0}{1}", "Failed to perform click using action builder", ex.Message));
            }
        }

        public static void DoubleClick(WindowsDriver<IWebElement> driver, IWebElement element, int loopCount = 20, int intervalToWaitMillSecs = 500)
        {
            try
            {
                IsElementExistsWithWait(element, loopCount, intervalToWaitMillSecs);
                TestReport.LogSuccess("Double Click element " + element.GetAttribute("Name") + "");
                GetActionsInstance(driver).DoubleClick(element).Build().Perform();
            }
            catch (Exception ex)
            {
                TestReport.LogFailure(string.Format("{0}{1}", "Failed to double click element", ex.Message));
            }
        }

        public static void RightClick(WindowsDriver<IWebElement> driver, IWebElement element, int loopCount = 20, int intervalToWaitMillSecs = 500)
        {
            try
            {
                IsElementExistsWithWait(element, loopCount, intervalToWaitMillSecs);
                TestReport.LogSuccess("Right Click element " + element.GetAttribute("Name") + "");
                GetActionsInstance(driver).ContextClick(element).Build().Perform();
            }
            catch (Exception ex)
            {
                TestReport.LogFailure(string.Format("{0}{1}", "Failed to right click element", ex.Message));
            }
        }

        private static Actions GetActionsInstance(WindowsDriver<IWebElement> driver) { return new Actions(driver); }
    }
}