Пример #1
0
        public static void KeyPress(String obj, String data)
        {
            Log.Info("KeyPress " + data + " on .. " + obj);
            ExtentReporter.NodeInfo("KeyPress " + data + " on .. " + obj);
            try
            {
                string[] locator = obj.Split('_');
                switch (data.ToLower().Trim())
                {
                case "enter":
                    driver.FindElement(LocateValue(locator[1], GetKey(obj))).SendKeys(Keys.Enter);
                    break;

                case "return":
                    driver.FindElement(LocateValue(locator[1], GetKey(obj))).SendKeys(Keys.Return);
                    break;

                case "tab":
                    driver.FindElement(LocateValue(locator[1], GetKey(obj))).SendKeys(Keys.Tab);
                    break;

                default:
                    Log.Error("Not a key");
                    break;
                }
            }
            catch (Exception e)
            {
                Log.Error("Not able to KeyPress " + data + " | Exception: " + e.Message);
                ExtentReporter.NodeError("Not able to KeyPress " + data + " | Exception: " + e.Message);
                DriverScript.iOutcome = 3;
            }
        }
Пример #2
0
        public static void AssertElementContains(String obj, String data)
        {
            Log.Info("AssertElementContains .. " + obj);
            ExtentReporter.NodeInfo("AssertElementContains .. " + obj);
            try
            {
                string[] locator = obj.Split('_');
                By       by      = LocateValue(locator[1], GetKey(obj));

                //WaitForInvisibilityLoading(out double loadtime);
                //Log.Info("Loadtime: " + loadtime);

                //ScrollIntoView(by);
                WaitUntil(by, driver);

                Assert.AreEqual(GetTextByDriver(by), data);
                WaitSeconds("", "2");
                DriverScript.iOutcome = 1;
            }
            catch (AssertFailedException e)
            {
                Log.Error("AssertElementContains Assert Fail| Exception: " + e.Message);
                ExtentReporter.NodeFail("AssertElementContains Assert Fail| Exception: " + e.Message);
                DriverScript.iOutcome = 2;
            }
            catch (Exception e)
            {
                Log.Error("Failed AssertElementContains | Exception: " + e.Message);
                ExtentReporter.NodeError("Failed AssertElementContains | Exception: " + e.Message);
                DriverScript.iOutcome = 3;
            }
        }
Пример #3
0
        public static void NavigateToURL(String obj, String data)
        {
            try
            {
                Log.Info($"Navigating to URL {data}");
                ExtentReporter.NodeInfo($"Navigating to URL {data}");

                ((IJavaScriptExecutor)driver).ExecuteScript("return window.stop;");

                string currentURL = driver.Url;
                if (!currentURL.Equals(data))
                {
                    driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(Constants.NavigationTimeout);
                    driver.Url = data;
                    //driver.Navigate().GoToUrl(data);
                }
                else
                {
                    driver.Navigate().Refresh();
                }
            }
            catch (Exception e)
            {
                Log.Error("Not able to navigate to URL | Exception: " + e.Message);
                ExtentReporter.NodeInfo("Not able to navigate to URL | Exception: " + e.Message);
                DriverScript.iOutcome = 3;
            }
        }
Пример #4
0
        public static void OpenMobileApp(String obj, String data)
        {
            Log.Info("Opening App");
            ExtentReporter.NodeInfo("Opening App");

            try
            {
                if (data.Equals(OS.Android.ToString()))
                {
                    OpenAndroidDriver(Constants.DeviceName, Constants.Udid, Constants.PlatformVersion, Constants.AndroidAppapk);
                }
                else if (data.Equals(OS.IOS.ToString()))
                {
                    //IOS
                }

                Log.Info("App Opened");
                ExtentReporter.NodeInfo("App Opened");
            }
            catch (Exception e)
            {
                Log.Error($"Failed OpenApp | Exception: {e.Message}");
                ExtentReporter.NodeError($"Failed OpenApp | Exception: {e.Message}");
                DriverScript.iOutcome = 3;
            }
        }
Пример #5
0
        public static void DragDropTrad(String obj, String data)
        {
            Log.Info("Draging Webelement " + obj);
            ExtentReporter.NodeInfo("Draging Webelement " + obj);
            try
            {
                string[] locator1      = obj.Split('_');
                string[] locator2value = data.Split('_');

                By byDragElement = LocateValue(locator1[1], GetKey(obj));
                By byDropValue   = LocateValue(locator2value[1], GetKey(data));

                IWebElement source;
                IWebElement target;

                //WaitForInvisibilityLoading(out double loadtime);
                //Log.Info("Loadtime: " + loadtime);

                WaitUntilExists(byDragElement, driver);
                if (IsElementPresent(byDragElement))
                {
                    source = driver.FindElement(byDragElement);
                }
                else
                {
                    WaitForElement(byDragElement);
                    source = driver.FindElement(byDragElement);
                }

                WaitUntilExists(byDropValue, driver);
                if (IsElementPresent(byDragElement))
                {
                    target = driver.FindElement(byDropValue);
                }
                else
                {
                    WaitForElement(byDragElement);
                    target = driver.FindElement(byDropValue);
                }

                IJavaScriptExecutor jse = (IJavaScriptExecutor)driver;
                if (File.Exists(Constants.Drag_Drop))
                {
                    WaitSeconds("", "3");
                    string dragAndDropScript = File.ReadAllText(Constants.Drag_Drop);
                    jse.ExecuteScript(dragAndDropScript, source, target);
                    WaitSeconds("", "3");
                }
            }
            catch (Exception e)
            {
                Log.Error("Not able to drag and drop | Exception: " + e.Message);
                ExtentReporter.NodeError("Not able to drag and drop | Exception: " + e.Message);
                DriverScript.iOutcome = 3;
            }
        }
Пример #6
0
        public static void AssertTaskcompleted(String obj, String data)
        {
            Log.Info("AssertTaskcompleted .. " + obj);
            ExtentReporter.NodeInfo("AssertTaskcompleted .. " + obj);
            try
            {
                string[] locator = obj.Split('_');


                string newcompleteddata;
                string newprogressddata;

                newcompleteddata = GetKey(obj).Replace("#1", DateTime.Today.Date.ToString("dd/MM/yyyy")).Replace("#2", DateTime.Today.Date.ToString("مكتملة"));
                newprogressddata = GetKey(obj).Replace("#1", DateTime.Today.Date.ToString("dd/MM/yyyy")).Replace("#2", DateTime.Today.Date.ToString("جاري"));


                By bycompleteddata = LocateValue(locator[1], newcompleteddata);
                By byprogressddata = LocateValue(locator[1], newprogressddata);

                ExtentReporter.NodeInfo($"completed .. {newcompleteddata}|{bycompleteddata}");

                ExtentReporter.NodeInfo($"inprogress .. {newprogressddata}|{byprogressddata}");

                if (IsElementPresent(bycompleteddata))
                {
                    WaitSeconds("", "2");
                    DriverScript.iOutcome = 1;
                }
                else if (IsElementPresent(byprogressddata))
                {
                    Assert.Fail();
                }
                else
                {
                    ExtentReporter.NodeInfo("nothing .. ");
                    Assert.Fail();
                }
            }
            catch (AssertFailedException e)
            {
                Log.Error("AssertTaskcompleted Assert Fail| Exception: " + e.Message);
                ExtentReporter.NodeFail("AssertTaskcompleted Assert Fail| Exception: " + e.Message);
                DriverScript.iOutcome = 2;
            }
            catch (Exception e)
            {
                Log.Error("Failed AssertTaskcompleted | Exception: " + e.Message);
                ExtentReporter.NodeError("Failed AssertTaskcompleted | Exception: " + e.Message);
                DriverScript.iOutcome = 3;
            }
        }
Пример #7
0
 private static bool IsElementPresent(By by)
 {
     try
     {
         driver.FindElement(by);
         return(true);
     }
     catch (NoSuchElementException e)
     {
         Log.Info($"No able to find element by IsElementPresent | Exception: {e.Message}");
         ExtentReporter.NodeInfo($"No able to find element by IsElementPresent | Exception: {e.Message}");
         return(false);
     }
 }
Пример #8
0
 private static void WaitUntilClickable(By by, IWebDriver driver)
 {
     try
     {
         Log.Info("WaitUntilClickable ..");
         WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(Constants.Timeout));
         wait.Until(ExpectedConditions.ElementToBeClickable(by));
     }
     catch (Exception e)
     {
         Log.Error("Failed WaitUntilClickable | Exception: " + e.Message);
         ExtentReporter.NodeInfo("Failed WaitUntil | Exception: " + e.Message);
     }
 }
Пример #9
0
 private static void WaitUntilUrlContains(String data)
 {
     try
     {
         Log.Info("WaitUntilUrlContains .." + data);
         ExtentReporter.NodeInfo("WaitUntilUrlContains ..");
         WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(Constants.NavigationTimeout));
         wait.Until(ExpectedConditions.UrlContains(data));
     }
     catch (Exception e)
     {
         Log.Error("Failed WaitUntilUrlContains | Exception: " + e.Message);
         ExtentReporter.NodeError("Failed WaitUntilUrlContains | Exception: " + e.Message);
     }
 }
