Reputation: 11
I am learning angular and e2e and wanted to find out if anyone can point me in the right direction with the error i got. I followed thru this tutorial found at http://www.webdriverjs.com/protractor-example-with-typescript/
everything worked great with config.js but i started having issues with typescript execution...
i suspect something is wrong with package.json but not sure what. from reading stuff, there are different ways of configuring the package.json file like with versions and stuff... but i am new to protractor and can't figure out why some have the devdependencies, and some dont etc...
any help with this is greatly appreciated
here is the error i am getting when executing - npm test
C:\Users\username\Desktop\ProtractorAutomation>npm test
[email protected] pretest C:\Users\username\Desktop\ProtractorAutomation npm run tsc
[email protected] tsc C:\Users\username\Desktop\ProtractorAutomation tsc
error TS2688: Cannot find type definition file for 'protractor'.
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 npm ERR! npm v3.10.10 npm ERR! code ELIFECYCLE npm ERR! [email protected] tsc:
tsc
npm ERR! Exit status 2 npm ERR! npm ERR! Failed at the [email protected] tsc script 'tsc'. npm ERR! Make sure you have the latest version of node.js and npm installed. npm ERR! If you do, this is most likely a problem with the protractorautomation package, npm ERR! not with npm itself. npm ERR! Tell the author that this fails on your system: npm ERR! tsc npm ERR! You can get information on how to open an issue for this project with: npm ERR! npm bugs protractorautomation npm ERR! Or if that isn't available, you can get their info via: npm ERR! npm owner ls protractorautomation npm ERR! There is likely additional logging output above.npm ERR! Please include the following file with any support request: npm ERR!
C:\Users\username\Desktop\ProtractorAutomation\npm-debug.log npm ERR! Test failed. See above for more details.
my folder structure:
Folder "ProtractorAutomation" consists of these folders/ files
And files:
i tried to debug and ran some commands that added a lot of modules to node_modules directory
Here are the key files
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 = inside specs folder
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 = inside specs folder
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
capabilities: {
'browserName': 'chrome'
// 'browserName': 'firefox'
},
framework: 'jasmine',
specs: ['./specs/FirstSpec.js'],
jasmineNodeOpts: {
defaultTimeoutInterval: 30000
}
};
FirstSpec.ts = inside specs folder
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 folder - this is when i just run 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 = inside 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 = inside 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');
});
});
});
});
here are the versions
node -v v6.11.4
npm -v 3.10.10
protractor --version Version 5.1.2
i ran some commands to update/install typings and got lots of folders inside node_modules....
Thanks DH
Update after executing npm install Thanks, I tried it, but still get an error... here are the files in Directory of 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>npm install
Upvotes: 0
Views: 629
Reputation: 11
I was able to fix this, by running it on another pc. I think my mistake was with the folders. Followed tutorial again, changed the protractor version from 4 to 5 inside package.json file and it worked.
Upvotes: 0