执行npm测试时出错 - 错误TS2688:找不到'量角器'

时间:2017-10-23 15:24:46

标签: protractor angularjs-e2e

我正在学习角度和e2e,想知道是否有人 可以指出我正确的方向与我得到的错误。 我通过本教程发现了 http://www.webdriverjs.com/protractor-example-with-typescript/

使用config.js,一切都很好,但我开始遇到问题 打字稿执行...

我怀疑package.json有问题,但不确定是什么。 从阅读的东西,有不同的方式配置package.json文件,如版本和东西......但我是新的量角器,无法弄清楚为什么有一些有devdependencies,有些不等...

非常感谢任何帮助

这是执行时遇到的错误 - npm test

C:\Users\username\Desktop\ProtractorAutomation>npm test

  

protractorautomation@1.0.0预测试   C:\ Users \ username \ Desktop \ ProtractorAutomation npm run tsc

     

protractorautomation@1.0.0 tsc   C:\ Users \ username \ Desktop \ ProtractorAutomation tsc

     

错误TS2688:找不到'量角器'的类型定义文件。

     

npm ERR! Windows_NT 6.1.7601 npm ERR! argv“C:\ Program   Files \ nodejs \ node.exe“”C:\ Program Files \ nodejs \   node_modules \ npm \ bin \ npm-cli.js“”run“”tsc“npm ERR!node v6.11.4   错误的ERR! npm v3.10.10 npm ERR!代码ELIFECYCLE npm ERR!   protractorautomation@1.0.0 tsc:tsc npm ERR!退出状态2 npm ERR!   错误的ERR!在protractorautomation@1.0.0 tsc脚本'tsc'失败。   错误的ERR!确保您拥有最新版本的node.js和npm   安装。错误的ERR!如果你这样做,这很可能是一个问题   protractorautomation包,npm ERR!不是与npm本身。错误的ERR!   告诉作者你的系统失败了:npm ERR! tsc npm   呃!您可以获取有关如何为此项目打开问题的信息   with:npm ERR! npm bug protractorautomation npm ERR!或者如果那样   没有,您可以通过以下方式获取他们的信息:npm ERR! npm所有者ls   自动纠错npm ERR!可能还有其他日志记录   以上输出。

     

npm ERR!请在任何支持请求中包含以下文件:   npm ERR!
  C:\ Users \ username \ Desktop \ ProtractorAutomation \ npm-debug.log npm ERR!   测试失败。有关详细信息,请参见上文。

我的文件夹结构:

文件夹“ProtractorAutomation”由这些文件夹/文件组成

  • 文件夹ConvertedJSFiles
  • 文件夹node_modules
  • 文件夹规格

文件:

  • config.ts
  • config.js
  • npm-debug
  • package.json
  • tsconfig.json

我试图调试并运行一些添加了大量模块的命令 node_modules目录

以下是关键文件

的package.json

{
  "name": "protractorautomation",
  "version": "1.0.0",
  "description": "Protractor Typescript automation framework",
  "main": "config.js",
  "dependencies": {
    "protractor": "^5.1.2"
  },
  "devDependencies": {
    "@types/jasminewd2": "^2.2.0",
    "ts-node": "^3.0.2"},
  "scripts": {
    "pretest": "npm run tsc",
    "test": "protractor ConvertedJSFiles/config.js",
     "tsc": "tsc"
  },
  "keywords": [
    "Protractor",
    "Typescript"
  ],
  "author": "",
  "license": "ISC"
}

tsconfig.json

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "moduleResolution": "node",
    "sourceMap": false,
    "declaration": false,
    "removeComments": false,
    "noImplicitAny": false,
    "outDir": "ConvertedJSFiles",
    "types": ["jasmine", "node", "protractor"]
  },
  "exclude": [
    "node_modules"
  ]
}

config.ts =里面的specs文件夹

import { ProtractorBrowser, Config } from 'protractor';
export let config: Config = {
  seleniumAddress: 'http://localhost:4444/wd/hub',
  capabilities: {
    'browserName': 'chrome'
    //'browserName':'firefox'
    },
  framework: 'jasmine',
  specs: ['./specs/**/*.js'],
  jasmineNodeOpts: {
    defaultTimeoutInterval: 90000
  },
  onPrepare: () => {
   let globals = require('protractor');
   let browser = globals.browser;
   browser.manage().window().maximize();
   browser.manage().timeouts().implicitlyWait(5000);
 }
}

config.js =里面的specs文件夹

exports.config = {
  seleniumAddress: 'http://localhost:4444/wd/hub',
  capabilities: {
   'browserName': 'chrome'
//    'browserName': 'firefox'

    },
  framework: 'jasmine',
  specs: ['./specs/FirstSpec.js'],
  jasmineNodeOpts: {
    defaultTimeoutInterval: 30000
  }
};

FirstSpec.ts =内部规格文件夹