Пример #10
0
        private static void WaitUntil(By by, IWebDriver driver)
        {
            try
            {
                Log.Info("WaitUntil ..");
                ExtentReporter.NodeInfo("WaitUntil ..");

                WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(Constants.Timeout));
                wait.Until(d => d.FindElement(by));
            }
            catch (Exception e)
            {
                Log.Error("Failed WaitUntil | Exception: " + e.Message);
            }
        }
Пример #11
0
 private static void WaitUntilInvisibilityElement(By by)
 {
     try
     {
         Log.Info("WaitUntilInvisibilityElement ..");
         ExtentReporter.NodeInfo("WaitUntilInvisibilityElement ..");
         WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(Constants.NavigationTimeout));
         wait.Until(ExpectedConditions.InvisibilityOfElementLocated(by));
     }
     catch (Exception e)
     {
         Log.Error("Failed WaitUntilInvisibilityElement | Exception: " + e.Message);
         ExtentReporter.NodeError("Failed WaitUntilInvisibilityElement | Exception: " + e.Message);
     }
 }
Пример #12
0
        private static void ScrollIntoView(By by)
        {
            try
            {
                Log.Info("ScrollIntoView ..");
                ExtentReporter.NodeInfo("ScrollIntoView ..");

                IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
                js.ExecuteScript("arguments[0].scrollIntoView(true);", driver.FindElement(by));
            }
            catch (Exception e)
            {
                Log.Info($"Not able to ScrollIntoView | Exception: {e.Message}");
                ExtentReporter.NodeInfo($"Not able to ScrollIntoView | Exception: {e.Message}");
            }
        }
Пример #13
0
        public static void RefreshBrowser(String obj, String data)
        {
            try
            {
                Log.Info($"Refreshing Browser");
                ExtentReporter.NodeInfo($"Refreshing Browser");

                driver.Navigate().Refresh();
            }
            catch (Exception e)
            {
                Log.Error($"Failed RefreshBrowser | Exception: {e.Message}");
                ExtentReporter.NodeInfo($"Failed RefreshBrowser | Exception: {e.Message}");
                DriverScript.iOutcome = 3;
            }
        }
Пример #14
0
        private static bool ClearByDriver(By by, String data)
        {
            try
            {
                Log.Info("ClearByDriver ..");
                ExtentReporter.NodeInfo("ClearByDriver ..");

                driver.FindElement(by).Clear();
                return(true);
            }
            catch (Exception e)
            {
                Log.Info($"Not able to ClearByDriver | Exception: {e.Message}");
                ExtentReporter.NodeInfo($"Not able to ClearByDriver | Exception: {e.Message}");
                return(false);
            }
        }
Пример #15
0
        private static bool InputByappiumDriver(By by, String data)
        {
            try
            {
                Log.Info("InputByappiumDriver ..");
                ExtentReporter.NodeInfo("InputByappiumDriver ..");

                appiumdriver.FindElement(by).SendKeys(data);
                return(true);
            }
            catch (Exception e)
            {
                Log.Info($"Not able to InputByappiumDriver | Exception: {e.Message}");
                ExtentReporter.NodeInfo($"Not able to InputByappiumDriver | Exception: {e.Message}");
                return(false);
            }
        }
Пример #16
0
        private static bool ClickByappiumDriver(By by)
        {
            try
            {
                Log.Info("ClickByappiumDriver ..");
                ExtentReporter.NodeInfo("ClickByappiumDriver ..");

                appiumdriver.FindElement(by).Click();
                return(true);
            }
            catch (Exception e)
            {
                Log.Info($"Not able to ClickByappiumDriver | Exception: {e.Message}");
                ExtentReporter.NodeInfo($"Not able to ClickByappiumDriver | Exception: {e.Message}");
                return(false);
            }
        }
Пример #17
0
        private static bool SelectValueByappiumDriver(By by, string data)
        {
            try
            {
                Log.Info("SelectValueByappiumDriver ..");
                ExtentReporter.NodeInfo("SelectValueByappiumDriver ..");

                new SelectElement(appiumdriver.FindElement(by)).SelectByValue(data);
                return(true);
            }
            catch (Exception e)
            {
                Log.Info($"Not able to SelectValueByappiumDriver | Exception: {e.Message}");
                ExtentReporter.NodeInfo($"Not able to SelectValueByappiumDriver | Exception: {e.Message}");
                return(false);
            }
        }
