/**Execute the java script, scriptToExecute, on the site driver, e.g. to simulate an action that cannot be achieved by a webdriver action.
         * Such actions could be as forcing the browser to show hidden elements, get browser information, etc.
         * The java script execution should be used with caution since it not an exact simulation of the user behavior.
         * @param scriptToExecute
         * @return an object
         */
        public Object ExecuteJavaScript(string pageNameToSwitchTo, string frameNameToSwitchTo, string scriptToExecute, params IWebElement[] args)
        {
            SAFINCALog.Debug("scriptToExecute: " + scriptToExecute);
            Object obj           = null;
            long   maxTimeToWait = CommonUtilities.GetCurrentTimeMillis() + CommonUtilities.GLOBAL_TIMEOUT_TIME_IN_MSEC;

            while (obj == null && maxTimeToWait > CommonUtilities.GetCurrentTimeMillis())
            {
                try
                {
                    //driver = FindWebDriverElement.SwitchToFrameOrWindowByName(this.driver, pageNameToSwitchTo, frameNameToSwitchTo);
                    IJavaScriptExecutor iJavaScriptExecutor = (IJavaScriptExecutor)driver;

                    {
                        if (args != null && args.Length > 0)
                        {
                            obj = (Object)iJavaScriptExecutor.ExecuteScript(scriptToExecute, args[0]);
                            SAFINCALog.Debug("object: " + obj);
                            return(obj);
                        }
                        else
                        {
                            obj = (Object)iJavaScriptExecutor.ExecuteScript(scriptToExecute);
                            SAFINCALog.Debug("object: " + obj);
                            return(obj);
                        }
                    }
                }
                catch (Exception e)
                {
                }
            }
            return(obj);
        }
        public bool isAllRecordsPresentSVLGrid(int gridPosition, string field, String[] data)
        {
            IWebElement pageElement = null;
            IReadOnlyCollection <IWebElement> elementTdList = null;
            bool isPresentFlag = false; String dataOfField = null; int count = 0;

            try
            {
                //Find the Page Element
                pageElement = findWebDriverElement.waitForElementById(null, null, "Portal");

                elementTdList = pageElement.FindElements(By.XPath("(//div[contains(@class,'DynamicGrid')])[" + gridPosition + "]//tr[contains(@data-key,'==')]/td[@data-field='" + field + "']"));

                if (elementTdList.Count == 0)
                {
                    elementTdList = pageElement.FindElements(By.XPath("(//div[contains(@class,'DynamicGrid')])[" + gridPosition + "]//tr[contains(@external-value,'==')]/td[@data-field='" + field + "']"));
                }

                //Iterate over the td list
                foreach (IWebElement td in elementTdList)
                {
                    IWebElement span = td.FindElement(By.TagName("span"));

                    dataOfField = span.GetAttribute("innerHTML");

                    if (!dataOfField.Equals(""))
                    {
                        if (Array.Exists(data, element => element == dataOfField))
                        {
                            isPresentFlag = true; count++;
                        }
                        else
                        {
                            isPresentFlag = false;
                        }
                    }
                } // end of for each

                SAFINCALog.Info("Td count" + count);

                if (data.Length == count)
                {
                    SAFINCALog.Info("Record count match");
                }
                else
                {
                    new NotFoundException("All records didn't match correctly");
                }

                return(isPresentFlag);
            }

            catch (Exception e)
            {
                isPresentFlag = false;
                return(isPresentFlag);

                throw e;
            }
        }
Beispiel #3
0
        public static void setTestClassStart(String testClassName, String dateTime)
        {
            try
            {
                SAFINCALog.Info("Executing Test Cases for Class Started for Class : " + testClassName);

                errorTestResultFilePath = null;

                //For Directory
                if (!Directory.Exists(resultFolderPath))
                {
                    resultFolderPath = resultFolderPath + "_" + dateTime;
                    Directory.CreateDirectory(resultFolderPath);
                    System.IO.File.Copy(@Environment.CurrentDirectory + "\\Test_Results_Template.xlsx", resultFolderPath + "\\Test_Results" + "_" + dateTime + ".xlsx");
                }

                testResultFilePath = resultFolderPath + "\\Test_Results" + "_" + dateTime + ".xlsx";

                testResultFile = new FileInfo(testResultFilePath);

                excelPackage = new ExcelPackage(testResultFile);

                testCaseWorkSheet = excelPackage.Workbook.Worksheets.First();

                testStepWorkSheet = excelPackage.Workbook.Worksheets.Last();
            }

            catch (Exception e)
            {
                SAFINCALog.TestCaseErrorMessage(e);
            }
        }
Beispiel #4
0
        public static void setTestClassFinish(String testClassName)
        {
            try

            {
                SAFINCALog.Info("Executing Test Cases Finished for Class  : " + testClassName);

                excelPackage.SaveAs(testResultFile);

                excelPackage.Dispose();

                // excelPackage.Load(holdingStream);

                SAFINCALog.Info("Saving Test Results for Class : " + testClassName + " in path -> " + testResultFilePath);
            }
            catch (Exception e)
            {
                SAFINCALog.TestCaseErrorMessage(e);
            }
            finally
            {
                //tc_RowIndex = 7; ts_RowIndex = 7; testCaseIDCounter = 1;
                testStepIDCounter = 1;
            }
        }
        public void SeleniumQuit()
        {
            Console.WriteLine("Quitting Driver...........");
            try
            {
                if (driver != null)
                {
                    driver.Quit();
                    driver = null;
                }

                SAFINCALog.Info("Closing Web Driver...........");
                ProcessMgn.killProcessByNames("IEDriverServer");    //Make sure the process is killed

                //Try to add the link to the Result file and screenshots if necessary
                this.TestContext.AddResultFile(WriteTestResultsExcel.testResultFilePath);
                if (WriteTestResultsExcel.errorTestResultFilePath != null)
                {
                    this.TestContext.AddResultFile(WriteTestResultsExcel.errorTestResultFilePath);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.StackTrace);
            }
        }
        //Method Usage example as give below
        //getDictionaryValue(Login_Objects.LOGIN_APRISO_USERNAME, DOMAttributes.css_class.ToString());

        public String getDictionaryValue(Dictionary <String, String> dictionary, String Key)
        {
            try
            {
                String value = null;
                if (dictionary != null)
                {
                    if (dictionary.ContainsKey(Key))
                    {
                        value = dictionary[Key];
                        return(value);
                    }
                    else
                    {
                        return(value);
                    }
                }
                else
                {
                    return(value);
                }
            }
            catch (Exception e)
            {
                SAFINCALog.LogStackTrace(e);
                return(null);
            }
        }
Beispiel #7
0
        //Switch Iframes
        public void iframeswitch(String iframeTextSrc)
        {
            IReadOnlyCollection <IWebElement> iframelist = driver.FindElements(By.TagName("iframe"));

            String value = null;

            SAFINCALog.Info("Count of IFrames: " + iframelist.Count());
            //Iterate over the td list
            foreach (IWebElement iframe in iframelist)
            {
                value = iframe.GetAttribute("src");

                SAFINCALog.Info("Src of IFrames: " + value);

                if (value != null && value != "")
                {
                    if (value.Contains(iframeTextSrc))
                    {
                        driver.SwitchTo().Frame(iframe);
                        findWebDriverElement.Driver = driver;
                        javaScriptCalls.Driver      = driver;
                        operateOnWebDriverElement.FindWebDriverElement = findWebDriverElement;
                        operateOnWebDriverElement.JavaScriptCalls      = javaScriptCalls;
                        switchFlag = true;
                        src        = value;
                        SAFINCALog.Info("Iframe Match for " + iframeTextSrc);
                        break;
                    }
                }
            }
        }
Beispiel #8
0
        //Verify Table row Div data
        public bool verifyTableRowDivData(String className, String text)
        {
            IWebElement webelement = findWebDriverElement.waitForElementByClassName(null, null, className);
            Boolean     flag       = false;
            IReadOnlyCollection <IWebElement> elementDivList = webelement.FindElements(By.TagName("tbody"));

            try
            {
                foreach (IWebElement elementTable in elementDivList)
                {
                    IReadOnlyCollection <IWebElement> elementTrList = elementTable.FindElements(By.TagName("tr"));
                    foreach (IWebElement elementTr in elementTrList)
                    {
                        IReadOnlyCollection <IWebElement> elementTdList = elementTr.FindElements(By.TagName("td"));
                        foreach (IWebElement elementTd in elementTdList)
                        {
                            if (elementTd.Text == text)
                            {
                                SAFINCALog.Info("Status is " + text + " and as expected");
                                //break;
                                return(flag);
                            }
                        }

                        // if (flag) { break; }
                    }
                    // if (flag) { break; }
                }
                return(flag);
            }
            catch (Exception e) { SAFINCALog.TestCaseErrorMessage(e); }
            return(flag);
        }
        //Double Click a record in dynamic grid based on data-field and row number

        /*Parameter Usage
         * gridPosition : gridPosition of the dynamic grid in the page
         * field : data-field attribute of the column to select
         * row : row value can be 'first' or 'last' or actual number like '1','2' etc.
         * tag : tag on which the action should be performed
         **/
        public bool doubleClickRecordInDynamicGridBasedOnRowNumber(int gridPosition, string field, String row, String tag)
        {
            IWebElement pageElement = null;
            IReadOnlyCollection <IWebElement> tdListCollection = null; List <IWebElement> tdList = null; bool selectedFlag = false;
            int rowCount = 0;

            try
            {
                //Find the Page Element
                pageElement = findWebDriverElement.waitForElementById(null, null, "Portal");

                tdListCollection = pageElement.FindElements(By.XPath("(//div[contains(@class,'DynamicGrid')])[" + gridPosition + "]//tr[contains(@data-key,'==')]//tr[@data-field='" + field + "']"));

                if (tdListCollection.Count == 0)
                {
                    tdListCollection = pageElement.FindElements(By.XPath("(//div[contains(@class,'DynamicGrid')])[" + gridPosition + "]//tr[contains(@external-value,'==')]/td[@data-field='" + field + "']"));
                }

                if (tdListCollection.Count == 0)
                {
                    tdListCollection = pageElement.FindElements(By.XPath("(//div[contains(@class,'DynamicGrid')])[" + gridPosition + "]//tr[contains(@external-value,'=')]/td[@data-field='" + field + "']"));
                }

                tdList = new List <IWebElement>(tdListCollection);

                //Iterate over the input list
                for (int i = 0; i < tdList.Count; i++)
                {
                    if (row.Equals("first") && i == 0)
                    {
                        new Actions(driver).DoubleClick(tdList[i].FindElement(By.TagName(tag))).Perform(); break;
                    }

                    if (row.Equals("last") && i == tdList.Count - 1)
                    {
                        new Actions(driver).DoubleClick(tdList[i].FindElement(By.TagName(tag))).Perform(); break;
                    }

                    else if (int.TryParse(row, out rowCount) && i == rowCount)
                    {
                        new Actions(driver).DoubleClick(tdList[i].FindElement(By.TagName(tag))).Perform(); break;
                    }
                } // end of for each

                if (!selectedFlag)
                {
                    SAFINCALog.Info("Record Not Found"); throw new NotFoundException("Record Not Found with row:" + row);
                }

                return(selectedFlag);
            }

            catch (Exception e)
            {
                selectedFlag = false;
                return(selectedFlag);

                throw e;
            }
        }
Beispiel #10
0
        //Verify the table row data on the main panel
        public bool verifyTableRowData(String className, String text)
        {
            IWebElement webelement = findWebDriverElement.waitForElementByClassName(null, null, className);
            Boolean     flag       = false;
            IReadOnlyCollection <IWebElement> elementDivList = webelement.FindElements(By.TagName("tbody"));

            //Dictionary<String, String> attributeList = new Dictionary<string, string>();

            try
            {
                foreach (IWebElement elementTable in elementDivList)
                {
                    IReadOnlyCollection <IWebElement> elementTrList = elementTable.FindElements(By.TagName("tr"));
                    foreach (IWebElement elementTr in elementTrList)
                    {
                        IReadOnlyCollection <IWebElement> elementTdList = elementTr.FindElements(By.TagName("td"));
                        foreach (IWebElement elementTd in elementTdList)
                        {
                            if (elementTd.GetAttribute("innerHTML").Contains(text))
                            {
                                SAFINCALog.Info("Verified and passed");
                                flag = true;
                                return(flag);
                            }
                        }

                        // if (flag) { break; }
                    }
                    // if (flag) { break; }
                }
                return(flag);
            }
            catch (Exception e) { SAFINCALog.TestCaseErrorMessage(e); }
            return(flag);
        }
        public static long GetCurrentTimeMillis()
        {
            SAFINCALog.Debug(GetClassAndMethodName());
            DateTime Jan1st1970 = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);

            return((long)((DateTime.UtcNow - Jan1st1970).TotalMilliseconds));
        }
