Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

angularjs - How to write Protractor test scripts using Typescript along with Jasmine framework in Visual studio Code?

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) ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...