2008-09-26 10 views
10

एक सी # एप्लिकेशन से फ़ायरफ़ॉक्स में यूआरएल को कैप्चर करने के सबसे सरल कार्य से शुरू करें। यह user32.dll का उपयोग करके प्रकट होता है Windows API फ़ंक्शन IE के भीतर यूआरएल को कैप्चर करने के लिए दृष्टिकोण के रूप में काम नहीं करेगा।आप फ़ायरफ़ॉक्स को सी # एप्लिकेशन से कैसे स्वचालित कर सकते हैं?

उत्तर

3

WebAii फ़ायर्फ़ॉक्स स्वचालित कर सकते हैं स्थापित करने सहित और यूआरएल

4

मैं AutoHotkey साथ URL की एक पर कब्जा करने की जरूरत है चाहिए पुन: प्राप्त करने, उदाहरण के लिए, मैं भेजना होगा Ctrl + L (पता बार और उजागर सामग्री में ध्यान केंद्रित कर दिया) और Ctrl + C (क्लिपबोर्ड पर प्रतिलिपि चयन)। फिर आप जानकारी प्राप्त करने के लिए बस क्लिपबोर्ड पढ़ते हैं।

अधिक जटिल कार्यों के लिए, मैं Greasemonkey या iMacros एक्सटेंशन का उपयोग करता हूं, शायद इसी तरह के कीबोर्ड शॉर्टकट द्वारा ट्रिगर किया जाता है।

1

एक माइक्रोसॉफ्ट उपकरण मैं में भाग: http://msdn.microsoft.com/en-us/library/ms771286.aspx

मैं अपने पीसी पर यूआई जासूस नहीं है: .NET 3,5 http://msdn.microsoft.com/en-us/library/aa348551.aspx

यहाँ के हिस्से के रूप

यूआई स्वचालन, एक उदाहरण है फ़ायरफ़ॉक्स से पूछताछ करने के लिए, इसलिए मुझे नहीं पता कि यह आपकी user32.dll समस्या से मदद करेगा या नहीं।

2

यह बहुत बीटा-आई प्रतीत होता है, लेकिन किसी ने mozrepl के लिए .net connector बनाया। दरअसल, मोज़ेप कोड कोड बस github पर ले जाया गया। लेकिन mozrepl आपको फ़ायरफ़ॉक्स के XUL वातावरण में आदेश जारी करने देता है।

4

WatiN फ़ायरफ़ॉक्स के लिए समर्थन है।

2

सेलेनियम (Google परीक्षण इंजन - http://seleniumhq.org/) की कोशिश करो आप कार्य रिकॉर्ड कर सकते हैं (वे वेबपृष्ठ यूआई संबंधित) एक सी # स्रोत :)

1

आप सी # के लिए सेलेनियम 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, ""); 
     } 
    } 
} 
} 
संबंधित मुद्दे

 संबंधित मुद्दे