C # selenium environment configuration - Xiao Tang Shishu - blog Park

Clips have been self : https://www.cnblogs.com/tanghuang/p/6829248.html

1. Download the C # selenium

   

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

  selenium official website: http://www.seleniumhq.org/download/  

   

Download after decompression:

   

   

Open net35, which adds to the ranorex the dll file;

2. The browser environment configuration

Will need to use the browser chrome, firfox, exe files are located

Clip added to the system variable path to go, when necessary, the need to restart the computer;

This step is very important, otherwise run the following script can not open a browser, you need to add the browser address in the script

   

3. Local run the script;

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. remote execution machine remoting

Remote machine environment configuration:

  • 需要将浏览器添加到系统变量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/");

   

   

         }

   

   

   

Guess you like

Origin www.cnblogs.com/Areas/p/11343843.html