从文本输入字段获取链接,然后使用DalekJS打开它

时间:2015-04-10 03:06:22

标签: automated-tests dalekjs

我有一个问题,我需要遍历使用不可点击的DalekJS的链接,它是相当复制/可管理的。如何从浏览器中的输入字段中检索值,然后在test.open()调用中使用它?

<table>
    <tbody>
        <tr>
            <td>Link 1</td>
            <td><input type="text" value="http://example.com/link-1" class="start-link"></td>
        </tr>
        <tr>
            <td>Link 2</td>
            <td><input type="text" value="http://example.com/link-2" class="start-link"></td>
        <tr>
</table>

在上面的示例中,我希望DalekJS在测试过程中动态运行test.open('http://example.com/link-1');

module.exports = {

    'A test case': function (test) {
        test.open('http://example.com/example-from-above.html')
        .open('http://example.com/link-1')  //This is the link I'm trying to retrieve dynamically.
        .screenshot('image.png')
        .done();
    }
}

我该如何做到这一点?

1 个答案:

答案 0 :(得分:0)

DalekJS不允许同步读取HTML元素的值并在测试脚本中使用它们。如果您需要与测试页面的内容进行交互,execute方法可能有所帮助。

您可以尝试通过功能设置窗口位置&#34;在浏览器中执行&#34;:

module.exports = {

    'A test case': function (test) {
        test.open('http://example.com/example-from-above.html')
        // Open the URL from the first input element value
        .execute(function () {
            var input = document.querySelectorAll('.start-link')[0];
            location = input.value;
        })
        // Wait until the browser opens the page
        .waitFor(function () {
            return location.pathname.indexOf('link-1') > 0;
        })
        .screenshot('image.png')
        .done();
    }
}
相关问题