Beispiel #12
0
 /// <summary>
 /// Kill a pocess given the name of the process
 /// The process is killed if the pocess is longer than 3 seconds
 /// </summary>
 /// <param name="nameOfProcessToKill"></param>
 public static void killProcessByNames(string nameOfProcessToKill)
 {
     SAFINCALog.Debug(CommonUtilities.GetClassAndMethodName(), nameOfProcessToKill);
     string[] nameOfProcessToKillList = nameOfProcessToKill.Split(',');
     foreach (string nameOfProcess in nameOfProcessToKillList)
     {
         try
         {
             foreach (Process proc in Process.GetProcessesByName(nameOfProcess))
             {
                 DateTime procStartTime = proc.StartTime;
                 DateTime dateNow       = DateTime.Now;
                 long     diff          = (long)(dateNow - procStartTime).TotalMilliseconds;
                 //Kill the process if longer than 3 secunds
                 if (diff > 3000 && !(proc.ProcessName.ToLower().Contains("excel")))
                 {
                     proc.Refresh();
                     proc.Kill();
                 }
                 if (proc.ProcessName.ToLower().Contains("excel") && diff < 3000)
                 {
                     proc.Refresh();
                     proc.Kill();
                 }
             }
         }
         catch (Exception e)
         {
             SAFINCALog.Warning("The process, " + nameOfProcessToKill + " could not be killed. See Exception: \n" + e);
         }
         Thread.Sleep(1000);
     }
 }
        public static string GetCurrentDate()
        {
            SAFINCALog.Debug(GetClassAndMethodName());
            DateTime dt   = DateTime.Now;
            string   date = dt.ToString("dd_MM_yyyy_HH_mm_ss");

            return(date);
        }
        /// <summary>
        /// Same as {@methodref executeJavaScript} but with a WaitForAjaxCallToFinish before executing the java script
        /// </summary>
        /// <param name="pageNameToSwitchTo"></param>
        /// <param name="frameNameToSwitchTo"></param>
        /// <param name="scriptToExecute"></param>
        /// <returns></returns>
        public Object executeJavaScriptWithWaitForAjaxCallToFinish(string pageNameToSwitchTo, string frameNameToSwitchTo, string scriptToExecute)
        {
            SAFINCALog.Debug("scriptToExecute: " + scriptToExecute);
            WaitForAjaxCallToFinish();
            Object obj = ExecuteJavaScript(pageNameToSwitchTo, frameNameToSwitchTo, scriptToExecute);

            WaitForAjaxCallToFinish();
            return(obj);
        }
        /// <summary>
        /// Return a list of web element using the javascript to find element
        /// </summary>
        /// <param name="pageNameToSwitchTo"></param>
        /// <param name="frameNameToSwitchTo"></param>
        /// <param name="scriptToExecute"></param>
        /// <returns></returns>
        public ReadOnlyCollection <IWebElement> ExecuteJavaScriptIWebElementList(string pageNameToSwitchTo, string frameNameToSwitchTo, string scriptToExecute)
        {
            SAFINCALog.Debug("scriptToExecute: " + scriptToExecute);
            driver = FindWebDriverElement.SwitchToFrameOrWindowByName(this.driver, pageNameToSwitchTo, frameNameToSwitchTo);
            IJavaScriptExecutor iJavaScriptExecutor          = (IJavaScriptExecutor)driver;
            ReadOnlyCollection <IWebElement> iWebElementList = (ReadOnlyCollection <IWebElement>)iJavaScriptExecutor.ExecuteScript(scriptToExecute);

            SAFINCALog.Debug("iWebElementList: " + iWebElementList);
            return(iWebElementList);
        }
        public static string CreateFolder(string folderPath)
        {
            SAFINCALog.Debug(GetClassAndMethodName());
            string fullDirectoryPath = GetProjectDirectory() + folderPath;

            if (!Directory.Exists(fullDirectoryPath))
            {
                Directory.CreateDirectory(fullDirectoryPath);
            }
            return(fullDirectoryPath);
        }
        public static string GetProjectDirectory()
        {
            SAFINCALog.Debug(GetClassAndMethodName());
            var    outPutDirectory = GetOutPutDirectory();
            int    startIndex      = outPutDirectory.IndexOf("\\") + 1;
            int    binIndex        = outPutDirectory.IndexOf("bin");
            int    length          = binIndex - startIndex;
            string projectDir      = outPutDirectory.Substring(startIndex, length);

            return(projectDir);
        }
 /// <summary>
 /// Used Only wiht JQuery based web runningApplication
 /// </summary>
 public void WaitForAjaxCallToFinish()
 {
     SAFINCALog.Debug(CommonUtilities.GetClassAndMethodName());
     try
     {
         AjaxCallToFinish();
     }
     catch
     {
         SAFINCALog.Info(CommonUtilities.GetClassAndMethodName(), "CALLING THE JAVA SCRIPT THE FIST TIME FAILED. TRYING THE ONE MORE TIME");
         AjaxCallToFinish();
     }
 }
        /// <summary>
        /// Take a print screen and save the image as .png file.
        /// </summary>
        /// <param name="imageFullPathAndName"></param>
        public static void CreateAndSaveScreenShot(string imageFullPathAndName)
        {
            SAFINCALog.Debug(GetClassAndMethodName());
            Screen   screen   = Screen.PrimaryScreen;
            Bitmap   bmp      = new Bitmap(screen.Bounds.Width, screen.Bounds.Height);
            Graphics graphics = Graphics.FromImage(bmp);

            graphics.CopyFromScreen(0, 0, 0, 0, new Size(screen.Bounds.Width, screen.Bounds.Height));
            bmp.Save(imageFullPathAndName, ImageFormat.Png);
            string imageFullPathAndNameWithoutC    = imageFullPathAndName.Replace("C:", "").Replace("C:", "");
            string imageFullPathAndNameIncludeFile = "file://///" + System.Environment.MachineName + imageFullPathAndNameWithoutC;

            SAFINCALog.Info("The screenshot is saved: " + imageFullPathAndNameIncludeFile);
        }
