//Descontinuada //private int Convert.ToInt32(NpgsqlDataReader dr) //{ // if (dr != null) // { // if (dr.HasRows && dr.Read()) // { // int id = Convert.ToInt32(dr["ID"].ToString()); // dr.Close(); // return id; // } // else // { // return 0; // } // } // else // { // return 0; // } //} public int StartTest(string customerName, string suiteName, string scenarioName, string testName, string testType, string analystName, string testDesc, int ReportID = 0, int deleteFlag = 1) { Print("", null); customerName = Slugify(customerName); CstID = Convert.ToInt32(Call("arch.update_cst", "customer:" + customerName)); Print("Customer ID: " + CstID.ToString() + " [ " + customerName + " ]", null); SuiteName = Slugify(suiteName); SitID = Convert.ToInt32(Call("auto.update_sit", "cst_id:" + CstID.ToString(), "suite:" + SuiteName)); Print("Suite ID: " + SitID.ToString() + " [ " + suiteName + " ]", null); ScenarioName = Slugify(scenarioName); ScnID = Convert.ToInt32(Call("auto.update_scn", "cst_id:" + CstID.ToString(), "scenario:" + ScenarioName)); Print("Scenario ID: " + ScnID.ToString() + " [ " + ScenarioName + " ]", null); TestName = Slugify(testName); TestType = testType; TestDesc = testDesc; AnalystName = analystName; TstID = Convert.ToInt32(Call("auto.update_tst", "cst_id:" + CstID.ToString(), "sit_id:" + SitID.ToString(), "scn_id:" + ScnID.ToString(), "test:" + TestName, "type:" + TestType, "desc:" + TestDesc, "analyst:" + AnalystName)); Print("Test ID: " + TstID.ToString() + " [ " + TestName + " ]", null); Print("", null); if (ReportID != 0 && deleteFlag == 1) { Call("auto.delete_rpt", "cst_id:" + CstID.ToString(), "rpt_id:" + ReportID.ToString(), "sit_id:" + SitID.ToString(), "scn_id:" + ScnID.ToString(), "tst_id:" + TstID.ToString()); } if (TemConexao) { RptID = Convert.ToInt32(Call("auto.update_rpt", "cst_id:" + CstID.ToString(), "sit_id:" + SitID.ToString(), "scn_id:" + ScnID.ToString(), "tst_id:" + TstID.ToString(), "rpt_id:" + ReportID.ToString(), "status:pendente")); if (RptID == 0) { return(0); } ; } else { RptID = ReportID; } Print("Report ID: " + RptID.ToString(), null); if (deleteFlag == 1) { Call("auto.delete_lgs", "cst_id:" + CstID.ToString(), "sit_id:" + SitID.ToString(), "scn_id:" + ScnID.ToString(), "tst_id:" + TstID.ToString(), "rpt_id:" + RptID.ToString()); Call("auto.delete_stp", "cst_id:" + CstID.ToString(), "tst_id:" + TstID.ToString()); } return(RptID); }
public int StartTest(string customerName, string suiteName, string scenarioName, string testName, string testType, string analystName, string testDesc, int reportID = 0, int deleteFlag = 1, string statusType = "worst") { try { if (Connected == false) { Print("--------------------------------------------------------------------------------", null); Print(" Report Database Offline", null); } Print("--------------------------------------------------------------------------------", null); CustomerName = Slugify(customerName); CstID = Convert.ToInt32(Call("arch.update_cst", "customer:" + CustomerName)); Print(" Customer ID: " + CstID.ToString() + " [" + CustomerName + "]", null); SuiteName = Slugify(suiteName); SitID = Convert.ToInt32(Call("auto.update_sit", "cst_id:" + CstID.ToString(), "suite:" + SuiteName)); Print(" Suite ID: " + SitID.ToString() + " [" + SuiteName + "]", null); ScenarioName = Slugify(scenarioName); ScnID = Convert.ToInt32(Call("auto.update_scn", "cst_id:" + CstID.ToString(), "scenario:" + ScenarioName)); Print(" Scenario ID: " + ScnID.ToString() + " [" + ScenarioName + "]", null); TestName = Slugify(testName); TestType = testType; TestDesc = testDesc; AnalystName = analystName; TstID = Convert.ToInt32(Call("auto.update_tst", "cst_id:" + CstID.ToString(), "sit_id:" + SitID.ToString(), "scn_id:" + ScnID.ToString(), "test:" + TestName, "type:" + TestType, "desc:" + TestDesc, "analyst:" + AnalystName, "status:" + statusType)); Print(" Test ID: " + TstID.ToString() + " [" + TestName + "]", null); Print("--------------------------------------------------------------------------------", null); if (deleteFlag == 1) { if (ReportID != 0) { Call("auto.delete_rpt", "cst_id:" + CstID.ToString(), "rpt_id:" + reportID.ToString(), "sit_id:" + SitID.ToString(), "scn_id:" + ScnID.ToString(), "tst_id:" + TstID.ToString()); Call("auto.delete_lgs", "cst_id:" + CstID.ToString(), "sit_id:" + SitID.ToString(), "scn_id:" + ScnID.ToString(), "tst_id:" + TstID.ToString(), "rpt_id:" + reportID.ToString()); } Call("auto.delete_stp", "cst_id:" + CstID.ToString(), "tst_id:" + TstID.ToString()); } RptID = Convert.ToInt32(Call("auto.update_rpt", "cst_id:" + CstID.ToString(), "sit_id:" + SitID.ToString(), "scn_id:" + ScnID.ToString(), "tst_id:" + TstID.ToString(), "rpt_id:" + reportID.ToString(), "status:pendente")); Print(" Report ID: " + RptID.ToString(), null); Print("--------------------------------------------------------------------------------", null); return(RptID); } catch (Exception ex) { throw new Exception(Print("Exception at StartTest", ex)); } }
//Descontinuado //public Image ByteToImage(int CstId, int RptId, int lgsID, string file_full_path) //{ // try // { // NpgsqlDataReader dr = Call("auto.get_image", "cst_id:" + CstId.ToString(), "rpt_id:" + RptId.ToString(), "lgs_id:" + lgsID.ToString()); // if (dr.HasRows && dr.Read()) // { // MemoryStream ms = new MemoryStream((byte[])dr["image_data"]); // Image img = Image.FromStream(ms, true); // dr.Close(); // return img; // } // else // { // dr.Close(); // return null; // } // } // catch (Exception ex) // { // Print("ByteToImage", ex); // return null; // } //} public void EndTest(int ReportID = 0, string status = "pronto", bool deleteReport = false) { try { if (this.SitID == 0) { throw new Exception(Print("EndTest(SitID=0)", null)); } if (this.ScnID == 0) { throw new Exception(Print("EndTest(ScnID=0)", null)); } if (this.TstID == 0) { throw new Exception(Print("EndTest(TstID=0)", null)); } if (this.RptID == 0) { throw new Exception(Print("EndTest(RptID=0)", null)); } if (deleteReport == true || ReportID == 0) { Call("auto.delete_rpt", "cst_id:" + CstID.ToString(), "rpt_id:" + RptID.ToString()); } if (Conexao.ConexaoAberta()) { Conexao.FecharConexao(); Print("End Test", null); } } catch (Exception ex) { Print("EndTest", ex); } }
public int StartStep(string desc, int turn = 1, string status = "executando", string logMsg = "", string paramName = "", string paramValue = "") { try { if (this.CstID == 0) { throw new Exception(Print("StartStep(CstID=0)", null)); } if (this.SitID == 0) { throw new Exception(Print("StartStep(SitID=0)", null)); } if (this.ScnID == 0) { throw new Exception(Print("StartStep(ScnID=0)", null)); } if (this.TstID == 0) { throw new Exception(Print("StartStep(TstID=0)", null)); } if (this.RptID == 0) { throw new Exception(Print("StartStep(RptID=0)", null)); } if (status == "executando") { string logLine = " Step " + GetStepNumber(desc).ToString() + "." + turn.ToString() + ": " + desc; if (logMsg != "" || paramName != "") { logLine = logLine + " ("; if (logMsg != "") { logLine = logLine + "Obs: " + logMsg; if (paramName != "") { logLine = logLine + " - "; } } if (paramName != "") { logLine = logLine + "Parameter: " + paramName + " = " + paramValue; logLine = logLine + ")"; } } Print("StartStep('')", null); Print("StartStep(" + logLine + ")", null); } return(Convert.ToInt32(Call("auto.update_lgs", "cst_id:" + CstID.ToString(), "sit_id:" + SitID.ToString(), "scn_id:" + ScnID.ToString(), "tst_id:" + TstID.ToString(), "rpt_id:" + RptID.ToString(), "dsc:" + desc, "turn_id:" + turn.ToString(), "status:" + status, "log_msg:" + logMsg, "param_name:" + paramName, "param_value:" + paramValue))); } catch (Exception ex) { throw new Exception(Print("StartStep", ex)); } }
public int DoStep(string desc, string expected_result = "", string status = "active", int newStep = 1) { try { if (this.CstID == 0) { throw new Exception(Print("DoStep(CstID=0)", null)); } if (this.SitID == 0) { throw new Exception(Print("DoStep(SitID=0)", null)); } if (this.ScnID == 0) { throw new Exception(Print("DoStep(ScnID=0)", null)); } if (this.TstID == 0) { throw new Exception(Print("DoStep(TstID=0)", null)); } if (this.RptID == 0) { throw new Exception(Print("DoStep(RptID=0)", null)); } StepNumber = Convert.ToInt32(Call("auto.update_stp", "cst_id:" + CstID.ToString(), "tst_id:" + TstID.ToString(), "dsc:" + desc, "expected_result:" + expected_result, "status:" + status)); if (newStep == 1) { Call("auto.delete_lgs", "cst_id:" + CstID.ToString(), "sit_id:" + SitID.ToString(), "scn_id:" + ScnID.ToString(), "tst_id:" + TstID.ToString(), "rpt_id:" + RptID.ToString(), "description:" + desc); } Call("auto.count_stp", "cst_id:" + CstID.ToString(), "tst_id:" + TstID.ToString()); StartStep(desc, 1, status = "pendente"); return(StepNumber); } catch (Exception ex) { throw new Exception(Print("DoStep", ex)); } }
public string PrintPageComSelenium(IWebDriver driver, bool full = false, int sleep = 0) { try { if (sleep > 0) { System.Threading.Thread.Sleep(sleep * 1000); } //Create base directory and set image filename string printPath = GetAppPath() + "/Prints" + "/" + CustomerName + "/" + RptID.ToString() + "/" + SuiteName + "/" + ScenarioName + "/" + TestName; if (!Directory.Exists(printPath)) { Directory.CreateDirectory(printPath); } string filename = printPath + "/" + StepNumber.ToString().PadLeft(4, '0') + "_" + StepTurn.ToString().PadLeft(2, '0') + "-" + TestName.Replace("-", "_") + ".png"; if (File.Exists(filename)) { File.Delete(filename); } if (full) { /* * Dispositivo Width X Heigh * Reponsive 400 X 1397 * Galaxy S5 360 X 640 * Pixel 2 411 X 731 * Pixel 2 XL 411 X 823 * iPhone 5/SE 320 X 568 * iPhone 6/7/8 375 X 667 * iPhone 6/7/8 Plus 414 X 736 * iPhone X 375 X 812 * iPad 768 X 1024 * iPad Pro 1024 X 1366 */ Bitmap stitchedImage = null; // First scroll to load all page components ((IJavaScriptExecutor)driver).ExecuteScript(String.Format("window.scrollBy({0}, {1})", 0, -100000)); for (int p = 0; p < 200; p++) { ((IJavaScriptExecutor)driver).ExecuteScript(String.Format("window.scrollBy({0}, {1})", 0, 500)); System.Threading.Thread.Sleep(5); } ((IJavaScriptExecutor)driver).ExecuteScript(String.Format("window.scrollBy({0}, {1})", 0, -100000)); System.Threading.Thread.Sleep(200); // Get full page size long totalwidth1 = (long)((IJavaScriptExecutor)driver).ExecuteScript("return document.body.offsetWidth");//documentElement.scrollWidth"); long totalHeight1 = (long)((IJavaScriptExecutor)driver).ExecuteScript("return document.body.parentNode.scrollHeight"); int totalWidth = (int)totalwidth1; int totalHeight = (int)totalHeight1; // Get viewport size long viewportWidth1 = (long)((IJavaScriptExecutor)driver).ExecuteScript("return document.body.clientWidth"); //documentElement.scrollWidth"); long viewportHeight1 = (long)((IJavaScriptExecutor)driver).ExecuteScript("return window.innerHeight"); //documentElement.scrollWidth"); int viewportWidth = (int)viewportWidth1; int viewportHeight = (int)viewportHeight1; // Split screen in multiple rectangles List <Rectangle> rectangles = new List <Rectangle>(); // Loop until total height for (int i = 0; i < totalHeight; i += viewportHeight) { int newHeight = viewportHeight; // Fix if element height too big if (i + viewportHeight > totalHeight) { newHeight = totalHeight - i; } // Loop until total width for (int ii = 0; ii < totalWidth; ii += viewportWidth) { int newWidth = viewportWidth; // Fix if element width too big if (ii + viewportWidth > totalWidth) { newWidth = totalWidth - ii; } // Create and add new rectangle Rectangle currRect = new Rectangle(ii, i, newWidth, newHeight); rectangles.Add(currRect); } } // Build image stitchedImage = new Bitmap(totalWidth, totalHeight); // Get all screenshots together Rectangle previous = Rectangle.Empty; foreach (var rectangle in rectangles) { // Calculate needed scrolling if (previous != Rectangle.Empty) { int xDiff = rectangle.Right - previous.Right; int yDiff = rectangle.Bottom - previous.Bottom; ((IJavaScriptExecutor)driver).ExecuteScript(String.Format("window.scrollBy({0}, {1})", xDiff, yDiff)); System.Threading.Thread.Sleep(200); } // Take screenshot var screenshot = ((ITakesScreenshot)driver).GetScreenshot(); // Build an image from the screenshot Image screenshotImage; using (MemoryStream memStream = new MemoryStream(screenshot.AsByteArray)) { screenshotImage = Image.FromStream(memStream); } // Calculate source rectangle Rectangle sourceRectangle = new Rectangle(viewportWidth - rectangle.Width, viewportHeight - rectangle.Height, rectangle.Width, rectangle.Height); // Copy image using (Graphics g = Graphics.FromImage(stitchedImage)) { g.DrawImage(screenshotImage, rectangle, sourceRectangle, GraphicsUnit.Pixel); } // Set previous rectangle previous = rectangle; } // Save image file stitchedImage.Save(filename, ImageFormat.Png); } else { Screenshot ss = ((ITakesScreenshot)driver).GetScreenshot(); ss.SaveAsFile(filename, ScreenshotImageFormat.Png); } return(filename); } catch (Exception ex) { Print("Exception at PrintPageComSelenium", ex); return(null); } }
public void GetReportURL() { try { if (String.IsNullOrEmpty(CustomerName)) { throw new Exception(Print("GetReportURL [CustomerName='']", null)); } if (RptID == 0) { throw new Exception(Print("GetReportURL [RptID=0]", null)); } if (Connected) { if (String.IsNullOrEmpty(ReportTitle)) { throw new Exception(Print("GetReportURL [ReportTitle='']", null)); } if (String.IsNullOrEmpty(AnalystName)) { throw new Exception(Print("GetReportURL [AnalystName='']", null)); } Conn.OpenConn(); if (Conn.ConnOpened()) { URLDomain = Call("auto.get_conf", "cst_name:" + CustomerName, "conf_name:" + "export_url_domain"); string profileParam = ""; if (ReportProfile != "") { profileParam = "&profile=" + ReportProfile; } string CompileURL = URLDomain + "/portal/auto/reports/update.php?customer_name=" + CustomerName + "&rpt_id=" + RptID.ToString() + "&rpt_title=" + ReportTitle + "&rpt_obs=" + ReportObs + "&rpt_analyst=" + AnalystName + profileParam; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(CompileURL); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); string URLReturn = new StreamReader(response.GetResponseStream()).ReadToEnd(); if (URLReturn.Contains("[Done]")) { Print(" Relatório gerado com sucesso! Clique no link abaixo:", null); Print(" " + URLDomain + "/portal/auto/reports/" + CustomerName + "/" + RptID.ToString(), null); } else { Print(" Relatório gerado com erro!", null); Print(CompileURL, null); } } Conn.CloseConn(); } else { Print(" Teste executado, porém o relatório não foi atualizado. Clique no link abaixo para acessar o último relatório disponível:", null); Print(" " + URLDomain + "/portal/auto/reports/" + CustomerName + "/" + ReportID.ToString(), null); } } catch (Exception ex) { Print("Exception at GetReportURL", ex); } }
public void EndTest(int reportID = 0, string status = "pronto", bool deleteReport = false) { try { if (CstID == 0) { throw new Exception(Print("EndTest [CstID=0]", null)); } if (RptID == 0) { throw new Exception(Print("EndTest [RptID=0]", null)); } if (SitID == 0) { throw new Exception(Print("EndTest [SitID=0]", null)); } if (ScnID == 0) { throw new Exception(Print("EndTest [ScnID=0]", null)); } if (TstID == 0) { throw new Exception(Print("EndTest [TstID=0]", null)); } if (deleteReport == true || reportID == 0) { Call("auto.delete_rpt", "cst_id:" + CstID.ToString(), "rpt_id:" + RptID.ToString(), "sit_id:" + SitID.ToString(), "scn_id:" + ScnID.ToString(), "tst_id:" + TstID.ToString()); } Print("--------------------------------------------------------------------------------", null); GetReportURL(); Print("--------------------------------------------------------------------------------", null); if (Conn.ConnOpened()) { Conn.CloseConn(); } } catch (Exception ex) { Print("Exception at EndTest", ex); } }
public int StartStep(string stepDesc, int turn = 0, string status = "executando", string logMsg = "", string paramName = "", string paramValue = "") { try { if (CstID == 0) { throw new Exception(Print("StartStep [CstID=0]", null)); } if (SitID == 0) { throw new Exception(Print("StartStep [SitID=0]", null)); } if (ScnID == 0) { throw new Exception(Print("StartStep [ScnID=0]", null)); } if (TstID == 0) { throw new Exception(Print("StartStep [TstID=0]", null)); } if (RptID == 0) { throw new Exception(Print("StartStep [RptID=0]", null)); } StepName = stepDesc; if (turn == 0) { StepTurn = NextTurn(GetStepNumber(StepName)); } else { StepTurn = turn; } if (status == "executando") { string logLine = " Step " + GetStepNumber(StepName).ToString() + "." + StepTurn.ToString() + ": " + StepName; if (logMsg != "" || paramName != "") { logLine = logLine + " ("; if (logMsg != "") { logLine = logLine + "Obs: " + logMsg; if (paramName != "") { logLine = logLine + " - "; } } if (paramName != "") { logLine = logLine + "Parameter: " + paramName + " = " + paramValue; } logLine = logLine + ")"; } Print(logLine, null); } return(Convert.ToInt32(Call("auto.update_lgs", "cst_id:" + CstID.ToString(), "sit_id:" + SitID.ToString(), "scn_id:" + ScnID.ToString(), "tst_id:" + TstID.ToString(), "rpt_id:" + RptID.ToString(), "dsc:" + StepName, "turn_id:" + StepTurn.ToString(), "status:" + status, "log_msg:" + logMsg, "param_name:" + paramName, "param_value:" + paramValue))); } catch (Exception ex) { throw new Exception(Print("Exception at StartStep", ex)); } }
public int NextTurn(int stepNumber, string mode = "add") { try { if (CstID == 0) { throw new Exception(Print("NextTurn [CstID=0]", null)); } if (RptID == 0) { throw new Exception(Print("NextTurn [RptID=0]", null)); } if (SitID == 0) { throw new Exception(Print("NextTurn [SitID=0]", null)); } if (ScnID == 0) { throw new Exception(Print("NextTurn [ScnID=0]", null)); } if (TstID == 0) { throw new Exception(Print("NextTurn [TstID=0]", null)); } if (Connected) { StepTurn = Convert.ToInt32(Call("auto.get_trn_num", "cst_id:" + CstID.ToString(), "rpt_id:" + RptID.ToString(), "sit_id:" + SitID.ToString(), "scn_id:" + ScnID.ToString(), "tst_id:" + TstID.ToString(), "step_id:" + stepNumber.ToString())); if (mode == "add") { StepTurn += 1; } } else { StepTurn = LocalTurn(TestName, StepName, mode); } return(StepTurn); } catch (Exception ex) { throw new Exception(Print("Exception at NextTurn", ex)); } }
public int DoStep(string stepDesc, string expectedResult = "", string status = "active", int newStep = 1) { try { if (CstID == 0) { throw new Exception(Print("DoStep [CstID=0]", null)); } if (SitID == 0) { throw new Exception(Print("DoStep [SitID=0]", null)); } if (ScnID == 0) { throw new Exception(Print("DoStep [ScnID=0]", null)); } if (TstID == 0) { throw new Exception(Print("DoStep [TstID=0]", null)); } if (RptID == 0) { throw new Exception(Print("DoStep [RptID=0]", null)); } if (Connected) { StepNumber = Convert.ToInt32(Call("auto.update_stp", "cst_id:" + CstID.ToString(), "tst_id:" + TstID.ToString(), "dsc:" + stepDesc, "expected_result:" + expectedResult, "status:" + status)); } else { StepNumber = LocalTurn(TestName + "_DoStep", stepDesc + "_DoStep"); } if (newStep == 1) { Call("auto.delete_lgs", "cst_id:" + CstID.ToString(), "sit_id:" + SitID.ToString(), "scn_id:" + ScnID.ToString(), "tst_id:" + TstID.ToString(), "rpt_id:" + RptID.ToString(), "description:" + stepDesc); StartStep(stepDesc, 1, status = "pendente"); } Call("auto.count_stp", "cst_id:" + CstID.ToString(), "tst_id:" + TstID.ToString()); return(StepNumber); } catch (Exception ex) { throw new Exception(Print("Exception at DoStep", ex)); } }