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:Userscpr018Desktopselenium> 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/");

   

   

         }

   

   

   

原文地址:https://www.cnblogs.com/Areas/p/11343843.html