Beispiel #20
0
        // Click the menu from the left side of the panel
        public void clickLeftPanelMenu(String id, String param)
        {
            IWebElement webelement = findWebDriverElement.waitForElementById(null, null, id);
            Boolean     flag       = false;
            IReadOnlyCollection <IWebElement> elementLiList = webelement.FindElements(By.TagName("li"));

            try
            {
                foreach (IWebElement elementLi in elementLiList)
                {
                    IReadOnlyCollection <IWebElement> elementUlList = elementLi.FindElements(By.TagName("ul"));

                    foreach (IWebElement elementUl in elementUlList)
                    {
                        IReadOnlyCollection <IWebElement> elementList = elementLi.FindElements(By.TagName("li"));

                        foreach (IWebElement subelementList in elementList)
                        {
                            IReadOnlyCollection <IWebElement> anchorElementList = subelementList.FindElements(By.TagName("a"));

                            foreach (IWebElement anchorElement in anchorElementList)
                            {
                                if (anchorElement.Text == param)
                                {
                                    anchorElement.Click();
                                    flag = true;
                                    break;
                                }
                            }
                            if (flag)
                            {
                                break;
                            }
                        }
                        if (flag)
                        {
                            break;
                        }
                    }
                    if (flag)
                    {
                        break;
                    }
                }
            }
            catch (Exception e) { SAFINCALog.TestCaseErrorMessage(e); }
        }
Beispiel #21
0
        //Click the table on the main panel using class
        public void clickTableRowUsingClassAndInput(String className, String text)
        {
            IWebElement webelement = findWebDriverElement.waitForElementByClassName(null, null, className);
            Boolean     flag       = false;
            IReadOnlyCollection <IWebElement> elementDivList = webelement.FindElements(By.TagName("tbody"));

            //Dictionary<String, String> attributeList = new Dictionary<string, string>();

            try
            {
                foreach (IWebElement elementTable in elementDivList)
                {
                    IReadOnlyCollection <IWebElement> elementTrList = elementTable.FindElements(By.TagName("tr"));
                    foreach (IWebElement elementTr in elementTrList)
                    {
                        IReadOnlyCollection <IWebElement> elementTdList = elementTr.FindElements(By.TagName("td"));
                        foreach (IWebElement elementTd in elementTdList)
                        {
                            IReadOnlyCollection <IWebElement> elementInputList = elementTr.FindElements(By.TagName("input"));
                            foreach (IWebElement elementInput in elementInputList)
                            {
                                if (elementInput.GetAttribute("value") == text)
                                {
                                    elementInput.Click();
                                    flag = true;
                                    break;
                                }
                            }
                            if (flag)
                            {
                                break;
                            }
                        }

                        if (flag)
                        {
                            break;
                        }
                    }
                    if (flag)
                    {
                        break;
                    }
                }
            }
            catch (Exception e) { SAFINCALog.TestCaseErrorMessage(e); }
        }
        //Method to search if a record is present in the dynamic grid or not
        public bool isRecordPresent_InputField_DynamicGrid(int gridPosition, string field, String data)
        {
            IWebElement pageElement = null;
            IReadOnlyCollection <IWebElement> TdInputList = null; bool isPresentFlag = false;

            try
            {
                //Find the Page Element
                pageElement = findWebDriverElement.waitForElementById(null, null, "Portal");

                TdInputList = pageElement.FindElements(By.XPath("(//div[contains(@class,'DynamicGrid')])[" + gridPosition + "]//tr[contains(@data-key,'==')]//input[@data-field='" + field + "']"));

                if (TdInputList.Count == 0)
                {
                    TdInputList = pageElement.FindElements(By.XPath("(//div[contains(@class,'DynamicGrid')])[" + gridPosition + "]//tr[contains(@external-value,'==')]//input[@data-field='" + field + "']"));
                }


                //Iterate over the input list
                foreach (IWebElement input in TdInputList)
                {
                    if (input.GetAttribute("value") != null && input.GetAttribute("value").Equals(data))
                    {
                        isPresentFlag = true; break;
                    }
                    else
                    {
                    }
                } // end of for each

                if (!isPresentFlag)
                {
                    SAFINCALog.Info("Record Not Found"); throw new NotFoundException();
                }

                return(isPresentFlag);
            }

            catch (Exception e)
            {
                isPresentFlag = false;
                return(isPresentFlag);

                throw e;
            }
        }
