C# selenium環境配置 - 小唐師叔 - 博客園


已剪輯自: https://www.cnblogs.com/tanghuang/p/6829248.html

1.下載C#selenium

   

https://seleniumhq.github.io/selenium/docs/api/dotnet/index.html

  selenium官網:  http://www.seleniumhq.org/download/

   

下載后解壓:

   

   

打開net35后,將里面的dll文件添加到ranorex中;

2.瀏覽器環境配置

將需要用到的瀏覽器chrome,firfox,等exe所在的文件

夾添加到系統變量path中去,必要的時候需要重啟電腦;

這一步很重要,否則運行下面的腳本打開不了瀏覽器,需要在腳本中添加瀏覽器地址

   

3.本地運行腳本;

using Selenium;

using OpenQA.Selenium;

using OpenQA.Selenium.Chrome;

public void Test001()

        {

              IWebDriver selenium = new ChromeDriver();

              selenium.Navigate().GoToUrl("http://www.baidu.com/");

              //selenium.FindElement();

        }

   

4.在遠程機執行remoting

遠程機環境配置:

  • 需要將瀏覽器添加到系統變量path
  • 需要下載selenium-server-standalond.jar
  • 然后再cmd或者windows PowerShell中進入到selenium-server-standalond.jar所在的文件夾,執行命令,打開服務,命令如下
  • PS C:\Users\cpr018\Desktop\selenium> java -jar selenium-server-standalone.jar
  • 在客戶端運行腳本,即可在遠程執行測試腳本
  • remoting其他詳細設置請看 http://www.cnblogs.com/tanghuang/p/6829258.html

   

客戶端腳本:

   

using Selenium;

using OpenQA.Selenium;

using OpenQA.Selenium.Chrome;

using OpenQA.Selenium.Remote;

public static void test001()

        {

              //uri中的ip為遠程機的ip,開啟服務默認端口為4444

              var driver = new RemoteWebDriver(new Uri("http://192.168.226.131:4444/wd/hub"), DesiredCapabilities.Chrome());

              driver.Navigate().GoToUrl("http://www.baidu.com/");

   

   

         }

   

   

   


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM