Java构造函数参数Selenium与WebDriverBackedElenium

Java构造函数参数Selenium与WebDriverBackedElenium,java,selenium,Java,Selenium,我正在使用一个较旧版本的自动化脚本,该脚本登录到一个页面并运行测试 我们希望将经典的selenium构造函数更改为WebDriverBackedSelenium构造函数,以便进行更复杂的测试 我们最初的构造函数调用是: selenium = new DefaultSelenium("localhost", 4444, "*firefox", "https://asdffdsa.com/"); 如何使用相同的参数设置WebDriverBackedElenium构造函数?API显示我们需要将构造函

我正在使用一个较旧版本的自动化脚本,该脚本登录到一个页面并运行测试

我们希望将经典的selenium构造函数更改为WebDriverBackedSelenium构造函数,以便进行更复杂的测试

我们最初的构造函数调用是:

selenium = new DefaultSelenium("localhost", 4444, "*firefox", "https://asdffdsa.com/");
如何使用相同的参数设置WebDriverBackedElenium构造函数?API显示我们需要将构造函数设置为:

seWebDriver = new WebDriverBackedSelenium(driver, "https://asdffdsa.com");
似乎没有任何关于selenium服务器运行的位置、端口和浏览器的指示

当前正在使用以下代码:

driver = new FirefoxDriver();
    seWebDriver = new WebDriverBackedSelenium(driver, "https://www.asdfdfdfsfs.com");

    seWebDriver.open("/");
刚才注意到我得到了以下错误:

原因:org.openqa.selenium.firefox.NotConnectedException:45000毫秒后无法连接到端口7055上的主机127.0.0.1。firefox控制台输出: *LOG addons.manager:应用程序已升级 LOG addons.xpi:启动 LOG addons.xpi:跳过不可用的安装位置应用程序系统共享 LOG addons.xpi:忽略名称不是有效加载项ID的文件条目:/var/folders/pf/hvzyf38x59vfbgf8zpvw5v800000gn/T/anonymous250156010712840923webdriver配置文件/扩展名/webdriver暂存 LOG addons.xpi:checkForChanges LOG addons.xpi-utils:打开数据库 LOG addons.xpi-utils:创建数据库架构 LOG addons.xpi:新加载项fxdriver@googlecode.com安装在应用程序配置文件中 块列表::\u loadBlocklistFromFile:块列表已禁用 LOG addons.xpi:app global中安装的新附加组件{972ce4c6-7e08-4474-a285-3208198ce6fd} LOG addons.xpi:使用对已安装加载项的更改更新数据库 LOG addons.xpi-utils:更新加载项状态 LOG addons.xpi-utils:编写加载项列表 LOG addons.manager:关闭 LOG addons.xpi:关闭 LOG addons.xpi-utils:关闭 LOG addons.xpi-utils:数据库已关闭 LOG addons.xpi:启动 LOG addons.xpi:跳过不可用的安装位置应用程序系统共享 LOG addons.xpi:忽略名称不是有效加载项ID的文件条目:/var/folders/pf/hvzyf38x59vfbgf8zpvw5v800000gn/T/anonymous250156010712840923webdriver配置文件/扩展名/webdriver暂存 LOG addons.xpi:checkForChanges
*
LOG addons.xpi:未发现任何更改

下面是一个使用Webdriver支持的selenium的示例

在使用webdriverbacked Selenium时,无需提及端口号

在下面的程序中,对象
Selenium
用于利用Selenium RC(旧的自动化脚本构造函数)的属性

对象
driver
用于利用Webdriver(Selenium2.0)的功能


在上面的WebDriverBackedElenium示例中,您传入的第一个参数是“driver”。看看我如何在上面设置我的WebDriver:它指定了中心位置。

我认为在这个自动化中我们需要WebDriver的功能,但是当我设置它并将其作为单元测试运行时,它试图加载localhost而不是我在构造函数中提供的站点。您使用的是driver.get(url)还是selenium.open(url)?如果你能分享代码的话会很有帮助的。selenium.open(url)代码太乱了,我想把它整理一下,然后把相关的部分贴出来。伙计,看看我下面的答案。不要使用driver=new FirefoxDriver(),而是使用driver=new RemoteWebDriver(hub,capabilities),其中hub类似于。我不明白我已经提供了答案,你为什么还要编辑这个问题。另外,selenium文档也很好,所有这些都在这里得到了回答。上面列出的错误是由于版本控制不可映射性或其他原因造成的。有关这方面的更多信息,请参阅。
public class BackedWebdriver {

    public static WebDriver driver;
    public static String baseUrl;
    public static Selenium selenium;

    public static void main(String[] args) {
        driver = new FirefoxDriver();    //Here we are mentioning that we will use Firefox browser
        baseUrl = "http://www.google.co.in/";
        driver.get(baseUrl);
        selenium = new WebDriverBackedSelenium(driver, baseUrl);
        selenium.windowMaximize();
        driver.findElement(By.id("gbqfq")).clear();
        driver.findElement(By.id("gbqfq")).sendKeys("selenium");
        selenium.click("g");
        driver.findElement(By.id("gbqfb")).click();


    }
DesiredCapabilities ffLinux = DesiredCapabilities.firefox();
ffLinux.setBrowserName("firefox");
ffLinux.setPlatform(Platform.LINUX);
String hubLocation = http://yourmachine.com:4444/wd/hub;
WebDriver driver = new RemoteWebDriver(hubLocation, ffLinux);
driver.get(yourWebApplicationURLThatsBeingTested);