Beispiel #23
0
        //Verify the table row div data(column as index) using xpath on the main panel
        public bool verifyTableDivDataUsingXpath(String xpath, int index, String verifyText)
        {
            IWebElement webelement = findWebDriverElement.WaitForElementByXPath(null, null, xpath);
            Boolean     flag       = false;
            IReadOnlyCollection <IWebElement> elementDivList = webelement.FindElements(By.TagName("tbody"));

            Dictionary <String, String> attributeList = new Dictionary <string, string>();

            try
            {
                foreach (IWebElement elementTable in elementDivList)
                {
                    IReadOnlyCollection <IWebElement> elementTrList = elementTable.FindElements(By.TagName("tr"));
                    foreach (IWebElement elementTr in elementTrList)
                    {
                        IReadOnlyCollection <IWebElement> elementTdList = elementTr.FindElements(By.TagName("td"));
                        int counter = 0;
                        foreach (IWebElement elementTd in elementTdList)
                        {
                            if (counter == index)
                            {
                                if (elementTd.Text == verifyText)
                                {
                                    SAFINCALog.Info("Results are not expected");
                                    flag = true;
                                    return(flag);
                                    //break;
                                }
                            }
                            counter++;
                        }


                        //if (flag) { break; }
                    }
                    //if (flag) { break; }
                }
                return(flag);
            }
            catch (Exception e) { SAFINCALog.TestCaseErrorMessage(e); }
            return(flag);
        }
Beispiel #24
0
        //Click the table row using xpath with condition on the main panel
        public void clickTableRowUsingXpathWithCondition(String xpath, String verifyText, String clickText)
        {
            IWebElement webelement = findWebDriverElement.WaitForElementByXPath(null, null, xpath);
            Boolean     flag       = false;
            IReadOnlyCollection <IWebElement> elementDivList = webelement.FindElements(By.TagName("tbody"));

            Dictionary <String, String> attributeList = new Dictionary <string, string>();

            try
            {
                foreach (IWebElement elementTable in elementDivList)
                {
                    IReadOnlyCollection <IWebElement> elementTrList = elementTable.FindElements(By.TagName("tr"));
                    foreach (IWebElement elementTr in elementTrList)
                    {
                        if (elementTr.GetAttribute("innerHTML").Contains(verifyText))
                        {
                            IReadOnlyCollection <IWebElement> elementTdList = elementTr.FindElements(By.TagName("td"));
                            foreach (IWebElement elementTd in elementTdList)
                            {
                                if (elementTd.GetAttribute("innerHTML").Contains(clickText))
                                {
                                    elementTd.Click();
                                    flag = true;
                                    break;
                                }
                            }
                        }

                        if (flag)
                        {
                            break;
                        }
                    }
                    if (flag)
                    {
                        break;
                    }
                }
            }
            catch (Exception e) { SAFINCALog.TestCaseErrorMessage(e); }
        }
Beispiel #25
0
        //Verify the table row data using Class with condition to verify on the main panel
        public bool verifyTableRowDataUsingClassWithCondition(String className, String verifyText, String clickText)
        {
            IWebElement webelement = findWebDriverElement.waitForElementByClassName(null, null, className);
            Boolean     flag       = false;
            IReadOnlyCollection <IWebElement> elementDivList = webelement.FindElements(By.TagName("tbody"));

            try
            {
                foreach (IWebElement elementTable in elementDivList)
                {
                    IReadOnlyCollection <IWebElement> elementTrList = elementTable.FindElements(By.TagName("tr"));
                    foreach (IWebElement elementTr in elementTrList)
                    {
                        if (elementTr.GetAttribute("innerHTML").Contains(verifyText))
                        {
                            IReadOnlyCollection <IWebElement> elementTdList = elementTr.FindElements(By.TagName("td"));
                            foreach (IWebElement elementTd in elementTdList)
                            {
                                if (elementTd.GetAttribute("innerHTML").Contains(clickText))
                                {
                                    SAFINCALog.Info("Status is " + clickText + " which is as expected");
                                    flag = true;
                                    return(flag);
                                    //break;
                                }
                            }
                        }

                        //if (flag) { break; }
                    }
                    // if (flag) { break; }
                }
                return(flag);
            }
            catch (Exception e)
            {
                SAFINCALog.TestCaseErrorMessage(e);
            }
            return(flag);
        }
        /// <summary>
        /// Wait for a page to loaded on the screen
        /// </summary>
        private void AjaxCallToFinish()
        {
            string documentReadyState         = "";
            string documentReadyStateStripped = "";
            long   maxTimeToWait = CommonUtilities.GetCurrentTimeMillis() + CommonUtilities.GLOBAL_TIMEOUT_TIME_IN_MSEC;

            while (!documentReadyStateStripped.Equals("complete") && maxTimeToWait > CommonUtilities.GetCurrentTimeMillis())
            {
                try
                {
                    SAFINCALog.Debug(CommonUtilities.GetClassAndMethodName());
                    String scriptToExecute = "return document.readyState";
                    documentReadyState         = (string)driver.ExecuteScript(scriptToExecute);
                    documentReadyStateStripped = documentReadyState.Trim().ToLower();
                }
                catch
                {
                    SAFINCALog.Debug(CommonUtilities.GetClassAndMethodName(), "JAVASCRIPT NOT READY YET");
                    Thread.Sleep(500);
                }
            }
        }
