6

Cannot find name DescribeMy project is going from standalone to Web, Our new WebSite is getting created in AngularJS so Protractor is the tool selected for Test Automation.

I want to Integrate Typescript with dependencies of Jasmine and Node so that I don't get errors such as

cannot find name Describe
cannot find name it
cannot find name Expect

Can Anyone tell me how to add Jasmine and Protractor dependencies, so that when I hit ctrl + space i'll get all options available.

I have installed Typescript. And I am getting protractor dependencies such as browser, element, by etc.

What should i do for describe,it,expect (Jasmine stuffs) ?

Kishan Patel
  • 1,385
  • 3
  • 13
  • 24
  • check my answer in this question.. it is not exactly the same but I believe you have the same issue. You need type definition files for jasmine..http://stackoverflow.com/questions/39058504/why-i-am-not-able-be-see-any-expect-methods-like-tobe-in-protractor/39058896#39058896 – TypeScripter Sep 06 '16 at 16:01
  • Where can i find jasmine.d.ts file ? I got the same error which balaji got. – Kishan Patel Sep 07 '16 at 06:57
  • /typings/main/ambient/jasmine/jasmine.d.ts there is no path like this. – Kishan Patel Sep 07 '16 at 06:58
  • http://stackoverflow.com/questions/40284366/how-to-integrate-protractor-test-cases-with-hiptest Can anyone help me on this ? – Kishan Patel Oct 28 '16 at 04:44

2 Answers2

7

I use Visual Studio Code everyday to write my scripts, it's my current favourite editor for Protractor because of its built in support for TypeScript!

Here are the following things which can come into my mind which could help you setup your framework-

  • Download the latest VS Code version - https://code.visualstudio.com/download
  • Install typescript globally npm install -g typescript
  • Install protractor globally npm install -g protractor
  • Create your project folder
  • Setup you project folder for git, node and typescript -

    npm init -f // will create default package.json stating its nodejs project
    git init  // will create .git file, you project is now git project
    tsc --init  // will create tsconfig.json stating its typescript project
    
  • Install typings and dev dependencies-

    npm install --save-dev protractor // this will install protractor as a dev dependency
    npm install --save-dev typescript // this will install typescript as a dev dependency
    npm install --save-dev @types/jasmine // jasmine typings
    npm install --save-dev @types/node    // node typings
    
  • At this point you have setup your basic protractor-typescript project and you can see all the typings and dependencies in package.json. Now you are good to write your typed scripts :).
  • Now compile your scripts by running -

    tsc or tsc -w 
    
  • After successfull compilation all your javascript files would be generated.
  • The run protractor

    protractor config.js
    
  • You can also setup your vs code for debugging with protractor which I have mentioned here - Protractor -VS Code Debugging

For more details pls refer the TypeScript Tutorial, Protractor API

The Typescript error you are observing this is due to VS Code not recognizing global typescript 2.0 version.

To solve this open vscode go to preferences--> user settings --> settings.json will be opened and enter the highlighted path as shown

enter image description here Save your file and restart VSCode now you are good to go :)

Ram Pasala
  • 4,931
  • 3
  • 16
  • 26
  • I did all the steps suggested by you Ram. I created my first file as test.ts. It still says cannot find name 'describe' and cannot find 'it'. I added the screenshot. Please see. – Kishan Patel Sep 08 '16 at 09:24
  • import {$} from 'D:/nsWeb/node_modules/protractor/globals'; Is this the option? – Kishan Patel Sep 08 '16 at 09:36
  • 1
    no need to give the absolute path you can just give `import {$} from 'protractor/globals'` and the typescript error you are seeing that is an existing issue , they are working on it you would see it would show like that but it actually compiles successfully, this would be fixed in coming release! – Ram Pasala Sep 08 '16 at 09:38
  • My describe error is also gone now... Yupieeee. Thanks a ton Ram. Really I appreciate your efforts right from scratch.. I will always contact you for help. Can I ? – Kishan Patel Sep 08 '16 at 09:45
  • I have updated my answer as well if you face this issue in future you can look at it , you can change settings.json in vscode ! sure i would be happy to help – Ram Pasala Sep 08 '16 at 09:53
  • Yes Sure . Thanks a lot. – Kishan Patel Sep 08 '16 at 10:01
  • One more question.. How to make background white? – Kishan Patel Sep 08 '16 at 10:05
  • browser.wait(protractor.ExpectedConditions.elementToBeClickable(module), 8000).thenCatch(function () { assert.fail(' element is not click able'); how can i import this assert ? I am getting cannot find name 'assert'. – Kishan Patel Sep 08 '16 at 11:56
  • node_modules/protractor/built/index.d.ts(1,1): error TS2654: Exported external package typings file cannot contain triple slash references. Please contact the package author to update the package defin ition. Ram how to solve this? – Kishan Patel Sep 09 '16 at 09:54
  • You have to use typescript 2.0 and above versions `npm install -g typescript2.0` – Ram Pasala Sep 09 '16 at 10:11
  • typescript 2.0 is not in the npm registry – Kishan Patel Sep 09 '16 at 10:22
  • My protractor folder is not having globals.js. Why so ? Any Idea? @Ram Pasala – Kishan Patel Oct 04 '16 at 06:51
  • Globals have been removed from version 4.0.9! – Ram Pasala Oct 04 '16 at 14:22
  • So How can i include them ? import {$} from globals ? Any Idea ? – Kishan Patel Oct 05 '16 at 12:42
  • 1
    Now you can import directly-` import {$} from 'protractor' ` – Ram Pasala Oct 06 '16 at 05:55
  • You always tell me to use {$} , but it never works for me. I have to use {browser,element and so on} from protractor , then only it works. Why so Ram? – Kishan Patel Oct 06 '16 at 09:26
  • Ram Can you help me on this ? http://stackoverflow.com/questions/40284366/how-to-integrate-protractor-test-cases-with-hiptest – Kishan Patel Oct 28 '16 at 04:44
2

I agree with the answers given. Just want to share a hack with you.

You don't need to transpile your Typescript codes to JavaScript anymore.

Create a launch.js file

require('ts-node').register({
  compilerOptions: {
    module: 'commonjs'
  },
  disableWarnings: true,
  fast: true
});
exports.config = require('./config/protractor.conf.ts').config;

And kick start protractor execution like:

> protractor launch 

You can save yourself from the headache of transpiling every time you make a change to typescript files.

Happy testng!

Abhinaba
  • 376
  • 1
  • 8