【问题标题】:What pattern can I use?我可以使用什么模式?
【发布时间】:2010-11-11 14:46:05
【问题描述】:

我正在使用 Selenium 2 实现一个项目,该项目目前不能很好地支持确认对话框。

有一个解决这个限制的方法,您只需覆盖 window.confirm 以返回您需要为特定测试用例返回的值。

可以设置并执行以下字符串:

public static final String CONFIRM_DIALOG_BOX = 
    "window.confirm = function(msg) { return true; }";

public static final String CANCEL_DIALOG_BOX = 
    "window.confirm = function(msg) { return false; }";

作为模板方法,这看起来很简单,但是我在同一个页面对象上有多个测试用例,我需要在与页面交互后确认/拒绝。因此,使用单一方法一次完成所有这些测试是行不通的。

将命令注入到测试方法中可能是有意义的,但我在这里的最终目标是允许我们的技术人员通过将一些字符串写入 XML 来创建测试,然后使用 Spring 表达式语言执行它;这消除了编写测试的一些“容易”。

主要需要注意的是,由于需求,这个测试套件实际上是一个应用程序,而不是一组单独运行的测试用例。如果它们是小型测试用例会容易得多,因为我可以扩展一个抽象测试用例并使用相同的设置和拆卸例程。

我最终要寻找的是沿着这个模板方法的东西,但我需要能够在单个页面对象上支持多个测试用例。

public final void executeTest(boolean confirmDialogBoxResponse) {

    // store normal functionality and allow us to return 
    // window.confirm to normal state upon completion of test.
    prepare(confirmDialogBoxResponse);

    testMethod(); // What about params to these methods?

    /* Adding an interface to the method would be nice, but 
     * would make things a bit more cumbersome for our
     * less technical staff, which would allow me to replace
     * the above with this:
     *
     *    executeTest(TestCommand command, confirmDialogResponse);
     *         command.execute(); // Still have params issue
     */

    // restore window.confirm to normal state -- if we cancel we stay 
    // on same page, and need to restore things as they were, the majority
    // of our confirm cases take you to new pages whereby window.confirm 
    // will be restored for us
    if (!confirmDialogResponse) {
        restore();
    }
}

【问题讨论】:

    标签: java design-patterns selenium-webdriver spring-el


    【解决方案1】:

    你看过Selenium Issue #27 recently (comment#46)吗?它附加了一些补丁,提供对警报和确认的支持?

    【讨论】:

    • 我看过补丁,但想等待“官方”回复。昨天我收到通知说这将是测试版,希望很快就会出现。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-13
    • 1970-01-01
    • 2010-12-11
    • 2010-10-27
    • 1970-01-01
    • 2021-01-06
    相关资源
    最近更新 更多