Ejemplo n.º 1
0
        public void GivenTheTestCaseTitleIs(string p0)
        {
            ExcelRecord record = new ExcelRecord();

            record.FeatureName  = FeatureContext.Current.FeatureInfo.Title;
            record.ScenarioName = ScenarioContext.Current.ScenarioInfo.Title + p0;
            ContextPage.GetInstance().SetExcelRecord(record);
        }
Ejemplo n.º 2
0
        public void AfterScenario()
        {
            ExcelRecord rec = ContextPage.GetInstance().GetExcelRecord();

            if (!(rec == null))
            {
                if (ScenarioContext.Current.TestError == null && (rec.ExpectedResult == null && rec.ActualResult == null))
                {
                    rec.Result = "PASS";
                }
                if (rec.ExpectedResult == null && rec.ActualResult == null && ScenarioContext.Current.TestError != null)
                {
                    rec.Result = "FAIL";
                    string error = ScenarioContext.Current.TestError.Message;
                    error            = error.Replace(",", " ");
                    error            = error.Replace("\n", " ");
                    error            = error.Replace("\r\n", " ");
                    error            = error.Replace("\r", " ");
                    rec.ErrorMessage = error;
                }
                if (rec.ExpectedResult != null && rec.ActualResult != null)
                {
                    if (rec.ExpectedResult.Equals(rec.ActualResult) && ScenarioContext.Current.TestError == null)
                    {
                        rec.Result = "PASS";
                    }
                    else
                    {
                        if (ScenarioContext.Current.TestError != null)

                        {
                            rec.Result = "FAIL";
                            string error = ScenarioContext.Current.TestError.Message;
                            error            = error.Replace(",", " ");
                            error            = error.Replace("\n", " ");
                            error            = error.Replace("\r\n", " ");
                            error            = error.Replace("\r", " ");
                            rec.ErrorMessage = error;
                        }
                    }
                }


                ContextPage.GetInstance().SetExcelRecord(rec);
            }
            ExcelWriter.GetInstance().excelRecord.Add(ContextPage.GetInstance().GetExcelRecord());

            //Flyshing Out Contextual Data//
            //ContextPage.GetInstance().ResetPostData();
            //Flyshing Out Contextual Data//
        }
Ejemplo n.º 3
0
        public void WhenGetRequestIsMade()
        {
            ExcelRecord    rec       = ContextPage.GetInstance().GetExcelRecord();
            RestProperties rest_prop = new RestProperties();
            IRestResponse  response  = rest_prop.CallGetAPIRequest();

            context.Set_Response(response);
            string ali         = response.Content.ToString();
            string replacement = Regex.Replace(ali, "\"|{|}", "");

            replacement  = replacement.Replace(",", "   ");
            rec.Response = replacement;
            ContextPage.GetInstance().SetExcelRecord(rec);
        }
Ejemplo n.º 4
0
        public void WhenPostRequestIsMade()
        {
            ExcelRecord    rec       = ContextPage.GetInstance().GetExcelRecord();
            RestProperties rest_prop = new RestProperties();
            string         format    = context.Get_api_format();
            IRestResponse  response  = rest_prop.CallPostAPIRequest(format);
            int            code      = (int)response.StatusCode;

            context.Set_Response(response);
            string replacement = response.Content.ToString();

            if (context.Get_api_format() == "xml")
            {
                replacement = replacement.Replace("\n", "");
            }
            if (context.Get_api_format() == "json")
            {
                replacement = Regex.Replace(replacement, "\"|{|}", "");
                replacement = replacement.Replace(",", "   ");
            }
            rec.Response = replacement;
            ContextPage.GetInstance().SetExcelRecord(rec);
        }
Ejemplo n.º 5
0
 public void SetExcelRecord(ExcelRecord record)
 {
     excelRecord = record;
 }
Ejemplo n.º 6
0
        public void AfterScenario()
        {
            ExcelRecord rec = ContextPage.GetInstance().GetExcelRecord();

            if (!(rec == null))
            {
                if (ScenarioContext.Current.TestError == null && (rec.ExpectedResult == null && rec.ActualResult == null))
                {
                    rec.Result = "PASS";
                }
                if (rec.ExpectedResult == null && rec.ActualResult == null && ScenarioContext.Current.TestError != null)
                {
                    rec.Result = "FAIL";
                    string error = ScenarioContext.Current.TestError.Message;
                    error            = error.Replace(",", " ");
                    error            = error.Replace("\n", " ");
                    error            = error.Replace("\r\n", " ");
                    error            = error.Replace("\r", " ");
                    rec.ErrorMessage = error;
                }
                //if (rec.ExpectedResult != null && rec.ActualResult != null)
                //{
                //    if (rec.ExpectedResult.Equals(rec.ActualResult) && ScenarioContext.Current.TestError == null)
                //    {
                //        rec.Result = "PASS";
                //    }
                //    else
                //    {
                //        if (ScenarioContext.Current.TestError != null)

                //        {
                //            rec.Result = "FAIL";
                //            string error = ScenarioContext.Current.TestError.Message;
                //            error = error.Replace(",", " ");
                //            error = error.Replace("\n", " ");
                //            error = error.Replace("\r\n", " ");
                //            error = error.Replace("\r", " ");
                //            rec.ErrorMessage = error;

                //        }
                //    }

                //}

                if (rec.ExpectedResult != null)
                {
                    if (rec.ExpectedResult.ToLower() == "pass")
                    {
                        if (Common.Configuration.GetInstance().GetByKey("Record_Video").ToLower() == "yes")
                        {
                            AndroidDriver <AndroidElement> driver = (AndroidDriver <AndroidElement>)ContextPage.Driver;
                            string video        = driver.StopRecordingScreen();
                            string FeatureName  = ContextPage.GetInstance().GetExcelRecord().FeatureName;
                            string savelocation = Common.Configuration.GetInstance().GetByKey("ScreenshotFolderPath") + FeatureName + DateTime.Now.ToString("yyyyMMdd") + "/Videos/";
                            if (savelocation.Contains("{Device_Name}"))
                            {
                                savelocation = savelocation.Replace("{Device_Name}", Common.Configuration.GetInstance().GetByKey("deviceName").ToString());
                            }
                            byte[] decode = Convert.FromBase64String(video);
                            if (!Directory.Exists(savelocation))
                            {
                                Directory.CreateDirectory(savelocation);
                            }
                            string fileName = ContextPage.GetInstance().GetExcelRecord().ScenarioName + DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".mp4";
                            rec.VideoPath = savelocation + fileName;
                            File.WriteAllBytes(savelocation + fileName, decode);
                        }
                    }
                    if (ScenarioContext.Current.TestError == null)
                    {
                        rec.Result = "PASS";
                    }
                    else
                    {
                        if (ScenarioContext.Current.TestError != null)

                        {
                            rec.Result = "FAIL";
                            string error = ScenarioContext.Current.TestError.Message;
                            error            = error.Replace(",", " ");
                            error            = error.Replace("\n", " ");
                            error            = error.Replace("\r\n", " ");
                            error            = error.Replace("\r", " ");
                            rec.ErrorMessage = error;
                        }
                    }
                }


                ContextPage.GetInstance().SetExcelRecord(rec);
            }
            ExcelWriter.GetInstance().excelRecord.Add(ContextPage.GetInstance().GetExcelRecord());

            //Flyshing Out Contextual Data//
            //ContextPage.GetInstance().ResetPostData();
            //Flyshing Out Contextual Data//
        }