import { ElementFinder, browser, by, element } from 'protractor';
describe('angularjs homepage todo list', function () { //Suite in 

Jasmine
  it('should add a todo', function () { // Test in Jasmine
    browser.get('https://angularjs.org'); // Entering application url in 

browser
    // Enter text under TODO
    element(by.model('todoList.todoText')).sendKeys('write first 

protractor test');
    element(by.css('[value="add"]')).click(); // Clicks on 'Add' button
    // Getting all Todo lists displayed
    element.all(by.repeater('todo in')).then(function (todoList) {
      // Asserting the TODO's count as 3
      expect(todoList.length.toString()).toEqual('3');
      todoList[2].getText().then(function (text) {
        //Verifying newly entered TODO is added
        expect(text).toEqual('write first protractor test');
      });
    });
  });
});

FirstSpec.js = inside specs文件夹 - 这是我刚运行config.js

的时候
//Suite in Jasmine
describe('angularjs homepage todo list', function() {
  // Test in Jasmine
  it('should add a todo', function() {
    // Entering application url in browser
    browser.get('https://angularjs.org');
    // Enter text under TODO input field

//in the html code this element is :
//<input type="text" ng-model="todoList.todoText" size="30"
// placeholder="add new todo here" class="ng-pristine ng-valid ng-empty 

ng-touched">
    element(by.model('todoList.todoText')).sendKeys('write first 

protractor test');

    // Clicks on 'Add' button
    // line in code where button is
    //<input class="btn-primary" type="submit" value="add">  WHY 

BY.CSS???
    element(by.css('[value="add"]')).click();

    // Getting all Todo lists displayed
    var todoList = element.all(by.repeater('todo in todoList.todos'));
    // Asserting the TODO's count as 3
    expect(todoList.count()).toEqual(3);
    //Verifying newly entered TODO is added
    expect(todoList.get(2).getText()).toEqual('write first protractor 

test');
  });
});

config.js =在ConvertedJSFiles内部

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.config = {
    seleniumAddress: 'http://localhost:4444/wd/hub',
    capabilities: {
        'browserName': 'chrome'
        //'browserName':'firefox'
    },
    framework: 'jasmine',
    specs: ['./specs/**/*.js'],
    jasmineNodeOpts: {
        defaultTimeoutInterval: 90000
    },
    onPrepare: function () {
        var globals = require('protractor');
        var browser = globals.browser;
        browser.manage().window().maximize();
        browser.manage().timeouts().implicitlyWait(5000);
    }
};

FirstSpec.js = ConvertedJSFiles / Specs

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var protractor_1 = require("protractor");
describe('angularjs homepage todo list', function () {
    it('should add a todo', function () {
        protractor_1.browser.get('https://angularjs.org'); // Entering application url in browser
        // Enter text under TODO
        protractor_1.element(protractor_1.by.model('todoList.todoText')).sendKeys('write first protractor test');
        protractor_1.element(protractor_1.by.css('[value="add"]')).click(); // Clicks on 'Add' button
        // Getting all Todo lists displayed
        protractor_1.element.all(protractor_1.by.repeater('todo in')).then(function (todoList) {
            // Asserting the TODO's count as 3
            expect(todoList.length.toString()).toEqual('3');
            todoList[2].getText().then(function (text) {
                //Verifying newly entered TODO is added
                expect(text).toEqual('write first protractor test');
            });
        });
    });
});

这是版本

节点-v v6.11.4

npm -v 3.10.10

量角器 - 版本 版本5.1.2

我运行了一些命令来更新/安装打字输入并在node_modules ....中获得了很多文件夹。

由于 DH

执行npm install后更新 谢谢,我试过了,但仍然收到错误...这里是C:\ Users \ username \ Desktop \ ProtractorAutomation目录中的文件

10/23/2017  09:58 AM    <DIR>          .
10/23/2017  09:58 AM    <DIR>          ..
10/22/2017  08:23 PM               288 config.js
10/22/2017  08:23 PM               547 config.ts
10/22/2017  07:17 PM    <DIR>          ConvertedJSFiles
10/22/2017  11:01 PM    <DIR>          node_modules
10/23/2017  09:54 AM             5,706 notes_files-questions.txt
10/23/2017  12:22 AM               517 package.json
10/22/2017  07:31 PM    <DIR>          specs
10/22/2017  11:03 PM               353 tsconfig.json
               5 File(s)          7,411 bytes
               5 Dir(s)  358,075,498,496 bytes free

C:\Users\username\Desktop\ProtractorAutomation>npm install
npm ERR! Windows_NT 6.1.7601
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\
node_modules\\npm\\bin\\npm-cli.js" "install"
npm ERR! node v6.11.4
npm ERR! npm  v3.10.10
npm ERR! code ETARGET

npm ERR! notarget No compatible version found: @types/jasminewd2@^2.2.0
npm ERR! notarget Valid install targets:
npm ERR! notarget 2.0.3, 2.0.2, 2.0.1, 2.0.0
npm ERR! notarget
npm ERR! notarget This is most likely not a problem with npm itself.
npm ERR! notarget In most cases you or one of your dependencies are requesting
npm ERR! notarget a package version that doesn't exist.
npm ERR! notarget
npm ERR! notarget It was specified as a dependency of 'protractorautomation'
npm ERR! notarget

npm ERR! Please include the following file with any support request:
npm ERR!     C:\Users\username\Desktop\ProtractorAutomation\npm-debug.log

C:\ Users \ username \ Desktop \ ProtractorAutomation&gt; npm install

1 个答案:

答案 0 :(得分:0)

我能够通过在另一台电脑上运行来解决这个问题。我想我的错误在于文件夹。再次关注教程,将量程器版本从package.json文件中的4更改为5,并且工作正常。