Beispiel #1
0
 public QADataGridRow GetRowWithHotkeys(string columnName, string textInColumn)
 {
     if (QAWait.Until(() => RowCount > 0, 5000))
     {
         if (!UIItem.ScrollBars.Vertical.IsScrollable)
         {
             GetRow(0).Click();
             if (!GetSelectedRow().Exists)
             {
                 Desktop.Instance.Keyboard.PressSpecialKey(KeyboardInput.SpecialKeys.DOWN);
                 Desktop.Instance.Keyboard.PressSpecialKey(KeyboardInput.SpecialKeys.DOWN);
                 SelectFirstRow();
             }
         }
         else
         {
             ScrollUpWithHotKeys();
             SelectFirstRow();
         }
         while (!UIItem.ScrollBars.Vertical.IsMaximal())
         {
             var row = GetSelectedRow();
             if (row.GetValueFromColumn(columnName) == textInColumn)
             {
                 return(row);
             }
             Desktop.Instance.Keyboard.PressSpecialKey(KeyboardInput.SpecialKeys.DOWN);
         }
         return(new QADataGridRow(null, "Row from grid"));
     }
     return(new QADataGridRow(null, "Row from grid"));
 }
Beispiel #2
0
 /// <summary>
 ///     Sets UI to a specific row
 ///     <param name="someTextInRow">Some text, which contained in row</param>
 ///     <returns>true if row found</returns>
 /// </summary>
 public bool SelectDataGridRow(string textInRow)
 {
     QAWait.Until(() => RowCount > 0, 5000);
     for (var rowCount = 0; rowCount < RowCount; rowCount++)
     {
         var row        = GetRow(rowCount);
         var textForRow = row.GetTextFromAllCells();
         if (textForRow.Contains(textInRow))
         {
             row.Click();
             return(true);
         }
     }
     return(false);
 }
        /// <summary>
        ///     Screenshot method using the ChromeAutomationDriver.Driver object
        /// </summary>
        /// <param name="element">IWebElement</param>
        /// <param name="reportLevel">'debug' to include all screenshots. Or 'noscreenshots' to exclude screenshots</param>
        private static void CaptureChromeScreenshot(IWebElement element)
        {
            try
            {
                var ss = ((ITakesScreenshot)Report.Driver).GetScreenshot();

                // Get the real screen location of the element
                const string javascript = "return arguments[0].getBoundingClientRect()";
                var          obj        = (Dictionary <string, object>)((IJavaScriptExecutor)Report.Driver).ExecuteScript(javascript, element);
                var          rect       = new Rectangle((int)double.Parse(obj["left"].ToString()), (int)double.Parse(obj["top"].ToString()), (int)double.Parse(obj["width"].ToString()), (int)double.Parse(obj["height"].ToString()));

                if (rect.Width == 0 || rect.Height == 0)
                {
                    Report.Output(Report.Level.Action, "Unable to take a screenshot of the element. Height or Width is equal zero.");
                    return;
                }

                using (var ms = new MemoryStream(ss.AsByteArray))
                {
                    using (var img = Image.FromStream(ms))
                    {
                        var bmp = new Bitmap(rect.Width, rect.Height);
                        using (var gr = Graphics.FromImage(bmp))
                        {
                            gr.DrawImage(img, new Rectangle(0, 0, bmp.Width, bmp.Height), rect, GraphicsUnit.Pixel);
                        }

                        var now       = string.Format("{0:yyyy-MM-dd_hh-mm-ss-f}", DateTime.Now);
                        var imageName = "Image_" + now + ".png";
                        var fileName  = ScreenshotDirectory + imageName;

                        bmp.Save(fileName, ImageFormat.Png);

                        QAWait.Until(() => File.Exists(fileName));
                    }
                }
            }
            catch (Exception e)
            {
                Report.Output(Report.Level.Debug, "Unable to take screenshot. Exception occured: " + e.Message);
            }
        }