【问题标题】:How to debug intern functional tests如何调试实习生功能测试
【发布时间】:2015-12-30 03:38:32
【问题描述】:

我正在使用节点检查器来调试我的实习生功能测试。在功能测试中如何使用调试器? 如果我有一个看起来像的功能测试

'Sample Test' : function() {
            console.log("load row grid mesh test");
            return this.remote
            .setFindTimeout(5000)
            .setWindowSize(800, 500)
            .then(pollUntil('return document.evaluate("//span[contains(@class, \'abcd\') and following-sibling::span[child::span[text() = \'App\']]]", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue', 8000))
            .expand("App")
            .expand("Sample")
            .open("SampleApp.xlsx")
            .then(pollUntil('return document.evaluate( "//div[contains(@class, \'Cover\') and @style = \'display: none; top: 0px; left: 0px;\']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue', 8000))
            .findAllByClassName("abc")
              .getAttribute("style")
              .then( function(style) {
                  //I am able to put a debugger here without isssue
                  assert.isTrue(style.length < 32);
                  assert.notStrictEqual(style[0].indexOf("top: 0px;"), -1);
                  assert.notStrictEqual(style[25].indexOf("top: 480px;"), -1);
              }).end()
            debugger // I NEED TO PAUSE HERE
            .findByXpath('//div[@class = \'abc\']//span[text() = \'AppleSample\']')
              .moveMouseTo().end()

不确定如何放置调试器。我是新来的实习生。任何帮助将不胜感激

【问题讨论】:

  • 您是否尝试过在您选择的浏览器中运行您的客户端代码并使用浏览器的调试工具?

标签: intern node-inspector


【解决方案1】:

我个人对intern不熟悉,但假设它提供了Promise接口,你应该可以添加以下代码来触发调试器:

'Sample Test' : function() {
            console.log("load row grid mesh test");
            return this.remote
            .setFindTimeout(5000)
            .setWindowSize(800, 500)
            .then(pollUntil('return document.evaluate("//span[contains(@class, \'abcd\') and following-sibling::span[child::span[text() = \'App\']]]", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue', 8000))
            .expand("App")
            .expand("Sample")
            .open("SampleApp.xlsx")
            .then(pollUntil('return document.evaluate( "//div[contains(@class, \'Cover\') and @style = \'display: none; top: 0px; left: 0px;\']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue', 8000))
            .findAllByClassName("abc")
              .getAttribute("style")
              .then( function(style) {
                  //I am able to put a debugger here without isssue
                  assert.isTrue(style.length < 32);
                  assert.notStrictEqual(style[0].indexOf("top: 0px;"), -1);
                  assert.notStrictEqual(style[25].indexOf("top: 480px;"), -1);
              }).end()
            .then(function(node) {
              debugger; // PAUSE HERE
              return node; // forward the promise value 
            });
            .findByXpath('//div[@class = \'abc\']//span[text() = \'AppleSample\']')
              .moveMouseTo().end()

【讨论】:

    【解决方案2】:

    我认为,一般来说,阅读长篇剧本是非常困难的。 如您所见,调试也很困难。

    我会把它分解成变量,例如:

    var setConfig = this.remote .setFindTimeout(5000) .setWindowSize(800, 500);

    var openSample = setConfig .then(pollUntil('return document.evaluate("//span[contains(@class,\'abcd\') and following-sibling::span[child::span[text() = \'App\']]]", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null) .singleNodeValue', 8000)) .expand("App") .expand("Sample") .open("SampleApp.xlsx");

    var abc = openSample.then(pollUntil('return document.evaluate( "//div[contains(@class, \'Cover\') and @style = \'display: none; top: 0px; left: 0px;\']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue', 8000)) .findAllByClassName("abc"); ...

    这仍然不是最好的方法,但至少看起来更清晰,可以帮助您更轻松地调试。

    【讨论】:

      【解决方案3】:

      我发现自己大部分时间都是通过手动暂停承诺字符串来进行调试的。

      我在问题行之前使用.sleep(10000)暂停测试,然后从终端手动退出crtl + c并使用firebug查看浏览器的状态。

      您还可以在运行测试时设置报告器类型,“控制台”报告器在查找代码中的错误时非常有用,虽然有点冗长。更多实习生文档在这里https://theintern.github.io/intern/#reporter-overview

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-08-28
        • 2014-05-21
        • 2015-06-18
        • 2016-02-11
        • 2015-10-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多