Ejemplo n.º 7
0
        ////For Taking Screenshot
        public static void TakeScreenshot()
        {
            try
            {
                AndroidDriver <AndroidElement> driver = (AndroidDriver <AndroidElement>)ContextPage.Driver;
                string FeatureName  = ContextPage.GetInstance().GetExcelRecord().FeatureName;
                string savelocation = Configuration.GetInstance().GetByKey("ScreenshotFolderPath") + FeatureName + DateTime.Now.ToString("yyyyMMdd") + "/";
                if (savelocation.Contains("{Device_Name}"))
                {
                    savelocation = savelocation.Replace("{Device_Name}", Common.Configuration.GetInstance().GetByKey("deviceName").ToString());
                }
                Screenshot sc = ((ITakesScreenshot)driver).GetScreenshot();
                if (!Directory.Exists(savelocation))
                {
                    Directory.CreateDirectory(savelocation);
                }
                string fileName = ContextPage.GetInstance().GetExcelRecord().ScenarioName + DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".png";
                sc.SaveAsFile(savelocation + fileName, ScreenshotImageFormat.Png);
                ExcelRecord record = ContextPage.GetInstance().GetExcelRecord();
                record.ScreenshotPath = savelocation + fileName;
                ContextPage.GetInstance().SetExcelRecord(record);
                //using (MemoryStream mStream = new MemoryStream(sct.AsByteArray))
                //{
                //    try
                //    {
                //        Image im = Image.FromStream(mStream);
                //        im.Save(fileName, ImageFormat.Png);
                //    }

                //    catch(Exception ex)
                //    {
                //        throw new Exception(ex.Message);
                //    }
                //    //im.Save(fileName, ImageFormat.Png);
                //}
                //Setting Screenshot Path
                //ExcelRecord record = new ExcelRecord();
                //record.ScreenshotPath = savelocation;
                //ContextPage.GetInstance().SetExcelRecord(record);


                //Screenshot screenshot = driver.GetScreenshot();
                //String filename = UUID.randomUUID().toString();
                //File targetFile = new File(path_screenshot + filename + ".jpg");
                //FileUtils.copyFile(srcFile, targetFile);
                //ITakesScreenshot ssdriver = ContextPage.Driver as ITakesScreenshot;
                //Screenshot screenshot = ssdriver.GetScreenshot();
                //string fileName = ContextPage.GetInstance().GetExcelRecord().ScenarioName + ".png";
                //screenshot.SaveAsFile(savelocation + fileName, ScreenshotImageFormat.Png);

                //Rectangle bounds = Screen.GetBounds(Point.Empty);

                //using (Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height))
                //{
                //    using (Graphics g = Graphics.FromImage(bitmap))
                //    {
                //        g.CopyFromScreen(Point.Empty, Point.Empty, bounds.Size);
                //    }
                //    string fileName = ContextPage.GetInstance().GetExcelRecord().ScenarioName + DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".png";
                //    bitmap.Save(savelocation + fileName, ImageFormat.Png);
                //    ExcelRecord record = ContextPage.GetInstance().GetExcelRecord();
                //    record.ScreenshotPath = savelocation + fileName;
                //    ContextPage.GetInstance().SetExcelRecord(record);
                //}
                // string fileName = ContextPage.GetInstance().GetExcelRecord().ScenarioName + DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".png";
                //Screenshot sc = new Screenshot(driver.GetScreenshot().AsBase64EncodedString);
                //sc.GetScreenshot().SaveAsFile(fileName);
                //driver.GetScreenshot().SaveAsFile(fileName,ScreenshotImageFormat.Png);
                //File f = sc.SaveAsFile(fileName);
                //File scrFile = ((ITakesScreenshot)driver).(OutputType.FILE);
                //File targetFile = File.Copy(screenshot, fileName);
                //FileUtils.copyFile(srcFile, targetFile);
            }
            catch (Exception exception)
            {
                throw new AssertFailedException(exception.Message);
            }
        }