Intern/Leadfoot:Getting error-在instanceof check中需要一个函数,但在.Cl



我正在学习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_modulesleadfootSession.js:88:40>
  at <node_modulesleadfootSession.js:109:39>
  at new Promise  <node_modulesdojoPromise.ts:411:3>
  at ProxiedSession._post  <node_modulesleadfootSession.js:63:10>
  at Element._post  <node_modulesleadfootElement.js:23:31>
  at Element.click  <node_modulesleadfootElement.js:138:15>
  at Command.<anonymous>  <node_modulesleadfootCommand.js:680:19>
  at <node_modulesdojoPromise.ts:393:15>
  at run  <node_modulesdojoPromise.ts:237:7>
  at <node_modulesdojonextTick.ts:44:3>
  at Command.target.(anonymous function) [as click]  <node_modulesleadfootComm
and.js:674:11>
  at Test.registerSuite.IQC_HomePage [as test]  <testsfunctionalIQC_Acceptance
.js:44:7>
  at <node_modulesinternlibTest.js:181:24>
  at <node_modulesinternbrowser_modulesdojoPromise.ts:393:15>
  at runCallbacks  <node_modulesinternbrowser_modulesdojoPromise.ts:11:11>
  at <node_modulesinternbrowser_modulesdojoPromise.ts:317:4>
  at run  <node_modulesinternbrowser_modulesdojoPromise.ts:237:7>
  at <node_modulesinternbrowser_modulesdojonextTick.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

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

这里有一个建议:

.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会这样做)。

希望这能有所帮助!

最新更新