首页 > 解决方案 > 获取错误 protractor_1.browser.action 不是函数

问题描述

我在执行操作时遇到错误。规格文件代码

it("testcase action", async()=> {

    browser.waitForAngularEnabled(false);
     
    await browser.get("https://google.com");

    await browser.actions().mouseMove(element(by.css("input[name='q']"))).sendKeys("protrac").perform();

    await browser.sleep(8000);

    await browser.actions().sendKeys(protractor.Key.ARROW_DOWN);

    await browser.action().sendKeys(protractor.Key.ENTER);
})
 

配置文件中的代码

import {Config, browser} from "protractor";
 
// An example configuration file

export let config: Config = {

    // The address of a running selenium server.

    //seleniumAddress: 'http://localhost:4444/wd/hub',

    directConnect:true,
  
    // Capabilities to be passed to the webdriver instance.

    capabilities: {

      browserName: 'chrome',

      'goog: chromeOptions':{

        w3c: false

      },
      
    },
  
    // Spec patterns are relative to the configuration file location passed

    // to protractor (in this example conf.js).

    // They may include glob patterns.

    specs: ['testspec.js'],
  
    // Options to be passed to Jasmine-node.

    jasmineNodeOpts: {

      showColors: true, // Use colors in the command line report.

    }

  };

我面临的错误

> protractortypescriptcucumberframework@1.0.0 pretest C:\Users\Admin\Eclipse Protractor 
JavaScript\ProtractorTypeScriptCucumberFramework

> tsc



> protractortypescriptcucumberframework@1.0.0 test C:\Users\Admin\Eclipse Protractor 
JavaScript\ProtractorTypeScriptCucumberFramework

> protractor JSFiles/configuration.js


[12:35:49] I/launcher - Running 1 instances of WebDriver

[12:35:50] I/direct - Using ChromeDriver directly...


DevTools listening on ws://127.0.0.1:50594/devtools/browser/c5170ccf-5c5d-408d-8d10-c6eb3022c11f

Started

(node:7448) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues.
 Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.

F


Failures:

1) Action class testcase action

  Message:

    Failed: protractor_1.browser.action is not a function

  Stack:

    TypeError: protractor_1.browser.action is not a function

        at C:\Users\Admin\Eclipse Protractor 
JavaScript\ProtractorTypeScriptCucumberFramework\testspec.ts:110:15

        at Generator.next (<anonymous>)

        at fulfilled (C:\Users\Admin\Eclipse Protractor 
JavaScript\ProtractorTypeScriptCucumberFramework\JSFiles\testspec.js:5:58)

    From: Task: Run it("testcase action") in control flow

        at UserContext.<anonymous> (C:\Users\Admin\Eclipse Protractor
 JavaScript\ProtractorTypeScriptCucumberFramework\node_modules\jasminewd2\index.js:94:19)

    From asynchronous test:

    Error


        at C:\Users\Admin\Eclipse Protractor 

JavaScript\ProtractorTypeScriptCucumberFramework\testspec.ts:102:1

        at Generator.next (<anonymous>)

        at C:\Users\Admin\Eclipse Protractor 
JavaScript\ProtractorTypeScriptCucumberFramework\JSFiles\testspec.js:8:71

        at new Promise (<anonymous>)

        at __awaiter (C:\Users\Admin\Eclipse Protractor 

JavaScript\ProtractorTypeScriptCucumberFramework\JSFiles\testspec.js:4:12)


        at Suite.fdescribe (C:\Users\Admin\Eclipse Protractor 

JavaScript\ProtractorTypeScriptCucumberFramework\testspec.ts:99:36)


Ran 1 of 5 specs

1 spec, 1 failure

Finished in 13.633 seconds


[12:36:37] I/launcher - 0 instance(s) of WebDriver still running

[12:36:37] I/launcher - chrome #01 failed 1 test(s)

[12:36:37] I/launcher - overall: 1 failed spec(s)

[12:36:37] E/launcher - Process exited with error code 1

npm ERR! code ELIFECYCLE

npm ERR! errno 1

npm ERR! protractortypescriptcucumberframework@1.0.0 test: `protractor JSFiles/configuration.js`

npm ERR! Exit status 1

npm ERR!

npm ERR! Failed at the protractortypescriptcucumberframework@1.0.0 test script.

npm ERR! This is probably not a problem with npm. There is likely additional logging output above.


npm ERR! A complete log of this run can be found in:

npm ERR!     C:\Users\Admin\AppData\Roaming\npm-cache\_logs\2020-07-21T07_06_38_712Z-debug.log

PS C:\Users\Admin\Eclipse Protractor JavaScript\ProtractorTypeScriptCucumberFramework>

标签: protractor

解决方案


推荐阅读