Пример #18
0
        public static void WaitSeconds(String obj, String data)
        {
            try
            {
                int millisec = Convert.ToInt32(data) * 1000;
                Log.Info($"Waiting {data} seconds");
                ExtentReporter.NodeInfo($"Waiting {data} seconds");

                Thread.Sleep(millisec);
            }
            catch (Exception e)
            {
                Log.Error($"Failed WaitSeconds | Exception: {e.Message}");
                ExtentReporter.NodeInfo($"Failed WaitSeconds | Exception: {e.Message}");
                DriverScript.iOutcome = 3;
            }
        }
Пример #19
0
        private static bool ClickByDriver(IWebElement element)
        {
            try
            {
                Log.Info("ClickByDriver ..");
                ExtentReporter.NodeInfo("ClickByDriver ..");

                element.Click();
                return(true);
            }
            catch (Exception e)
            {
                Log.Info($"Not able to ClickByDriver | Exception: {e.Message}");
                ExtentReporter.NodeInfo($"Not able to ClickByDriver | Exception: {e.Message}");
                return(false);
            }
        }
Пример #20
0
        public static void Click(String obj, String data)
        {
            Log.Info($"Clicking on Element {obj}");
            ExtentReporter.NodeInfo($"Clicking on Element {obj}");

            try
            {
                string[] locator = obj.Split('_');
                By       by      = LocateValue(locator[1], GetKey(obj));

                if (locator[0] == "Mobile")
                {
                    WaitUntilVisible(by, appiumdriver);
                    WaitSeconds("", "2");

                    if (!ClickByappiumDriver(by))
                    {
                        Log.Error("Failed ClickByappiumDriver");
                        ExtentReporter.NodeError("Failed ClickByappiumDriver");
                        DriverScript.iOutcome = 3;
                    }
                }
                else
                {
                    WaitUntilClickable(by, driver);
                    WaitSeconds("", "2");

                    if (!ClickByDriver(by))
                    {
                        if (!ClickByJavascript(by))
                        {
                            Log.Error("Failed ClickByDriver and ClickByJavascript");
                            ExtentReporter.NodeError("Failed ClickByDriver and ClickByJavascript");
                            DriverScript.iOutcome = 3;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Log.Error($"Failed Click | Exception: {e.Message}");
                ExtentReporter.NodeError($"Failed Click | Exception: {e.Message}");
                ExtentReporter.AddScreenShot("");
                DriverScript.iOutcome = 3;
            }
        }
Пример #21
0
        private static bool InputByJavascript(By by, String data)
        {
            try
            {
                Log.Info("InputByJavascript ..");
                ExtentReporter.NodeInfo("InputByJavascript ..");

                IJavaScriptExecutor jse = (IJavaScriptExecutor)driver;
                jse.ExecuteScript("arguments[0].value='" + data + "';", driver.FindElement(by));
                return(true);
            }
            catch (Exception e)
            {
                Log.Info($"Not able to InputByJavascript | Exception: { e.Message}");
                ExtentReporter.NodeInfo($"Not able to InputByJavascript | Exception: {e.Message}");
                return(false);
            }
        }
Пример #22
0
        public static void OpenBrowser(String obj, String data)
        {
            Log.Info($"Opening Browser {data}");
            ExtentReporter.NodeInfo($"Opening Browser {data}");
            try
            {
                driver = BuildDriver(Constants.DriverType, data);

                Log.Info($"Browser {data} Opened");
                ExtentReporter.NodeInfo($"Browser {data} Opened");
            }
            catch (Exception e)
            {
                Log.Error($"Failed OpenBrowser | Exception: {e.Message}");
                ExtentReporter.NodeError($"Failed OpenBrowser | Exception: {e.Message}");
                DriverScript.iOutcome = 3;
            }
        }
Пример #23
0
        private static bool ClickByJavascript(IWebElement element)
        {
            try
            {
                Log.Info("ClickByJavascript ..");
                ExtentReporter.NodeInfo("ClickByJavascript ..");

                IJavaScriptExecutor jse = (IJavaScriptExecutor)driver;
                jse.ExecuteScript("arguments[arguments.length - 1].click();", element);
                return(true);
            }
            catch (Exception e)
            {
                Log.Info($"Not able to ClickByJavascript | Exception: {e.Message}");
                ExtentReporter.NodeInfo($"Not able to ClickByJavascript | Exception: {e.Message}");
                return(false);
            }
        }
Пример #24
0
        public static void Select(String obj, String data)
        {
            Log.Info($"Selecting from dropdown Element {obj}");
            ExtentReporter.NodeInfo($"Selecting from dropdown Element {obj}");

            try
            {
                string[] locator = obj.Split('_');
                By       by      = LocateValue(locator[1], GetKey(obj));

                if (locator[0] == "Mobile")
                {
                    WaitUntil(by, appiumdriver);
                    if (!SelectTextByappiumDriver(by, data))
                    {
                        if (!SelectValueByappiumDriver(by, data))
                        {
                            Log.Error("Failed SelectTextByappiumDriver and SelectValueByappiumDriver");
                            ExtentReporter.NodeError("Failed SelectTextByappiumDriver and SelectValueByappiumDriver");
                            DriverScript.iOutcome = 3;
                        }
                    }
                }
                else
                {
                    WaitUntil(by, driver);
                    if (!SelectTextByDriver(by, data))
                    {
                        if (!SelectValueByDriver(by, data))
                        {
                            Log.Error("Failed SelectTextByDriver and SelectValueByDriver");
                            ExtentReporter.NodeError("Failed SelectTextByDriver and SelectValueByDriver");
                            DriverScript.iOutcome = 3;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Log.Error($"Failed Select | Exception: {e.Message}");
                ExtentReporter.NodeError($"Failed Select | Exception: {e.Message}");
                DriverScript.iOutcome = 3;
            }
        }
Пример #25
0
        private static void WaitFluentUntil(By by)
        {
            try
            {
                Log.Info("WaitFluentUntil ..");
                ExtentReporter.NodeInfo("WaitFluentUntil ..");

                DefaultWait <IWebDriver> fluentWait = new DefaultWait <IWebDriver>(driver);
                fluentWait.Timeout         = TimeSpan.FromSeconds(Constants.Timeout);
                fluentWait.PollingInterval = TimeSpan.FromSeconds(1);
                fluentWait.IgnoreExceptionTypes(typeof(NoSuchElementException));
                IWebElement searchResult = fluentWait.Until(x => x.FindElement(by));
            }
            catch (Exception e)
            {
                Log.Error("Failed WaitFluentUntil | Exception: " + e.Message);
                ExtentReporter.NodeError("Failed WaitFluentUntil | Exception: " + e.Message);
            }
        }
Пример #26
0
        public static void CloseMobileApp(String obj, String data)
        {
            try
            {
                Log.Info("Closing App");
                ExtentReporter.NodeInfo("Closing App");

                appiumdriver.Quit();

                Log.Info("App Closed");
                ExtentReporter.NodeInfo("App Closed");
            }
            catch (Exception e)
            {
                Log.Error($"Failed CloseApp | Exception: {e.Message}");
                ExtentReporter.NodeError($"Failed CloseApp | Exception: {e.Message}");
                DriverScript.iOutcome = 3;
            }
        }
Пример #27
0
        public static void CloseBrowser(String obj, String data)
        {
            try
            {
                if (driver != null)
                {
                    Log.Info("Closing Browser ");
                    ExtentReporter.NodeInfo("Closing Browser ");
                    //driver.Quit();
                    driver.Close();

                    Log.Info("Browser Closed");
                    ExtentReporter.NodeInfo("Browser Closed");
                }
            }
            catch (Exception e)
            {
                Log.Error("Not able to Close the Browser | Exception: " + e.Message);
                ExtentReporter.NodeError("Not able to Close the Browser | Exception: " + e.Message);
                DriverScript.iOutcome = 3;
            }
        }
Пример #28
0
        public static void CheckCheckbox(String obj, String data)
        {
            Log.Info("CheckCheckbox .. " + obj);
            ExtentReporter.NodeInfo("CheckCheckbox .. " + obj);
            try
            {
                string[] locator = obj.Split('_');
                By       by      = LocateValue(locator[1], GetKey(obj));

                //WaitForInvisibilityLoading(out double loadtime);
                //Log.Info("Loadtime: " + loadtime);

                ScrollIntoView(by);
                WaitUntilClickable(by, driver);

                IWebElement chkbx = driver.FindElement(by);
                if (!chkbx.Selected)
                {
                    if (!ClickByDriver(chkbx))
                    {
                        if (!ClickByJavascript(chkbx))
                        {
                            Log.Error("Not able to CheckCheckbox ..");
                            ExtentReporter.NodeError("Not able to CheckCheckbox ..");
                            DriverScript.iOutcome = 3;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Log.Error("Failed CheckCheckbox | Exception: " + e.Message);
                ExtentReporter.NodeError("Failed CheckCheckbox | Exception: " + e.Message);
                DriverScript.iOutcome = 3;
            }
        }