GWT 2.0 的硒测试 [英] Selenium Testing of GWT 2.0

查看:14
本文介绍了GWT 2.0 的硒测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How can I make a selenium click() work the same as a manual mouse click?

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

I have recently upgraded GWT from 1.7.1 to 2.0. Some selenium tests (SeleniumRC v1.0.1, IE7) are now failing. It seems that the Selenium.click() method is not selecting a GWT TreeItem. A manual click will make the TreeItem go blue (ie. look selected and have "gwt-TreeItem-selected" class attribute in the DOM), but the selenium test doesn't.

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

I'm convinced that selenium is actually finding the right element, just not clicking on it. If you change the string parameter in the click method you can check that selenium throws an exception when the element isn't found.

下面的示例代码使用 GWT Showcase 网站.它试图点击贝多芬"这个词.如果您用鼠标单击该词,您将看到 TreeItem 变为蓝色.但是,当您运行 selenium 测试时,它不会.

The sample code below uses the GWT Showcase website. It tries to click on the word "Beethoven". If you click on that word with your mouse, you'll see the TreeItem go blue. However when you run the selenium test, it won't.

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())——但没有一个能重现手动行为.

I have tried some other methods (Selenium.clickAt(), Selenium.fireEvent(), Selenium.mouseOver()/Down()/Up() ) - but none reproduce the manual behaviour.

推荐答案

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

Unfortunately having a look at this case I have not been able to replicate clicking with Selenium. I have seen a number of people complaining that they can't use Selenium with GWT and one of the more famous teams have that issue. The Google Wave development team have started using WebDriver to test their code.

现在的好消息是,目前有一个项目将 Selenium 和 WebDriver 合并,因为它们各有优缺点,而且其中很多都在不同的领域,因此最终产品会很棒.

Now the good thing is that there currently a project to merge Selenium and WebDriver as they have their strengths and weaknesses and a number of them are in different areas so the final product will be amazing.

我相信他们可能在 Google 代码 所以你需要做的就是更新 Selenium 的实例,它应该开始使用 WebDriver 代码来运行你的测试.

I believe that they may have a working version of the WebDriverBackedSelenium at Google Code so all you would need to do is update the instantiation of Selenium and it should start using the WebDriver code to run your test.

这篇关于GWT 2.0 的硒测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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