OperaProfile对象和Selenium RC(C#) [英] OperaProfile object and Selenium RC (C#)

查看:116
本文介绍了OperaProfile对象和Selenium RC(C#)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试将selenium-server-standalone-2.33.0.jar与Opera配合使用,并且需要更改一些配置文件首选项. 可以在C#项目中创建OperaProfile对象,并像这样使用它:

I'm try to use selenium-server-standalone-2.33.0.jar with opera and need to change some profile preferences. It possible to create OperaProfile object in C# project and using it like this:

OperaProfile profile = new OperaProfile(); // Error: Type or namespace 'OperaProfile' could not be found
profile.preferences().set("User Prefs", "Ignore Unrequested Popups", false);
DesiredCapabilities capabilities = DesiredCapabilities.Opera();
capabilities.SetCapability("opera.profile", profile);
IWebDriver driver = new RemoteWebDriver(new Uri("http://host:4444/wd/hub"), capabilities);

在这种情况下,我收到错误消息

In this case I got error message

找不到类型或名称空间"OperaProfile"

推荐答案

假设您在Windows上:

Assuming you are on Windows:

Operadriver用Java编写,而不是直接用C#支持,因为它不是由Selenium项目团队而是由Opera维护.

The Operadriver is written in Java and not suported directly in C#, as it is mainatined not by the Selenium project team but by Opera.

要使用它,必须先运行独立的Selenium Web服务器(从Windows的控制台),然后再开始测试. 在此处获取

To use it, you have to run the standalone Selenium webserver (from console on windows) before starting the test. get it here

您需要将OPERA_PATH设置为指向您的Opera.exe文件.使用以下命令启动服务器:

you need to set the OPERA_PATH to point to your opera.exe file. Start the server with the command:

java -jar selenium-server-standalone-2.33.0.jar 

我为这两个任务使用一只小蝙蝠:

i use a small bat for these two tasks:

SET OPERA_PATH="C:\Progra~2\Opera\opera.exe"
cd C:\pathToSeleniumJarFile
C:\Progra~2\Java\jre7\bin\java.exe -jar selenium-server-standalone-2.33.0.jar

C#: 使用C#代码中的remotewebdriver对象进行测试以连接到该对象.

C#: testing with remotewebdriver object in your C# code to connect to it.

        switch (WebBrowser)
        {
            case Browser.Chrome:
                // chromedriver.exe has to be in the debug folder
                ChromeOptions chrome = new ChromeOptions();
                chrome.AddArguments("--ignore-certificate-errors");
                webDriver = new ChromeDriver(chrome);
                break;

            ...

            case Browser.Opera:
                //note: set OPERA_PATH environment variable (in cmd or global)
                DesiredCapabilities opera = DesiredCapabilities.Opera();
                opera.SetCapability("opera.profile", @"C:\OperaProfile");
                webDriver = new RemoteWebDriver(opera);
                break;

            default:
                throw new NotImplementedException();

如果您要操作Opera客户端的配置文件(例如,接受不受信任的证书等),则需要设置

if you want to manipulate the profile of the opera client (e.g. to accept untrusted certificates etc) you need to set

opera.SetCapability("opera.profile", @"C:\OperaProfile");

将现有配置文件复制到您选择的位置,这里C:\ OperaProfile.

Copy an existing Profile to a location of your choice, here C:\OperaProfile.

==>避免在所有路径中出现空格< ==

==> Avoid spaces in all the pathes <==

这篇关于OperaProfile对象和Selenium RC(C#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