问题:GWT 2.0 的硒测试

如何使 selenium click() 与手动鼠标单击一样工作?

我最近将 GWT 从 1.7.1 升级到了 2.0。一些硒测试(SeleniumRC v1.0.1,IE7)现在失败了。 Selenium.click() 方法似乎没有选择 GWT TreeItem。手动单击将使 TreeItem 变为蓝色(即,看起来已选中并在 DOM 中具有“gwt-TreeItem-selected”类属性),但 selenium 测试没有。

我确信硒实际上是在找到正确的元素,只是没有点击它。如果您更改 click 方法中的字符串参数,您可以检查 selenium 在找不到元素时是否抛出异常。

下面的示例代码使用 GWT Showcase 网站。它试图点击单词“Beethoven”。如果你用鼠标点击那个词,你会看到 TreeItem 变成蓝色。但是,当您运行硒测试时,它不会。

package test;

import org.junit.Before;
import org.junit.Test;

import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.Selenium;

public class TestTreeClick {
    static Selenium selenium = null;

    @Before
    public void setUp() throws Exception {
        if (selenium == null) {
            selenium = new DefaultSelenium("localhost", 4444, "*iexplore",
                    "http://gwt.google.com/samples/Showcase/Showcase.html#CwTree");
            selenium.start();
        }
    }

    @Test
    public void testingClicking() {
        selenium.open("http://gwt.google.com/samples/Showcase/Showcase.html#CwTree");
        selenium.click("gwt-debug-cwTree-staticTree-root-child0-content");
    }
}

我尝试了一些其他方法(Selenium.clickAt()、Selenium.fireEvent()、Selenium.mouseOver()/Down()/Up()) - 但没有一个重现手动行为。

解答

不幸的是,看看这个案例,我无法使用 Selenium 复制点击。我看到很多人抱怨他们不能将 Selenium 与 GWT 一起使用,而其中一个更著名的团队也有这个问题。 Google Wave 开发团队已经开始使用 WebDriver 来测试他们的代码。

现在好消息是,目前有一个合并 Selenium 和 WebDriver 的项目,因为它们各有优缺点,而且其中一些位于不同的领域,因此最终产品将是惊人的。

我相信他们可能在Google 代码处拥有 WebDriverBackedSelenium 的工作版本,因此您需要做的就是更新 Selenium 的实例化,它应该开始使用 WebDriver 代码来运行您的测试。

Logo

Python社区为您提供最前沿的新闻资讯和知识内容

更多推荐