如何使用 Typescript 在 Atom 中集成 Protractor 测试用例?

How to integrate Protractor test cases in Atom using Typescript?

我已经为 atom 安装了 typescript,用于编写用于自动化的 Protractor 脚本。

我的代码是用 Jasmine 框架编写的,因为量角器很好地支持它。

我写的是这个结构

 describe('Sign in',function(){
     it ('Verify Modules Present', function(){
     loginPage.enterUsernameAndPasswordWithSignIn('a','b');
     browser.sleep(3000);
     var module = element(by.xpath("//*[@ng-reflect-router-link='My']"));
     browser.wait(protractor.ExpectedConditions.elementToBeClickable(module),
                                  8000).thenCatch(function () {
              assert.fail(' element is not click able');
      });
    var expectedModuleName = ["My", "X","Y", "Z" ];
    var testArray = ["My", "X","Y", "Z" ];;
    logger.log('info','Checking All modules');
    for (var i = 0; i < testArray.length;i++) {
      var moduleName = text.verifyText("//*[@ng-reflect-router-link='"+ testArray[i] + "']");
      expect(moduleName).toBe(expectedModuleName[i]);
    }
  logger.log('info','Checked All modules');
  });
});

我收到以下错误。

我的理解是:Typescript 无法找到 Jasmine 库。 如何操作?

我经历了: https://angular.io/docs/ts/latest/testing/jasmine-testing-101.html

但找不到太多。我也安装了打字。但我不知道如何使用它。

如何将 Jasmine Framework 配置为 Protractor 的 atom 以便解决此错误?

如果不是这样,哪个编辑器对这样做很有用,如何做?

请指导我..

显然,其中一些问题(例如 require 和 loginPage)不一定与 Jasmine 有任何关系。但是,问题是这些是全局变量,TS 编译器找不到它们的声明。解决此问题的最简单方法是按以下方式在文件顶部声明每个:

declare var describe: any;

这将解决 describeit 的问题。其他问题,例如 require 将是因为您没有使用 module import syntax.

您必须安装 jasminenode 打字以便 typescript 识别它们。现在有更好的方法,不需要 typings 文件夹和 typings.json。我们有 @types 个依赖项。

因此您可以按照以下步骤进行操作-

转到您的项目文件夹并安装依赖项-

 npm install --save-dev @types/jasmine //this would install jasmine typings as a dev dependency in your package.json
 npm install --save-dev @types/node   //this would install node typings as a dev dependency in your package.json

安装后尝试使用 tsctsc -w 观察模式编译它,现在你应该不会看到那些 TS 语法错误了!

而且你必须从 protractor/globals 导入 browser 才能使用它的方法,就像这样-

import {browser} from 'protractor/globals';

有关 protractor with typescript it uses cucumber as well as you can check out the official protractor-typescript example

初始设置的更多详细信息,您可以查看我的代表

这并没有完全解决我的问题。除了安装茉莉花类型(以上答案)

我必须打开 tsconfig.json 并确保 jasminecompilerOptions 下的 types 列表中。例如 { "compileOnSave": false, "compilerOptions": { "outDir": "./dist/out-tsc", "baseUrl": "src", "sourceMap": true, "declaration": false, "moduleResolution": "node", "emitDecoratorMetadata": true, "experimentalDecorators": true, "allowJs": true, "target": "es5", "paths": { "environments": [ "./environments" ] }, "types": [ "node", "jasmine" ], "typeRoots": [ "node_modules/@types" ], "lib": [ "es2016", "dom" ] } } 添加 "jasmine" 作为类型后,错误立即在 Atom 中消失。