WebDriver自動化測試載入器(1)---C#環境搭建

來源:互聯網
上載者:User

標籤:輸入   自動   關閉   static   pre   bin   code   操作   console   

  Webdriver是一個前端自動化測試載入器,可以類比使用者點選連結,填寫表單,點擊按鈕等操作,下面介紹其使用

一.下載WebdriverC#類庫以及對應瀏覽器驅動

http://www.seleniumhq.org/download/

也可以通過Nuget去下載,不過國內防火牆的問題,一般下載不來,所以還是使用上述方法比較穩

這裡只示範Google,其他瀏覽器操作類次

二.在項目中引用下載的DLL,chromedriver.exe可以把其放在項目根路徑,然後屬性裡設定始終複製即可

三.做一個Demo,讓瀏覽器類比開啟百度網頁,並且輸入asp.net,最後點擊搜尋按鈕

 1 using OpenQA.Selenium; 2 using OpenQA.Selenium.Chrome; 3 using System; 4  5 namespace Demo 6 { 7     class Program 8     { 9         static void Main(string[] args)10         {11             ChromeOptions options = new ChromeOptions()12             {13                 //Chrome瀏覽器路徑14                 BinaryLocation = @"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"15             };16             //ChromeDriver:Google瀏覽器,如果使用其他瀏覽器比如IE,需要使用其對應類17             //chromeDriverDirectory:不指定預設是當前運行路徑檔案夾裡尋找18             var driver = new ChromeDriver(@"D:\Program Files\案頭\WebDriver\Demo\bin\Debug", options);19             driver.Navigate().GoToUrl("https://www.baidu.com");20             driver.FindElement(By.Id("kw")).SendKeys("asp.net");21             driver.FindElement(By.Id("su")).Submit();22             Console.ReadLine();23             //關閉24             driver.Quit();25         }26     }27 }

WebDriver自動化測試載入器(1)---C#環境搭建

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.