Advertisement
Raizen

Untitled

May 12th, 2016
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 28.52 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. using System.Threading;
  8. using System.Drawing;
  9. using System.Drawing.Imaging;
  10. using System.Windows.Forms;
  11. using Word_Export;
  12. namespace Lune_Automation_Unite
  13. {
  14.     //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  15.     // ---------- Selenium_Server -------------
  16.     // This is the main class of the framework, it handle steps errors and pushes step
  17.     // execution to the report
  18.     //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  19.     public class Selenium_Server
  20.     {
  21.         private ISelenium selenium;
  22.         private StringBuilder verificationErrors;
  23.         private Database_Manager database;
  24.         private List<string> commandList = new List<string>();
  25.         //private Word_Export.Word_Export word = new Word_Export.Word_Export();
  26.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  27.         // ---------- Configuração de Variáveis -------------
  28.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  29.  
  30.         public int tries;
  31.         public int wait_time;
  32.         public int deepness;
  33.         public string path_save;
  34.         public string scenario_name;
  35.         public string selenium_timeout = "30000";
  36.         public int scenario_sequence;
  37.         public int scenario;
  38.         public int evidence_width = 800;
  39.         public int evidence_height = 600;
  40.         public bool on_error = false;
  41.         public bool highlight = false;
  42.         public bool on_error_continue = false;
  43.         public int scenario_time_begin = 0;
  44.         public int scenario_time_end = 0;
  45.         public int scenario_time_begin_transaction = 0;
  46.         public int scenario_time_end_transaction = 0;
  47.         public string time_of_test = "";
  48.         public int errorNum = 0;
  49.         public string currentError = "";
  50.         public string save_output = "";
  51.         public int on_error_step = 0;
  52.         private List<string> listCommands = new List<string>();
  53.        
  54.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  55.         // ---------- Método de configuração principal -------------
  56.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  57.         public void Config()
  58.         {
  59.            
  60.             //word.cgPageHeight(15);
  61.             System.Diagnostics.Process.Start("C:/Selenium/selenium-server-standalone-2.42.2.jar");
  62.             selenium = new DefaultSelenium("localhost", 4444, "*googlechrome", "http:generic");
  63.             selenium.Start();
  64.             verificationErrors = new StringBuilder();
  65.             selenium.WindowMaximize();
  66.             set_tries(10);
  67.             selenium.SetTimeout("30000");
  68.             scenario_sequence = 1;
  69.             database = new Database_Manager();
  70.             start_timer_transaction();
  71.         }
  72.    
  73.  
  74.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  75.         // ---------- Deepness configuration method -------------
  76.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  77.         public void set_deepness(int d)
  78.         {
  79.             deepness = d;
  80.         }
  81.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  82.         // ---------- Scenario configuration method -------------
  83.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  84.         public void set_scenario(int d)
  85.         {
  86.             listCommands.Clear();
  87.             //word.createDocument();
  88.             scenario_sequence = 1;
  89.             scenario = d;
  90.         }
  91.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  92.         // ---------- Path configuration method -------------
  93.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  94.         public void set_path(string d)
  95.         {
  96.             System.IO.Directory.CreateDirectory(d);
  97.             path_save = d;
  98.         }
  99.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  100.         // ---------- Path configuration method -------------
  101.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  102.         public void set_path(string d, string ev_name)
  103.         {
  104.             System.IO.Directory.CreateDirectory(d);
  105.             path_save = d + ev_name;
  106.         }
  107.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  108.         // ---------- Loop configuration method -------------
  109.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  110.         public void set_wait(int w)
  111.         {
  112.             wait_time = w;
  113.         }
  114.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  115.         // ---------- Wait configuration method -------------
  116.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  117.         public void set_timeout(int t)
  118.         {
  119.             selenium_timeout = t.ToString();
  120.         }
  121.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  122.         // ---------- Loop configuration Method -------------
  123.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  124.         public void set_tries(int t)
  125.         {
  126.             tries = t;
  127.         }
  128.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  129.         // ---------- Highlight configuration Method -------------
  130.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  131.         public void set_highlight(bool h)
  132.         {
  133.             highlight = h;
  134.         }
  135.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  136.         // ---------- OnErrorContinue configuration Method -------------
  137.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  138.         public void set_OnErrorContinue(bool error)
  139.         {
  140.             on_error_continue = error;
  141.         }
  142.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  143.         // ---------- Evidence Resolution configuration Method -------------
  144.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  145.         public void set_EvidenceResolution(int width, int height)
  146.         {
  147.            evidence_height = height;
  148.            evidence_width = width;
  149.         }
  150.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  151.         // ---------- Action Method:Compare -------------
  152.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  153.         public bool Compare(string value1, string value2)
  154.         {
  155.             if (deepness > 0)
  156.                 take_evidence("Compare");
  157.             if (value1 == value2)
  158.                 return true;
  159.             else
  160.                 return false;
  161.  
  162.         }
  163.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  164.         // ---------- Loop configuration method -------------
  165.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  166.         public string GetText(string locator)
  167.         {
  168.             if (on_error)
  169.                 return "";
  170.             try
  171.             {
  172.                 return selenium.GetText(locator);
  173.             }
  174.             catch
  175.             {
  176.                 return "Valor não exibido na tela";
  177.             }
  178.            
  179.         }
  180.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  181.         // ---------- Action Method:Type -------------
  182.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  183.         public void Type(string locator, string value)
  184.         {
  185.             listCommands.Add("Type|" + locator + "|" + value);
  186.             if (on_error)
  187.                 return;
  188.             if (deepness > 1)
  189.                 take_evidence("Type");
  190.             if (waitelement(locator))
  191.             {
  192.                     if (selenium.IsEditable(locator))
  193.                         selenium.Type(locator, value);
  194.                     else
  195.                     {
  196.                         if (value == "")
  197.                             return;
  198.                         Error("editable", locator);
  199.                     }
  200.                     if (deepness > 0)
  201.                         take_evidence("Type");
  202.                     return;
  203.  
  204.             }
  205.             Error("objetone", locator);
  206.             if (deepness > 0)
  207.                 take_evidence("Type");
  208.         }
  209.  
  210.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  211.         // ---------- Action Method:Type -------------
  212.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  213.         public void KeyPress(string locator, string value)
  214.         {
  215.             listCommands.Add("KeyPress|" + locator + "|" + value);
  216.             if (on_error)
  217.                 return;
  218.             if (deepness > 1)
  219.                 take_evidence("KeyPress");
  220.             if (waitelement(locator))
  221.             {
  222.                 if (selenium.IsEditable(locator))
  223.                     selenium.Type(locator, value);
  224.                 else
  225.                 {
  226.                     if (value == "")
  227.                         return;
  228.                     Error("editable", locator);
  229.                 }
  230.                 if (deepness > 0)
  231.                     take_evidence("KeyPress");
  232.                 return;
  233.  
  234.             }
  235.             Error("objetone", locator);
  236.             if (deepness > 0)
  237.                 take_evidence("KeyPress");
  238.         }    
  239.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  240.         // ---------- Action Method:Select -------------
  241.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  242.         public void Select(string locator, string value)
  243.         {
  244.             listCommands.Add("Select|" + locator + "|" + value);
  245.             if (value == "label=")
  246.                 return;
  247.             if (on_error)
  248.                 return;
  249.             if (deepness > 1)
  250.                 take_evidence("Select");
  251.             if (waitelement(locator))
  252.             {
  253.                 selenium.Select(locator, value);
  254.                 if (deepness > 0)
  255.                     take_evidence("Select");
  256.                 return;
  257.  
  258.             }
  259.             Error("objetone", locator);
  260.             if (deepness > 0)
  261.                 take_evidence("Select");
  262.         }
  263.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  264.         // ---------- Action Method:Click -------------
  265.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  266.         public void Click(string locator)
  267.         {
  268.             listCommands.Add("Click|" + locator);
  269.             if (on_error)
  270.              return;
  271.             if (deepness > 1)
  272.                 take_evidence("Click");
  273.             if (waitelement(locator))
  274.             {
  275.                 try
  276.                 {
  277.                     selenium.Click(locator);
  278.                     wait_for_page("Click", locator);
  279.                     return;
  280.                 }
  281.                 catch (Exception)
  282.                 {
  283.                     Error("nopen", locator);
  284.                     if (deepness > 0)
  285.                         take_evidence("Click");
  286.                     return;
  287.                 }
  288.  
  289.             }
  290.             Error("objetone", locator);
  291.             if (deepness > 0)
  292.                 take_evidence("Click");
  293.         }
  294.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  295.         // ---------- Action Method:DoubleClick -------------
  296.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  297.         public void DoubleClick(string locator)
  298.         {
  299.             listCommands.Add("DoubleClick|" + locator);
  300.             if (on_error)
  301.                 return;
  302.             if (deepness > 1)
  303.                 take_evidence("DoubleClick");
  304.             if (waitelement(locator))
  305.             {
  306.                 selenium.DoubleClick(locator);
  307.                 wait_for_page("DoubleClick", locator);
  308.                 return;
  309.             }
  310.             Error("objetone", locator);
  311.             if (deepness > 0)
  312.                 take_evidence("DoubleClick");
  313.         }
  314.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  315.         // ---------- Action Method:DoubleClick -------------
  316.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  317.         public void Focus(string locator)
  318.         {
  319.             listCommands.Add("Focus|" + locator);
  320.             if (on_error)
  321.                 return;
  322.             if (deepness > 1)
  323.                 take_evidence("Focus");
  324.             if (waitelement(locator))
  325.             {
  326.                 selenium.Focus(locator);
  327.                 wait_for_page("Focus", locator);
  328.                 return;
  329.             }
  330.             Error("objetone", locator);
  331.             if (deepness > 0)
  332.                 take_evidence("Focus");
  333.         }
  334.  
  335.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  336.         // ---------- Action Method:Click -------------
  337.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  338.         public void Check(string locator)
  339.         {
  340.             listCommands.Add("Check|" + locator);
  341.             if (on_error)
  342.                 return;
  343.             if (deepness > 1)
  344.                 take_evidence("Check");
  345.             if (waitelement(locator))
  346.             {
  347.                 selenium.Check(locator);
  348.                 if (deepness > 0)
  349.                     take_evidence("Check");
  350.                 return;
  351.             }
  352.             Error("objetone", locator);
  353.             if (deepness > 0)
  354.                 take_evidence("Check");
  355.         }
  356.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  357.         // ---------- Action Method: MouseOver -------------
  358.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  359.         public void MouseOver(string locator)
  360.         {
  361.             listCommands.Add("MouseOver|" + locator);
  362.             if (on_error)
  363.                 return;
  364.             if (deepness > 1)
  365.                 take_evidence("MouseOver");
  366.             if (waitelement(locator))
  367.             {
  368.                 selenium.MouseOver(locator);
  369.                 if (deepness > 0)
  370.                     take_evidence("MouseOver");
  371.                 return;
  372.             }
  373.             Error("objetone", locator);
  374.             if (deepness > 0)
  375.                 take_evidence("MouseOver");
  376.         }
  377.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  378.         // ---------- Action Method:WindowMaximize -------------
  379.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  380.         public void WindowMaximize()
  381.         {
  382.             try
  383.             {
  384.                 selenium.WindowMaximize();
  385.             }
  386.             catch (Exception)
  387.             {
  388.                 Error("windowne", "");
  389.             }
  390.         }
  391.         public void Close()
  392.         {
  393.             selenium.Close();
  394.         }
  395.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  396.         // ---------- Action Method:Stop -------------
  397.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  398.         public void Stop()
  399.         {
  400.             selenium.Stop();
  401.         }
  402.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  403.         // ---------- Action Method:Open -------------
  404.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  405.         public void Open(string url)
  406.         {
  407.             listCommands.Add("Open|" + url);
  408.             if (on_error)
  409.                 return;
  410.             if (deepness > 1)
  411.                 take_evidence("Open");
  412.             try
  413.             {
  414.                 selenium.Open(url);
  415.                 if (deepness > 0)
  416.                     take_evidence("Open");
  417.                 return;
  418.             }
  419.             catch (Exception ex)
  420.             {
  421.                 return;
  422.                 // Ignore errors if unable to close the browser
  423.             }
  424.             Error("open", "");
  425.             if (deepness > 0)
  426.                 take_evidence("Open");
  427.            
  428.         }
  429.  
  430.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  431.         // ---------- Action Method: WaitElement -------------
  432.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  433.         public bool waitelement(string locator)
  434.         {
  435.             for (int n = 0; n < tries; n++)
  436.             {
  437.                 if (selenium.IsElementPresent(locator))
  438.                 {
  439.                     selenium.Focus(locator);
  440.                     if (highlight)
  441.                         selenium.Highlight(locator);
  442.                     return true;
  443.                 }
  444.                 System.Threading.Thread.Sleep(wait_time);
  445.             }
  446.             return false;
  447.         }
  448.  
  449.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  450.         // ---------- Action Method: IsElementPresent -------------
  451.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//    
  452.         public bool IsElementPresent(string locator)
  453.         {
  454.             return selenium.IsElementPresent(locator);
  455.         }
  456.        
  457.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  458.         // ---------- Action Method: Evidenciar -------------
  459.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  460.         public void take_evidence(string action)
  461.         {
  462.             ScreenCapture sc = new ScreenCapture();
  463.             Image img = sc.CaptureScreen();
  464.             ImageHandler image = new ImageHandler();
  465.             Bitmap evidencia = new Bitmap(img);
  466.             string path_image = path_save + "_" + scenario.ToString("00#") + "_" + scenario_sequence.ToString("00#") + "_" + action + "_" + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString("0#") + DateTime.Now.Day.ToString("0#") + ".gif";
  467.             image.Save(evidencia, evidence_width, evidence_height, 60, path_image);
  468.             start_timer_transaction();
  469.             System.Threading.Thread.Sleep(1000);
  470.             scenario_sequence += 1;
  471.         }
  472.         public void CaptureEntirePageScreenshot(string filename, string kwargs)
  473.         {
  474.             selenium.CaptureEntirePageScreenshot(filename, kwargs);
  475.         }
  476.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  477.         // ---------- Action Method:Wait For Page -------------
  478.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  479.         public void WaitForPageToLoad(string timeout)
  480.         {
  481.             selenium.WaitForPageToLoad(timeout);
  482.             take_evidence("PageLoad");
  483.         }
  484.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  485.         // ---------- Action Method:Wait For Page -------------
  486.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  487.         public void wait_for_page()
  488.         {
  489.             try
  490.             {
  491.                 selenium.WaitForPageToLoad("1");
  492.             }
  493.             catch
  494.             {
  495.                 selenium.WaitForPageToLoad(selenium_timeout);
  496.                 return;
  497.             }
  498.         }
  499.  
  500.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  501.         // ---------- Action Method:Wait For Page Overload(Evidence) -------------
  502.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  503.         public void wait_for_page(string evidence, string locator)
  504.         {
  505.             take_evidence(evidence);
  506.         }
  507.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  508.         // ---------- Auxiliar Method:start_timer(Starts the Timer) -------------
  509.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  510.         public void start_timer(){
  511.             scenario_time_begin = (DateTime.Now.Second + DateTime.Now.Minute * 100 + DateTime.Now.Hour * 10000);
  512.         }
  513.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  514.         // ---------- Auxiliar Method:start_timer_transaction(Starts the Timer for steps) -------------
  515.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  516.         public void start_timer_transaction()
  517.         {
  518.             scenario_time_begin_transaction = (DateTime.Now.Second + DateTime.Now.Minute * 100 + DateTime.Now.Hour * 10000);
  519.         }
  520.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  521.         // ---------- Auxiliar Method:end_timer_transaction(Ends the Timer for steps) -------------
  522.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  523.         public string end_timer_transaction()
  524.         {
  525.             int hour = scenario_time_begin_transaction / 10000;
  526.             int minute = (scenario_time_begin_transaction / 100) % 100;
  527.             int second = scenario_time_begin_transaction % 100;
  528.             hour = DateTime.Now.Hour - hour;
  529.             minute = DateTime.Now.Minute - minute;
  530.             if (minute < 0)
  531.             {
  532.                 hour -= 1;
  533.                 minute += 60;
  534.             }
  535.             second = DateTime.Now.Second - second;
  536.             if (second < 0)
  537.             {
  538.                 minute -= 1;
  539.                 second += 60;
  540.             }
  541.             scenario_time_end_transaction -= scenario_time_begin_transaction;
  542.             time_of_test = hour.ToString("0#") + ":" + minute.ToString("0#") + ":" + second.ToString("0#");
  543.             return time_of_test;
  544.         }
  545.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  546.         // ---------- Auxiliar Method:end_timer(Ends the Timer) -------------
  547.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  548.         public string end_timer()
  549.         {
  550.             int hour = scenario_time_begin / 10000;
  551.             int minute = (scenario_time_begin / 100) % 100;
  552.             int second = scenario_time_begin % 100;
  553.             hour = DateTime.Now.Hour - hour;
  554.             minute = DateTime.Now.Minute - minute;
  555.             if (minute < 0){
  556.                 hour -= 1;
  557.                 minute += 60;
  558.             }
  559.             second = DateTime.Now.Second - second;
  560.             if (second < 0)
  561.             {
  562.                 minute -= 1;
  563.                 second += 60;
  564.             }
  565.             scenario_time_end -= scenario_time_begin;
  566.             time_of_test = hour.ToString("0#") + ":" + minute.ToString("0#") + ":" + second.ToString("0#");
  567.             return time_of_test;
  568.         }
  569.  
  570.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  571.         // ---------- Error Method -------------
  572.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  573.         public void Error(string type, string erro)
  574.         {
  575.             on_error = true;
  576.             switch (type)
  577.             {
  578.                 case "objetone":
  579.                     save_output = "Objeto: " + erro + " não encontrado";
  580.                     break;
  581.                 case "timeout":
  582.                     save_output = "Timeout excedido";
  583.                     break;
  584.                 case "mensagemne":
  585.                     save_output = "Mensagem não esperada";
  586.                     break;
  587.                 case "editable":
  588.                     save_output = "Objeto: " + erro + " não pode ser editado";
  589.                     break;
  590.                 case "open":
  591.                     save_output = "Página: " + erro + " não pode ser aberta";
  592.                     break;
  593.                 case "nopen":
  594.                     save_output = "Não foi possível abrir o arquivo";
  595.                     break;
  596.                 case "inactive":
  597.                     save_output = "A tela: " + erro + " não está ativa";
  598.                     break;
  599.                 case "itemne":
  600.                     save_output = "Item: " + erro + " não encontrado na listbox";
  601.                     break;
  602.             }
  603.         }
  604.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  605.         // ---------- Set Error Method -------------
  606.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  607.         public void set_on_error(bool set){
  608.             on_error = set;
  609.             on_error_step = 0;
  610.             if (on_error == false)
  611.                 save_output = "";
  612.             if (on_error_continue)
  613.                 on_error = true;
  614.         }
  615.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  616.         // ---------- send_query - For SQL Only -------------
  617.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  618.         public void send_query(string query)
  619.         {
  620.             database.send_query(query);
  621.         }
  622.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  623.         // ---------- Invokes Me Methods -------------
  624.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  625.         public void invokeMethod(string name, object[] args)
  626.         {
  627.             this.GetType().GetMethod(name).Invoke(this, args);
  628.         }
  629.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  630.         // ---------- Gets error step -------------
  631.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  632.             public int GetOnErrorStep()
  633.             {
  634.                 return on_error_step;
  635.             }
  636.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  637.         // ---------- Gets the list of steps -------------
  638.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  639.         public List<string> GetList(){
  640.             return listCommands;
  641.         }
  642.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  643.         // ---------- Adds a step to the list -------------
  644.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  645.         public void AddOnList(string type, string locator)
  646.         {
  647.             listCommands.Add(type + "|" + locator);
  648.         }
  649.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  650.         // ---------- Adds a step to the list with its value -------------
  651.         //=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=//
  652.         public void AddOnList(string type, string locator, string value)
  653.         {
  654.             listCommands.Add(type + "|" + locator + "|" + value);
  655.         }
  656.     }
  657.  
  658. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement