【问题标题】:Java Constructor Parameters Selenium Versus WebDriverBackedSeleniumJava 构造函数参数 Selenium 与 WebDriverBackedSelenium
【发布时间】:2013-02-21 11:40:13
【问题描述】:

我正在使用旧版本的自动化脚本登录页面并运行测试。

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

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

selenium = new DefaultSelenium("localhost", 4444, "*firefox", "https://asdffdsa.com/");

如何设置具有相同参数的 WebDriverBackedSelenium 构造函数? 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。火狐控制台输出: * LOG addons.manager: 应用程序已升级 LOG addons.xpi:启动 LOG addons.xpi:跳过不可用的安装位置 app-system-share LOG addons.xpi:忽略名称不是有效插件 ID 的文件条目:/var/folders/pf/hvzyf38x59vfbgf8zpvw5v800000gn/T/anonymous2501560210712840923webdriver-profile/extensions/webdriver-staging LOG addons.xpi: checkForChanges LOG addons.xpi-utils: 打开数据库 LOG addons.xpi-utils:创建数据库模式 LOG addons.xpi:安装在 app-profile 中的新插件 fxdriver@googlecode.com Blocklist::_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:跳过不可用的安装位置 app-system-share LOG addons.xpi:忽略名称不是有效插件 ID 的文件条目:/var/folders/pf/hvzyf38x59vfbgf8zpvw5v800000gn/T/anonymous2501560210712840923webdriver-profile/extensions/webdriver-staging LOG addons.xpi: checkForChanges * LOG addons.xpi:未发现任何更改

【问题讨论】:

  • 老兄,看看我下面的回答。而不是使用 driver = new FirefoxDriver() 使用 driver = new RemoteWebDriver(hub, capabilities) 其中集线器类似于localhost:4444/wd/hub。我不明白为什么当我已经提供答案时你会编辑问题。此外,selenium 文档非常好,所有这些东西都在那里得到了解答。
  • 我上面列出的错误是由于版本控制不兼容或其他原因。请参阅stackoverflow.com/questions/10013898/… 了解更多信息。

标签: java selenium


【解决方案1】:

这是一个使用 Webdriver 支持的 selenium 的示例。

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

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

对象driver是为了利用Webdriver(Selenium2.0)的特性。

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();


    }

【讨论】:

  • 我认为我们在这个自动化中需要 Webdriver 的功能,但是当我设置它并将其作为 UnitTest 运行时,它试图加载 localhost 而不是我在构造函数中提供的站点。
  • 您使用的是 driver.get(url) 还是 selenium.open(url) ?如果你能分享代码会很有帮助。
  • selenium.open(url) 代码是一团糟,我想把它清理一下,然后把相关部分贴出来。
【解决方案2】:
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);

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

【讨论】:

    猜你喜欢
    • 2021-09-23
    • 2013-01-31
    • 1970-01-01
    • 2020-12-15
    • 1970-01-01
    • 1970-01-01
    • 2021-03-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多