Beispiel #27
0
        /// <summary>
        /// Deletes all the files within the specified folder
        /// </summary>
        /// <param name="folder">The folder from which we wish to delete all of the files</param>
        public static void ClearFolder(DirectoryInfo folder)
        {
            SAFINCALog.Debug(CommonUtilities.GetClassAndMethodName(), folder.FullName);
            // Iterate each file
            foreach (FileInfo file in folder.GetFiles())
            {
                try
                {
                    // Delete the file, ignoring any exceptions
                    file.Delete();
                }
                catch (Exception)
                {
                }
            }

            // For each folder in the specified folder
            foreach (DirectoryInfo subfolder in folder.GetDirectories())
            {
                // Clear all the files in the folder
                ClearFolder(subfolder);
            }
        }
Beispiel #28
0
        public static void setTestStepFinish(String status, Exception e)
        {
            try
            {
                // Test Step Error & ScreenShot Style
                testStepWorkSheet.Cells[ts_RowIndex, ts_testStepError_ColIndex].Style.WrapText      = true;
                testStepWorkSheet.Cells[ts_RowIndex, ts_testStepScreenShot_ColIndex].Style.WrapText = true;

                if (status.Equals("Pass"))
                {
                    //Set Test Step Result to Pass
                    testStepWorkSheet.Cells[ts_RowIndex, ts_testStepResult_ColIndex].Value = status;

                    testStepWorkSheet.Cells[ts_RowIndex, ts_testStepResult_ColIndex].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
                    testStepWorkSheet.Cells[ts_RowIndex, ts_testStepResult_ColIndex].Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.Green);

                    //set Test Step Error to NA
                    testStepWorkSheet.Cells[ts_RowIndex, ts_testStepError_ColIndex].Value = "NA";

                    //set Test Step Screenshot location to NA
                    testStepWorkSheet.Cells[ts_RowIndex, ts_testStepScreenShot_ColIndex].Value = "NA";

                    if (tc_Hierachy_Counter > 0)
                    {
                        subTestFailure = false;
                    }
                }

                else
                {
                    // Check for sub test case failure
                    if (!subTestFailure)
                    {
                        //Set Test Step Result to Fail
                        testStepWorkSheet.Cells[ts_RowIndex, ts_testStepResult_ColIndex].Value = status;

                        //Set the color of the status
                        testStepWorkSheet.Cells[ts_RowIndex, ts_testStepResult_ColIndex].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
                        testStepWorkSheet.Cells[ts_RowIndex, ts_testStepResult_ColIndex].Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.Red);



                        //Write Error Message in Excel
                        testStepWorkSheet.Cells[ts_RowIndex, ts_testStepError_ColIndex].Value = e.Message;

                        //set the width of the error column
                        testStepWorkSheet.Column(ts_testStepError_ColIndex).Width = 50;
                        testStepWorkSheet.Cells[ts_RowIndex, ts_testStepError_ColIndex].Style.WrapText = true;
                        testStepWorkSheet.Row(ts_RowIndex).Height = 50;
                        //testStepWorkSheet.Column(ts_testStepError_ColIndex).AutoFit();

                        CommonUtilities.CreateAndSaveScreenShot(resultFolderPath + "\\" + currentTestname + ".png");

                        Thread.Sleep(3 * 1000);

                        var uri = new Uri(resultFolderPath + "\\" + currentTestname + ".png");

                        errorTestResultFilePath = resultFolderPath + "\\" + currentTestname + ".png";

                        var cell = testStepWorkSheet.Cells[ts_RowIndex, ts_testStepScreenShot_ColIndex];

                        //cell.Hyperlink = new Uri(Environment.CurrentDirectory + "\\" + currentTestname + ".png");

                        // cell.Hyperlink = new Uri(Environment.CurrentDirectory + "\\" + currentTestname + ".png");

                        if (!(namedStyle != null))
                        {
                            namedStyle = testStepWorkSheet.Workbook.Styles.CreateNamedStyle("HyperLink");
                            namedStyle.Style.Font.UnderLine = true;
                            namedStyle.Style.Font.Color.SetColor(Color.Blue);
                        }

                        cell.Hyperlink = new ExcelHyperLink(uri.AbsoluteUri.ToString());

                        cell.StyleName = "HyperLink";
                        cell.Value     = currentTestname + ".png";
                        if (tc_Hierachy_Counter > 0)
                        {
                            subTestFailure = true;
                        }
                    }
                }

                //Increment the Row Counter
                ts_RowIndex++;
            }
            catch (Exception ex)
            {
                SAFINCALog.Info("Error Writing data to excel " + ex);
            }
        }
        /// <summary>
        /// Get the web element according to a given page name, frame name and location(identification method for the element)
        ///
        /// </summary>
        /// <param name="pageNameToSwitchTo"></param>
        /// <param name="frameNameToSwitchTo"></param>
        /// <param name="by"></param>
        /// <returns></returns>
        private IWebElement waitAndGetElement(string pageNameToSwitchTo, string frameNameToSwitchTo, params By[] by)
        {
            Exception exception = null;

            SAFINCALog.Debug(CommonUtilities.GetClassAndMethodName());
            String      errorMessage = "No Element Was Found by: " + by[0] + "\n EXCEPTION THROWN: ";
            IWebElement webElement   = null;

            if (waitForAjax)
            {
                //Check the status of the page by executing the javascipt, document.status, to see if the page is fully loaded
                //This check makes the system slower but minimize the risk of failure
                javaScriptCalls.WaitForAjaxCallToFinish();
            }
            //Max time to wait for an element
            long maxTimeToWait = CommonUtilities.GetCurrentTimeMillis() + CommonUtilities.GLOBAL_TIMEOUT_TIME_IN_MSEC;

            while (webElement == null && maxTimeToWait > CommonUtilities.GetCurrentTimeMillis())
            {
                try
                {
                    //Modify the diver by switching page and frame if needed
                    // driver = SwitchToFrameOrWindowByName(driver, pageNameToSwitchTo, frameNameToSwitchTo);

                    if (by.Length == 1)
                    {
                        var webElementList    = driver.FindElements(by[0]);
                        int nrOfFoundElements = webElementList.Count;
                        if (nrOfFoundElements > 1)
                        {
                            foreach (IWebElement webElementFromList in webElementList)
                            {
                                SAFINCALog.Warning("Tag name element: " + webElementFromList.TagName);
                                SAFINCALog.Warning("Text element: " + webElementFromList.Text);
                            }

                            errorMessage = "TOO MANY Elements Was Found by: " + by + "\n EXCEPTION THROWN: ";
                            //throw new Exception();
                        }
                        //Create a WebDriver wait to wait for the element to show on the page
                        var webDriverWait = new WebDriverWait(new SystemClock(), driver, TimeSpan.FromSeconds(CommonUtilities.GLOBAL_TIMEOUT_TIME_IN_MSEC / 1000), TimeSpan.FromMilliseconds(500));
                        webElement = webDriverWait.Until(ExpectedConditions.ElementExists(by[0]));
                    }
                    else
                    {
                        var    webElementList = driver.FindElements(by[0]);
                        string byLocator      = by[1].ToString().ToLower().Replace(" ", "");

                        if (byLocator.Contains("by.tagname"))
                        {
                            foreach (IWebElement webElementFromList in webElementList)
                            {
                                string webElementTagName = "by.tagname:" + webElementFromList.TagName.ToLower().Replace(" ", "");
                                SAFINCALog.Debug(CommonUtilities.GetClassAndMethodName(), "webElementTagName: " + webElementTagName, "byLocator: " + byLocator);
                                if (byLocator.Contains(webElementTagName))
                                {
                                    webElement = webElementFromList;
                                    break;
                                }
                            }
                        }
                        else if (byLocator.Contains("##"))
                        {
                            int    startIndex   = by[1].ToString().IndexOf("#") + 1;
                            int    endIndex     = by[1].ToString().IndexOf("##") - startIndex;
                            string s            = by[1].ToString().Substring(startIndex, endIndex);
                            int    elementIndex = int.Parse(by[1].ToString().Substring(startIndex, endIndex));
                            webElement = webElementList[elementIndex];
                        }
                    }
                }


                catch (Exception e)
                {
                    exception = e;
                    Thread.Sleep(500);
                }
            }

            if (webElement == null)
            {
                throw new DriverServiceNotFoundException(errorMessage + (exception == null? "":exception.ToString()));
            }
            return(webElement);
        }
Beispiel #30
0
 /// <summary>
 /// Clear the cache for Inernet Explorer
 /// </summary>
 public static void ClearIECache()
 {
     SAFINCALog.Debug(CommonUtilities.GetClassAndMethodName());
     // Clear the special cache folder
     ClearFolder(new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.InternetCache)));
 }