Advertisement
Raizen

Untitled

May 12th, 2016
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.26 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using NUnit.Framework;
  6. using Selenium;
  7.  
  8. namespace Lune_Automation_Unite
  9. {
  10.     //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  11.     // ---------- Selenium_MasterTCC -------------
  12.     // This is the main class of the execution, it handles how the execution is made and calls
  13.     // the Selenium_Server Class
  14.     //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  15.     public class Selenium_MasterTCC
  16.     {
  17.         //private ISelenium selenium_base;
  18.         private Selenium_Server selenium;
  19.         private StringBuilder verificationErrors;
  20.         private Lune_Basic_Module master;
  21.         public int starting_row = 0;
  22.         public int scene = 1;
  23.  
  24.         // Set Test Variables
  25.         public string name_of_test;
  26.  
  27.  
  28.  
  29.         public void SetupTest()
  30.         {
  31.             //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  32.             // ---------- CONFIGURAÇÂO INICIAL DA APLICAÇÃO -------------
  33.             //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  34.  
  35.             selenium = new Selenium_Server(); //Inicialização da classe
  36.             master = new Lune_Basic_Module();
  37.             selenium.Config(); //Configuração necessária
  38.             master.load_xml("C:/Selenium/configuracao.xml"); //Carrega o arquivo xml
  39.             KillProcess("Excel");
  40.             master.set_database(master.get_xml_tag("configuracao", "db"), master.get_xml_tag("configuracao", "caminhoDB"), "Master"); // Configuração de database
  41.             selenium.set_tries(int.Parse(master.get_xml_tag("configuracao", "falha"))); //Configuração de tentativas até falhar o teste
  42.             selenium.set_wait(1); //Configuração de tempo a cada nova tentativa
  43.             selenium.set_path(master.get_xml_tag("configuracao", "evidencia")); //Configuração de local e nome das evidências
  44.             selenium.set_deepness(int.Parse(master.get_xml_tag("configuracao", "deepness"))); //Configuração de profundidade das evidências
  45.             selenium.set_timeout(int.Parse(master.get_xml_tag("configuracao", "timeout"))); //Configuração de tempo limite para timeout
  46.             selenium.set_highlight(bool.Parse(master.get_xml_tag("configuracao", "highlight"))); //Configuração de highlight ativo ou inativo
  47.             string[] header = { "Cenário", "Número dos Passos", "Nome dos Passos", "Resultado Esperado", "Resultado Obtido", "Status" };
  48.             master.writeTestCasesHeader("CasosDeTeste", header);
  49.             starting_row = 2; //Configuração de linha inicial
  50.             master.change_tables("Master");
  51.             //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  52.             // Aqui fica o looping principal do framework, ele manuseia os cenários de teste
  53.             // de acordo com o banco de dados, caso o "Run" esteja como "Yes",
  54.             // O cenário será aberto e executado.
  55.             //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  56.             while (master.has_tests(starting_row))
  57.             {
  58.                 if (master.get_data(starting_row, 2) == "Yes")
  59.                 {
  60.  
  61.                     scene = 1; // Configura o caso de teste no estado inicial
  62.                     selenium.set_on_error(false); // Reseta a condição de erro para false
  63.                     selenium.set_scenario(scene); // Exporta o scene(que é 1) para a classe Selenium_Server
  64.                     name_of_test = master.get_data(starting_row, 1); //adquire o nome do cenário de teste
  65.                     selenium.set_path("C://Selenium//Evidencia_Teste//", name_of_test); //Configuração de local e nome das evidências
  66.                     master.change_tables(name_of_test); //Abre o a aba/banco de dados do cenário
  67.                     selenium.start_timer(); //Inicia o contador
  68.                     selenium_tests(); //Executa o cenário de teste
  69.                     //master.writeTestCases("CasosDeTeste", name_of_test, selenium.GetList(), starting_row, selenium.GetOnErrorStep());
  70.                     selenium.end_timer(); //Finaliza o contador
  71.                     starting_row += 1; //Vai para a próxima linha
  72.                 }
  73.                 master.change_tables("Master"); // Volta para a aba principal de controle dos cenários
  74.             }
  75.             TeardownTest(); // Finalização dos testes
  76.  
  77.         }
  78.  
  79.  
  80.         public void TeardownTest()
  81.         {
  82.             master.close_database();
  83.             try
  84.             {
  85.                 selenium.Stop();
  86.             }
  87.             catch (Exception)
  88.             {
  89.                 // Ignore errors if unable to close the browser
  90.             }
  91.             //Assert.AreEqual("", verificationErrors.ToString());
  92.         }
  93.  
  94.         // Aqui é feito a chamda para o método com o mesmo nome do
  95.         // cenário de teste.
  96.         public void selenium_tests()
  97.         {
  98.  
  99.             this.GetType().GetMethod(name_of_test).Invoke(this, null);
  100.         }
  101.         // Você pode adicionar métodos/funções auxiliares para a
  102.         // automatização
  103.         public void fazer_login(string login, string password)
  104.         {
  105.             //selenium....
  106.         }
  107.         // Aqui é o método principal do cenário, ele deve ter o mesmo nome que
  108.         // estará no banco de dados
  109.         public void Teste_Topicos()
  110.         {
  111.             int row = 2; //Linha inicial de onde iniciará os testes
  112.             while (master.has_tests(row)){ // Verificação se há algo escrito naquela linha
  113.                 selenium.set_scenario(scene);
  114.                 if (master.get_data(row, 2) == "No") // Caso o valor seja "No"
  115.                 {
  116.                     row += 1; //Pula uma linha
  117.                     continue; //Vai para a próxima iteração
  118.                 }
  119.                 //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  120.                 // ---------- Coloque aqui as variáveis utilizadas!!! -------------
  121.                 // Para chamar um dado da tabela basta usar o comando, master.get_data(row, col)
  122.                 // row é a linha, col a coluna, você também pode pegar dados de outras tabelas
  123.                 // Utilizando a função master.change_tables(name_of_test), mas lembre-se
  124.                 // de voltar para a tabela atual.
  125.                 //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  126.                 string text = "";
  127.                 string output = "";
  128.                 string caseName = master.get_data(row, 1);
  129.                 string expected_result = master.get_data(row, 5);
  130.                 string testResult = "";
  131.                 //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  132.                 // ---------- INSERIR O CÓDIGO AQUI!!! -------------
  133.                 // O código segue exatamente o mesmo padrão do Selenium RC, aonde
  134.                 // selenium é o objeto principal, e nele contém as funções para serem
  135.                 // utilizadas, dentro de cada função já tem um print, não é necessário
  136.                 // colocar comandos de print.
  137.                 //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  138.                 // Exemplo de um código
  139.                 //selenium.Open(caseName);
  140.                 //selenium.Type("//input[@type='password']", Senha);
  141.                 master.CheckValue(row, testResult);
  142.                 master.save_database();
  143.  
  144.  
  145.  
  146.                 // Example #2: Write one string to a text file.
  147.                 // WriteAllText creates a file, writes the specified string to the file,
  148.                 // and then closes the file.    You do NOT need to call Flush() or Close().
  149.                
  150.  
  151.             }
  152.         }
  153.  
  154.  
  155.  
  156.         public void KillProcess(string element)
  157.         {
  158.             System.Diagnostics.Process[] Processos = System.Diagnostics.Process.GetProcessesByName(element);
  159.             foreach (System.Diagnostics.Process x in Processos)
  160.             {
  161.                 x.Kill();
  162.             }
  163.         }
  164.     }
  165. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement