1

几天前,我开始阅读有关 Web 应用程序自动化测试的内容,经过大量试验和错误(和教程),终于设法在本地和 BrowserStack 上运行了几个实习生功能测试,但有一件事我不能环绕我的头是报告。

例如,我有一个简单的测试,它填写一些登录页面数据,提交表单,并检查一切是否正常。

代码可能如下所示:

define(function (require) {
    var registerSuite = require('intern!object');
    var assert = require('intern/chai!assert');
    var fs = require('intern/dojo/node!fs');

    registerSuite({
        name: 'index',

        'Log in test': function () {
            var user = 'username';
            var pass = 'pAsssWord';

            return this.remote                
                .get(require.toUrl('http://localhost/MyApp/'))
                .setFindTimeout(20000)                              

                //fill in username
                .findDisplayedByCssSelector('#panelUsernamePassword .usernameField')                
                    .click()
                    .clearValue()
                    .type(user)
                    .end()

                //fill in password
                .findDisplayedByCssSelector('#panelUsernamePassword .passwordField')                
                    .click()
                    .clearValue()
                    .type(pass)
                    .end()
                .takeScreenshot()
                .then(function(data) {
                    fs.writeFileSync("after-data-filled.png", data, 'base64');
                })  
                //click login button
                .findDisplayedByCssSelector('#panelUsernamePassword button')
                .click()
                .end()
                .sleep(500)
                .takeScreenshot()
                .then(function(data) {
                    fs.writeFileSync("after-login-pressed.png", data, 'base64');
                })
                //click popup close button
                .findDisplayedByCssSelector('div[id$="close-button"]')
                .click()
                .end()
                .sleep(500)
                .takeScreenshot()
                .then(function(data) {
                    fs.writeFileSync("no-popup.png", data, 'base64');
                })              
                .end();
        }
    });
});

运行后intern-runner config=tests/intern.js

测试将通过,我将在控制台窗口中看到类似

    Listening on 0.0.0.0:9000
    Tunnel started
    ‣ Created session chrome 39 on WINDOWS (c7873066-b185-4025-a93a-829ea0fdb364)
    ✓ chrome 39 on WINDOWS - index - Log in test (15.393s)
    No unit test coverage for chrome 39 on WINDOWS
    chrome 39 on WINDOWS: 0/1 tests failed

好的,如果测试通过,我真的不需要太多信息,一切都很好,但另一方面,如果在测试中我有类似的东西:

.findDisplayedByCssSelector('#thisIsSomethingThatIsNotOnThePage')

我得到的关于失败的唯一信息是:

NoSuchElement: An element could not be located on the page using the given search parameters.

有没有办法知道页面上的哪个元素没有找到?也许我做错了什么?

谢谢

编辑:

完整的错误摘要:

× chrome 47 on WINDOWS - index - Log in test
NoSuchElement: An element could not be located on the page using the given search parameters.
  at <..\..\AppData\Roaming\npm\node_modules\intern\node_modules\leadfoot\lib\findDisplayed.js:37:21>
  at <..\..\AppData\Roaming\npm\node_modules\intern\node_modules\dojo\Promise.ts:393:15>
  at run  <..\..\AppData\Roaming\npm\node_modules\intern\node_modules\dojo\Promise.ts:237:7>
  at <..\..\AppData\Roaming\npm\node_modules\intern\node_modules\dojo\nextTick.ts:44:3>
  at doNTCallback0  <node.js:419:9>
  at process._tickCallback  <node.js:348:13>
  at Command.findDisplayed  <..\..\AppData\Roaming\npm\node_modules\intern\node_modules\leadfoot\Command.js:23:10>
  at Command.prototype.(anonymous function) [as findDisplayedByCssSelector]  <..\..\AppData\Roaming\npm\node_modules\intern\node_modules\leadfoot\lib\strategies.js:28:16>
  at Test.registerSuite.Log in test [as test]  <tests\functional\index.js:21:6>
  at <..\..\AppData\Roaming\npm\node_modules\intern\lib\Test.js:211:24>
  at <..\..\AppData\Roaming\npm\node_modules\intern\node_modules\dojo\Promise.ts:393:15>
  at runCallbacks  <..\..\AppData\Roaming\npm\node_modules\intern\node_modules\dojo\Promise.ts:11:11>
  at <..\..\AppData\Roaming\npm\node_modules\intern\node_modules\dojo\Promise.ts:317:4>
  at run  <..\..\AppData\Roaming\npm\node_modules\intern\node_modules\dojo\Promise.ts:237:7>
  at <..\..\AppData\Roaming\npm\node_modules\intern\node_modules\dojo\nextTick.ts:44:3>
  at doNTCallback0  <node.js:419:9>
4

1 回答 1

1

我不知道你怎么说这是你得到的关于错误的唯一信息。错误的堆栈跟踪显示在您粘贴的错误消息的正下方,将包括测试中导致错误的确切行。错误消息还包括发送到服务器的参数,这些参数准确地命名了搜索的元素。例如,我刚刚运行了一个测试来演示正常的错误输出:

Listening on 0.0.0.0:9000
Tunnel started
‣ Created session firefox on any platform (fb89e8af-73d6-4c90-bfe7-82820bf6e312)
× firefox on any platform - error handling demo (1.34s)
NoSuchElement: [POST http://localhost:4444/wd/hub/session/fb89e8af-73d6-4c90-bfe7-82820bf6e312/element / {"using":"css selector","value":".missing"}] Unable to locate element: {"method":"css selector","selector":".missing"}
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.48.2', revision: '41bccdd', time: '2015-10-09 19:59:12'
System info: [redacted]
Driver info: driver.version: unknown
  at ProxiedSession._post  <node_modules/intern/node_modules/leadfoot/Session.js:59:30>
  at ProxiedSession.Session.find  <node_modules/intern/node_modules/leadfoot/Session.js:1055:15>
  […]
  at Test.registerSuite.greeting form [as test]  <tests/functional/index.js:12:6>
  […]

如您所见,来自 Intern 的错误消息包括有关失败的端点 ( /element)、失败的查询(.missing使用 CSS 选择器)和失败的测试行(tests/functional/index.js 第 12 列)的显式信息6)。很难提供比这更多的信息!如果您没有看到这些信息,那么您可能有一些系统配置错误,尽管我不知道那可能是什么(真的是旧的或有问题的 Node.js?Chrome 39 肯定是古老的)。

于 2015-12-21T20:34:14.433 回答