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); }
    }
}

Sunday, 5 August 2018

Jquery search

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication3.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#myInput").on("keyup", function () {
                var value = $(this).val().toLowerCase();
                $("#myTable tr").filter(function () {
                    $(this).toggle($(this).text().toLowerCase().indexOf(value) > -1)
                });
            });
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <tr>
                <td>
                    <input type="text" id="myInput" name="fname" /></td>
            </tr>

            <table id="myTable" width="100%">

                <tr>
                    <th>First Name</th>
                    <th>Last Name</th>
                    <th>Email</th>
                </tr>
                <tr>
                    <td>Manoj</td>
                    <td>Sahoo</td>
                    <td>manoj@example.com</td>
                </tr>
                <tr>
                    <td>Rakesh</td>
                    <td>Dixit</td>
                    <td>rakesh@mail.com</td>
                </tr>
                <tr>
                    <td>Vipin</td>
                    <td>Dalei</td>
                    <td>vipin@greatstuff.com</td>
                </tr>
                <tr>
                    <td>April</td>
                    <td>Sahoo</td>
                    <td>april@abc.com</td>
                </tr>
            </table>
        </div>
    </form>
</body>
</html>

Tuesday, 17 April 2018

Fortran Compile


Fortran Compile
         !ashutosh
!declare below two lines
                  integer*4     val1   
                  character*10   chr2
                  val1=1003
!call below two lines where ever required
         write(chr2,"(I4.4)")val1
         CALL Write_To_Pipe(chr2)
                   !ashutosh

OR


OPEN(5, FILE='C:\MVRS\Routes\DATALOG.TXT',ACCESS='APPEND')
       WRITE(5,*)ERT_ID ! this a characer
             CLOSE(5)
 

Friday, 2 March 2018

Temp Table

Create Table #MyTempTable (
    EmployeeID int,
    Name varchar(100)
);

Insert Into #MyTempTable SELECT dbo.Employee.Id as EmployeeID, dbo.Table_1.Name as Name
FROM   dbo.Employee INNER JOIN
             dbo.Table_1 ON dbo.Employee.Id = dbo.Table_1.id

Select EmployeeID, Name from #MyTempTable

Drop Table #MyTempTable