Intern / Leadfoot:获取错误 - 在instanceof检查中期望一个函数,但是在[object(对象)方法上)。{Click()方法

时间:2016-04-19 23:29:51

标签: intern leadfoot

我正在学习Intern / leadfoot并尝试编写一个简单的测试。测试是将用户登录到站点并在下一页验证后注销用户。

使用Chromedriver v2.21。

Getting unknown error : Expecting a function in instanceof check, but got [object Object] for click() method for an element. However, the element is being identified and get the value for getVisibleText().

这是我的测试代码:

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

    registerSuite({
        name: 'Acceptance',             

        'Login': function () {          
            return this.remote  
                .get(require.toUrl('http://example.com'))
                .setFindTimeout(5000)
                .findByXpath('id("ius-userid")')
                    .click()
                    .type('user@user.com')
                    .end()
                .findByXpath('id("ius-password")')
                    .click()
                    .type('password')
                    .end()
                .findByXpath('id("ius-sign-in-submit-btn")')
                    .click()                    
                    .end()                      
                .sleep(15000)
        },

        'HomePage': function () {           
            return this.remote
                .setFindTimeout(5000)
                .findByXpath('id("userWelcome")')                   
                    .getVisibleText()
                        .then(function (text) {                         
                            assert.strictEqual(text, 'Welcome user@user.com!', 'Vaerify that, the Home page for the logged in user is displayed!');
                    })
                    .end()
                .findByXpath('id("settingsAndLogout")/A[2]') 
                    .getVisibleText()
                        .then(function(text){
                            console.log("The Sign out link text is :...", text.trim());
                            assert.strictEqual(text.trim(), 'Sign Out', 'Verify that, the Sign Out link is present.');
                        })                  
                    .click()
                    .end()
        }
    });
});

而且,这是输出:

Listening on 0.0.0.0:9000
Tunnel started
? Created session chrome on any platform (5fcd3559690a324e3a5a3db6cd367387)
√ chrome on any platform - Acceptance - Login (20.268s)
The Sign out link text is :... Sign Out
x chrome on any platform - Acceptance - HomePage (0.13s)
UnknownError: [POST http://localhost:4444/wd/hub/session/5fcd3559690a324e3a5a3db
6cd367387/element/0.8815118646376954-2/click] unknown error: Expecting a functio
n in instanceof check, but got [object Object]
  (Session info: chrome=49.0.2623.112)
  (Driver info: chromedriver=2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7
c4),platform=Windows NT 6.1 SP1 x86_64)
  at runRequest  <node_modules\leadfoot\Session.js:88:40>
  at <node_modules\leadfoot\Session.js:109:39>
  at new Promise  <node_modules\dojo\Promise.ts:411:3>
  at ProxiedSession._post  <node_modules\leadfoot\Session.js:63:10>
  at Element._post  <node_modules\leadfoot\Element.js:23:31>
  at Element.click  <node_modules\leadfoot\Element.js:138:15>
  at Command.<anonymous>  <node_modules\leadfoot\Command.js:680:19>
  at <node_modules\dojo\Promise.ts:393:15>
  at run  <node_modules\dojo\Promise.ts:237:7>
  at <node_modules\dojo\nextTick.ts:44:3>
  at Command.target.(anonymous function) [as click]  <node_modules\leadfoot\Comm
and.js:674:11>
  at Test.registerSuite.IQC_HomePage [as test]  <tests\functional\IQC_Acceptance
.js:44:7>
  at <node_modules\intern\lib\Test.js:181:24>
  at <node_modules\intern\browser_modules\dojo\Promise.ts:393:15>
  at runCallbacks  <node_modules\intern\browser_modules\dojo\Promise.ts:11:11>
  at <node_modules\intern\browser_modules\dojo\Promise.ts:317:4>
  at run  <node_modules\intern\browser_modules\dojo\Promise.ts:237:7>
  at <node_modules\intern\browser_modules\dojo\nextTick.ts:44:3>
  at nextTickCallbackWith0Args  <node.js:453:9>
  at process._tickCallback  <node.js:382:13>
No unit test coverage for chrome on any platform

需要帮助解决问题。提前谢谢!

1 个答案:

答案 0 :(得分:0)

这是一个建议:

.findByXpath('id("settingsAndLogout")/A[2]')
        .getVisibleText()
        .then(function(text){
          console.log("The Sign out link text is :...", text.trim());
          assert.strictEqual(text.trim(), 'Sign Out', 'Verify that, the Sign Out link is present.');
        })
      .end()
      .findByXpath('id("settingsAndLogout")/A[2]')
        .click()
      .end()

不是最优雅的解决方案,因为findbyXpath是多余的。但问题是,.click()期望先前的命令/元素promise在解析时返回实际元素(findByXpath会这样做)。

希望这有帮助!