2008-09-26 64 views

回答

3

WebAii可以自動火狐,包括設置和獲取URL

4

我應該需要做的AutoHotkey的URL的捕捉,比如,我會立即發送Ctrl + L(放焦點在地址欄和亮點內容)和Ctrl + C(將選擇複製到剪貼板)。然後,您只需閱讀剪貼板即可獲取信息。

對於更復雜的任務,我會使用Greasemonkey或iMacros擴展,可能是由類似的鍵盤快捷鍵觸發的。

2

它似乎是非常beta-ey,但有人爲mozrepl構建了.net connector。實際上,mozrepl codebase只是移動到github。但是mozrepl可以讓你向Firefox的XUL環境下發命令。

2

嘗試硒(在谷歌測試引擎 - http://seleniumhq.org/)您可以錄製任務(網頁UI相關的)在Firefox和轉換記錄做成C#源:)

1

可以使用硒的webdriver爲C#。

這是一個跨平臺的API,允許您控制各種使用API​​的Java,C#等瀏覽器。

代碼C#與Selenium WebDriver測試的附件。

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using OpenQA.Selenium.Firefox; 
using OpenQA.Selenium; 
using OpenQA.Selenium.Interactions; 
using OpenQA.Selenium.Interactions.Internal; 
using OpenQA.Selenium.Support.UI; 
using OpenQA.Selenium.IE; 
using NUnit.Framework; 
using System.Text.RegularExpressions; 

namespace sae_test 
{ class Program 
    { private static string baseURL; 
     private static StringBuilder verificationErrors; 

    static void Main(string[] args) 
    { // test with firefox 
     IWebDriver driver = new OpenQA.Selenium.Firefox.FirefoxDriver(); 
     // test with IE 
     //InternetExplorerOptions options = new InternetExplorerOptions(); 
     //options.IntroduceInstabilityByIgnoringProtectedModeSettings = true; 
     //IWebDriver driver = new OpenQA.Selenium.IE.InternetExplorerDriver(options); 
     SetupTest(); 
     driver.Navigate().GoToUrl(baseURL + "Account/Login.aspx"); 
     IWebElement inputTextUser = driver.FindElement(By.Id("MainContent_LoginUser_UserName")); 
     inputTextUser.Clear(); 
     driver.FindElement(By.Id("MainContent_LoginUser_UserName")).Clear(); 
     driver.FindElement(By.Id("MainContent_LoginUser_UserName")).SendKeys("usuario"); 
     driver.FindElement(By.Id("MainContent_LoginUser_Password")).Clear(); 
     driver.FindElement(By.Id("MainContent_LoginUser_Password")).SendKeys("123"); 
     driver.FindElement(By.Id("MainContent_LoginUser_LoginButton")).Click(); 
     driver.Navigate().GoToUrl(baseURL + "finanzas/consulta.aspx"); 
     // view combo element 
     IWebElement comboBoxSistema = driver.FindElement(By.Id("MainContent_rcbSistema_Arrow")); 
     //Then click when menu option is visible 
     comboBoxSistema.Click(); 
     System.Threading.Thread.Sleep(500); 
     // container of elements systems combo 
     IWebElement listaDesplegableComboSistemas = driver.FindElement(By.Id("MainContent_rcbSistema_DropDown")); 
     listaDesplegableComboSistemas.FindElement(By.XPath("//li[text()='BOMBEO MECANICO']")).Click(); 
     System.Threading.Thread.Sleep(500); 
     IWebElement comboBoxEquipo = driver.FindElement(By.Id("MainContent_rcbEquipo_Arrow")); 
     //Then click when menu option is visible 
     comboBoxEquipo.Click(); 
     System.Threading.Thread.Sleep(500); 
     // container of elements equipment combo 
     IWebElement listaDesplegableComboEquipos = driver.FindElement(By.Id("MainContent_rcbEquipo_DropDown")); 

     listaDesplegableComboEquipos.FindElement(By.XPath("//li[text()='MINI-V']")).Click(); 
     System.Threading.Thread.Sleep(500); 

     driver.FindElement(By.Id("MainContent_Button1")).Click();    
     try 
     { Assert.AreEqual("BOMBEO MECANICO_22", driver.FindElement(By.XPath("//*[@id=\"MainContent_RejillaRegistroFinanciero_ctl00_ctl04_LabelSistema\"]")).Text); 
     } 
     catch (AssertionException e) 
     { verificationErrors.Append(e.Message); 
     } 
     // verify coin format $1,234,567.89 usd 
     try 
     { Assert.IsTrue(Regex.IsMatch(driver.FindElement(By.XPath("//*[@id=\"MainContent_RejillaRegistroFinanciero_ctl00_ctl04_labelInversionInicial\"]")).Text, "\\$((,)*[0-9]*[0-9]*[0-9]+)+(\\.[0-9]{2})? usd")); 
     } 
     catch (AssertionException e) 
     { verificationErrors.Append(e.Message); 
     } 
     try 
     { Assert.IsTrue(Regex.IsMatch(driver.FindElement(By.XPath("//*[@id=\"MainContent_RejillaRegistroFinanciero_ctl00_ctl04_labelCostoOpMantto\"]")).Text, "\\$((,)*[0-9]*[0-9]*[0-9]+)+(\\.[0-9]{2})? usd")); 
     } 
     catch (AssertionException e) 
     { verificationErrors.Append(e.Message); 
     } 
     try 
     { Assert.IsTrue(Regex.IsMatch(driver.FindElement(By.XPath("//*[@id=\"MainContent_RejillaRegistroFinanciero_ctl00_ctl04_labelCostoEnergia\"]")).Text, "\\$((,)*[0-9]*[0-9]*[0-9]+)+(\\.[0-9]{2})? usd")); 
     } 
     catch (AssertionException e) 
     { verificationErrors.Append(e.Message); 
     } 
     try 
     { Assert.IsTrue(Regex.IsMatch(driver.FindElement(By.XPath("//*[@id=\"MainContent_RejillaRegistroFinanciero_ctl00_ctl04_labelcostoUnitarioEnergia\"]")).Text, "\\$((,)*[0-9]*[0-9]*[0-9]+)+(\\.[0-9]{2})? usd")); 
     } 
     catch (AssertionException e) 
     { verificationErrors.Append(e.Message); 
     } 
     // verify number format 1,234,567.89 
     try 
     { Assert.IsTrue(Regex.IsMatch(driver.FindElement(By.XPath("//*[@id=\"MainContent_RejillaRegistroFinanciero_ctl00_ctl04_labelConsumo\"]")).Text, "((,)*[0-9]*[0-9]*[0-9]+)+(\\.[0-9]{2})?")); 
     } 
     catch (AssertionException e) 
     { verificationErrors.Append(e.Message); 
     } 
     System.Console.WriteLine("errores: " + verificationErrors); 
     System.Threading.Thread.Sleep(20000); 
     driver.Quit(); 
    } 

    public static void SetupTest() 
    { baseURL = "http://127.0.0.1:8081/ver.rel.1.2/"; 
     verificationErrors = new StringBuilder(); 
    } 

    protected static void mouseOver(IWebDriver driver, IWebElement element) 
    { Actions builder = new Actions(driver); 
     builder.MoveToElement(element); 
     builder.Perform(); 
    } 

    public static void highlightElement(IWebDriver driver, IWebElement element) 
    { for (int i = 0; i < 2; i++) 
     { IJavaScriptExecutor js = (IJavaScriptExecutor)driver; 
      js.ExecuteScript("arguments[0].setAttribute('style', arguments[1]);", 
        element, "color: yellow; border: 2px solid yellow;"); 
      js.ExecuteScript("arguments[0].setAttribute('style', arguments[1]);", 
        element, ""); 
     } 
    } 
} 
}