【问题标题】:How to test RichFaces combobox with Selenium Webdriver?如何使用 Selenium Webdriver 测试 RichFaces 组合框?
【发布时间】:2011-11-15 21:15:53
【问题描述】:

我们有一个基于 RichFaces 3.3.3 的应用程序。我们使用 Selenium IDE 创建了运行良好的自动化测试。由于 RichFaces 组合框不是真正的 html 组合框,而是带有一堆 javascript 的输入字段,因此在 Selenium 中,我们需要使用以下技巧选择一个值:

type      field_id "field value"
typeKeys  field_id "field value"
fireEvent field_id "blur"

为了将测试集成到我们的持续集成系统中,我们将测试转换为使用 WebDriver (Selenium 2.5.0) 作为后端的 jUnit 测试。不幸的是,组合框技巧停止工作。

所有type和typeKeys命令翻译如下:

// ERROR: Caught exception [ERROR: Unsupported command [fireEvent]]
driver.findElement(By.id("patientCreateDataForm:patientBirthDateInputDate")).clear(); 
driver.findElement(By.id("patientCreateDataForm:patientBirthDateInputDate")).sendKeys("16.06.1910");

有没有人有任何有效的解决方案来测试 RichFaces 组合框元素?

提前致谢!

【问题讨论】:

    标签: selenium richfaces webdriver


    【解决方案1】:

    解决方法如下:

    1. 点击 RichFaces 组合框
    2. 选择项目(男性或女性)并在 FirePath 帮助下复制路径
    3. 此后在 jUnit 测试中使用 Actions 方法。在下面的例子中,button参数是一个combobox button id,element参数是selected items xpath:

       private void comboboxSolution(String element, String button) {
          WebElement btn = driver.findElement(By.id(button));
          btn.click();
          WebElement myElement = driver.findElement(By.xpath(element));
          Actions builder = new Actions(driver);
          builder.moveToElement(myElement).click().perform();
      
      }
      

    【讨论】:

      【解决方案2】:

      试试这样的:

      typeKeys field_id "field value"
      waitForVisible (look with firebug at the id of the div that becomes visible after typing)
      click (look with firebug at the id of the entry you want to select)
      waitForNotVisible the_id_of_the previous_div
      

      我有这个解决方案适用于丰富的:建议框组件,它应该很容易适应组合框。

      【讨论】:

      • 这似乎是一种硒解决方案。我们对 selenium 没有问题,但是如果我们将测试用例导出到 WebDriver jUnit 脚本,它们不会从组合框中选择元素。我已经用生成的 webdriver 代码更新了问题。
      猜你喜欢
      • 2015-01-22
      • 1970-01-01
      • 1970-01-01
      • 2013-02-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多