从 selenium 测试脚本回到 selenese

发布于 2024-09-10 18:11:50 字数 489 浏览 1 评论 0原文

我有一堆使用 Test::WWW::Selenium 编写的测试脚本(但我使用 perl 的事实并不重要,selenium 支持的任何语言都可能存在我描述的问题)。当我的应用程序中的齿轮松动时,我想使用 Selenium IDE 重播测试,让我完全控制操作

但我不确定如何从我的测试脚本返回到 selenium IDE,您可以不要将 Perl 粘贴到 IDE 中并将其转换回“HTML”(又名内部 selenium 语言,又名 selenese)。唉,把它拿出来很容易。

RemoteRunner 中有命令历史记录,我可以将其直接复制并粘贴到 selenium ide 中,那太好了,但历史记录框只能保存 5 或 6 行并自行清除!所以它嘲笑我并且毫无用处。

那么如何更有效地记录这些呢? selenium rc 的日志记录选项(-browserSideLog、-log)在这方面似乎没有帮助。我正在考虑找到它的 RemoteRunner.html 并对其进行黑客攻击,这样它就不会清除该列表,但是还有其他方法吗?

I've got a bunch of test scripts written using Test::WWW::Selenium (but the fact that I used perl is inconsequential, any language selenium supports probably has the problem I describe). When the cogs in my application come loose I'd like to replay the test using the Selenium IDE, letting me have full control over the action

But I'm not sure how to go from my test script back into the selenium IDE, you can't paste perl into the IDE and have it transmogrify back to "HTML" (aka, internal selenium language, aka selenese). It was easy enough getting it out, alas.

The RemoteRunner has the command history in it, and I can copy and paste from this directly into selenium ide, and that would be great, but the history box will only hold 5 or 6 lines and clears itself! So it taunts me and is useless.

So how to log these more effectively? The logging options for the selenium rc (-browserSideLog, -log) don't seem to be helpful in this regard. I'm thinking of finding its RemoteRunner.html and hacking at it maybe so it won't clear that list, but is there another way?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

第七度阳光i 2024-09-17 18:11:50

这似乎是一项不太常见的任务,但却非常有趣。我不认为有某种标准方法必须实施。

我不太了解 Perl,并且使用 Java,所以这只是一个提示:

我将为我的测试扩展 DefaultSelenium 类,该类将使用扩展的 HttpCommandProcessor 来记录执行的所有命令:

import com.thoughtworks.selenium.HttpCommandProcessor;

public class ExtHttpCommandProcessor extends HttpCommandProcessor {

    public ExtHttpCommandProcessor(String serverHost, int serverPort,
            String browserStartCommand, String browserURL) {
        super(serverHost, serverPort, browserStartCommand, browserURL);
    }

    public String doCommand(String commandName, String[] args) {
        StringBuffer sb = new StringBuffer();

        sb.append("|" + commandName + "|");     

        if (args!=null) {
            for (String arg : args) {
                sb.append(arg + "|");
            }

            if (args.length<2) {
                sb.append(" |");
            }
        } else {
            sb.append(" | |");
        }

        System.out.println(sb.toString());
        // or log it where you want

        return super.doCommand(commandName, args);
    }

}

然后

import com.thoughtworks.selenium.DefaultSelenium;

public class ExtSelenium extends DefaultSelenium {
    public ExtSelenium(String serverHost, int serverPort,
            String browserStartCommand, String browserURL) {
        super(new ExtHttpCommandProcessor(serverHost, serverPort, browserStartCommand, browserURL));
    }
}

我将扩展 SeleneseTestCase 用作我的测试的基础:

import com.thoughtworks.selenium.SeleneseTestCase;

public class ExSeleneseTestCase  extends SeleneseTestCase {    

    public void setUp(String url, String browserString) throws Exception {
        int port = 4444;
        if (url==null) {
            url = "http://localhost:" + port;
        }
        selenium = new ExtSelenium("localhost", port, browserString, url);
        selenium.start();
        selenium.setContext(this.getClass().getSimpleName() + "." + getName());
    }

}

此类测试的输出将如下所示:

|getNewBrowserSession|*iexplore|http://localhost:8080/|
|setContext|SimpleTest.testNew| |
|打开|/webapp/test.html| |
|isTextPresent|示例文本| |
|点击|样本链接| |
|waitForPageToLoad|10000| |
|测试完成| | |

此解决方案不会记录 verifyassert ,因此它们也可能在 ExSeleneseTestCase 中被覆盖以产生一些跟踪。

It seems to be a not very common task but very interesting one. I do not think that there's some standard way so something has to be implemented.

I do not know Perl much and I use Java, so this is just a heads up:

I would extend the DefaultSelenium class for my tests that will use extended HttpCommandProcessor that will logs all commands performed:

import com.thoughtworks.selenium.HttpCommandProcessor;

public class ExtHttpCommandProcessor extends HttpCommandProcessor {

    public ExtHttpCommandProcessor(String serverHost, int serverPort,
            String browserStartCommand, String browserURL) {
        super(serverHost, serverPort, browserStartCommand, browserURL);
    }

    public String doCommand(String commandName, String[] args) {
        StringBuffer sb = new StringBuffer();

        sb.append("|" + commandName + "|");     

        if (args!=null) {
            for (String arg : args) {
                sb.append(arg + "|");
            }

            if (args.length<2) {
                sb.append(" |");
            }
        } else {
            sb.append(" | |");
        }

        System.out.println(sb.toString());
        // or log it where you want

        return super.doCommand(commandName, args);
    }

}

And

import com.thoughtworks.selenium.DefaultSelenium;

public class ExtSelenium extends DefaultSelenium {
    public ExtSelenium(String serverHost, int serverPort,
            String browserStartCommand, String browserURL) {
        super(new ExtHttpCommandProcessor(serverHost, serverPort, browserStartCommand, browserURL));
    }
}

Then I would extend SeleneseTestCase for use as the base in my tests:

import com.thoughtworks.selenium.SeleneseTestCase;

public class ExSeleneseTestCase  extends SeleneseTestCase {    

    public void setUp(String url, String browserString) throws Exception {
        int port = 4444;
        if (url==null) {
            url = "http://localhost:" + port;
        }
        selenium = new ExtSelenium("localhost", port, browserString, url);
        selenium.start();
        selenium.setContext(this.getClass().getSimpleName() + "." + getName());
    }

}

The output of such test will look like:

|getNewBrowserSession|*iexplore|http://localhost:8080/|
|setContext|SimpleTest.testNew| |
|open|/webapp/test.html| |
|isTextPresent|Sample text| |
|click|sampleLink| |
|waitForPageToLoad|10000| |
|testComplete| | |

This solution will not log verifys and asserts so they may also be overrided in ExSeleneseTestCase to produce some trace.

淡笑忘祈一世凡恋 2024-09-17 18:11:50

您也可以采取另一种方式,这可能更容易:在生成(部分)selenese HTML 文件时保存它们,并从 perl/java/... 代码中解析文件并使用 doCommand 执行行。这样,您就不必重建断言/验证语句,因为它们一开始就没有丢失。

You could also go the other way, which is probably easier: save the (partial) selenese HTML files when you generate them, and from the perl/java/... code, parse the files and execute the lines using doCommand. That way, you don't have to reconstruct the asserts/verify statements, because they weren't lost in the first place.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文