Exemplo n.º 1
0
        public static string TakeScreenshot(string x)
        {
            var feature  = FeatureContext.Current.FeatureInfo.Title.ToString().Trim().Replace(" ", "");
            var scenario = ScenarioContext.Current.ScenarioInfo.Title.ToString().Trim().Replace(" ", "");

            var tempo            = string.Format("{0:dd-MM-yyyy-hh-mm-ss}", DateTime.Now);
            var dateTime         = GeneralHelpers.GetCurrentDate("dd-MM-yyyy");
            var localArquivoBase = AppDomain.CurrentDomain.BaseDirectory.Replace("bin\\Debug\\", "Evidências");

            localArquivoCompleto = string.Format("{0}\\{1}\\{2}\\{3}", localArquivoBase, feature, scenario, dateTime);

            if (!Directory.Exists(localArquivoCompleto))
            {
                Directory.CreateDirectory(localArquivoCompleto);
            }

            ScreenshotImageFormat extensaoArquivo = ScreenshotImageFormat.Jpeg;

            if (numProposta != null)
            {
                arquivos.AddRange(Directory.GetFiles(localArquivoCompleto));

                var nome = localArquivoCompleto + "\\" + numProposta + ".Jpeg";
                if (arquivos.Contains(nome))
                {
                    fileName = null;
                }
                else
                {
                    fileName = numProposta;
                }
            }
            else
            {
                List <string> arquivos = new List <string>(Directory.GetFiles(localArquivoCompleto));
                var           nome     = localArquivoCompleto + "\\" + "Print" + tempo + ".Jpeg";
                if (arquivos.Contains(nome))
                {
                    fileName = null;
                }
                else
                {
                    fileName = "Print" + tempo;
                }
                arquivos.Clear();
            }

            if (fileName != null)
            {
                nomeArquivoCompleto = string.Format("{0}\\{1}.{2}", localArquivoCompleto, fileName, extensaoArquivo.ToString());

                try
                {
                    ((ITakesScreenshot)DriverFactory.INSTANCE)
                    .GetScreenshot()
                    .SaveAsFile(nomeArquivoCompleto, extensaoArquivo);
                }
                catch (Exception ex)
                {
                    var mensagemErro = string.Format("{0}\r\n{1}\r\n\r\n{2}",
                                                     "Ocorreu um erro ao tirar o print da evidência.",
                                                     ex.Message,
                                                     ex.StackTrace);

                    Console.WriteLine(mensagemErro);
                }
            }

            return(nomeArquivoCompleto);
        }
Exemplo n.º 2
0
        public static void CriaDocumento(string localImagem, string nomeDoc)
        {
            var feature  = FeatureContext.Current.FeatureInfo.Title.ToString().Trim().Replace(" ", "");
            var scenario = ScenarioContext.Current.ScenarioInfo.Title.ToString().Trim().Replace(" ", "");

            var tempo                  = string.Format("{0:dd-MM-yyyy-hh-mm-ss}", DateTime.Now);
            var dateTime               = GeneralHelpers.GetCurrentDate("dd-MM-yyyy");
            var localArquivoBase       = AppDomain.CurrentDomain.BaseDirectory.Replace("bin\\Debug\\", "Evidências");
            var localArquivosDeletados = AppDomain.CurrentDomain.BaseDirectory.Replace("bin\\Debug\\", "Arquivos-Deletados" + "\\" + tempo);

            var localArquivoCompleto = string.Format("{0}\\{1}\\{2}\\{3}", localArquivoBase, feature, scenario, dateTime);

            if (!Directory.Exists(localArquivosDeletados))
            {
                Directory.CreateDirectory(localArquivosDeletados);
            }

            if (nomeDoc == null)
            {
                nomeDoc = tempo;

                List <string> arquivos = new List <string>(Directory.GetFiles(localImagem));
                if (arquivos.Contains(nomeDoc + ".docx"))
                {
                    for (int i = 0; i <= arquivos.Count; i++)
                    {
                        using (FileStream fs = new FileStream(nomeDoc + ".docx", FileMode.Open))
                        {
                            //abre um documento
                            using (var document = DocX.Load(fs))
                            {
                                //Instancia a imagem ao Xceed.Words.NET
                                Xceed.Words.NET.Image img = document.AddImage(arquivos[i]);

                                // Cria um tipo Picture desta imagem
                                Picture pic = img.CreatePicture(400, 600);

                                //Insere e configura a imagem
                                Paragraph p0 = document.InsertParagraph();

                                p0.InsertPicture(pic, 0)
                                .SpacingAfter(30)
                                .Alignment = Alignment.center;

                                //salva o documento


                                nomeArquivo = localArquivoBase + "\\" + nomeDoc + ".docx";
                                document.SaveAs(nomeArquivo);
                            }
                        }
                    }
                }
                else
                {
                    //cria um novo documento
                    using (var document = DocX.Create(nomeDoc + ".docx"))
                    {
                        document.InsertParagraph("Teste: " + nomeDoc
                                                 )
                        .FontSize(15d)
                        .Bold()
                        .SpacingAfter(50d)
                        .Alignment = Alignment.left;

                        for (int i = 0; i < arquivos.Count; i++)
                        {
                            //Instancia a imagem ao Xceed.Words.NET
                            Xceed.Words.NET.Image img = document.AddImage(arquivos[i]);

                            // Cria um tipo Picture desta imagem
                            Picture pic = img.CreatePicture(400, 600);

                            //Insere e configura a imagem
                            Paragraph p0 = document.InsertParagraph();

                            p0.InsertPicture(pic, 0)
                            .SpacingAfter(30)
                            .Alignment = Alignment.center;

                            //salva o documento
                            nomeArquivo = localArquivoCompleto + "\\" + nomeDoc + ".docx";
                            document.SaveAs(nomeArquivo);

                            Directory.Move(arquivos[i], localArquivosDeletados);
                        }
                    }
                }
            }
        }