cannot find protractor-result folder 'protractor-html-screenshot-reporter' - node.js

I'm trying to generate reports in Protractor and i followed this tutorial to do that.
Here is my conf.js file.
var HtmlReporter = require('protractor-html-screenshot-reporter');
var reporter = new HtmlReporter({
baseDirectory: 'D:/My Work/Protractor/Financial/protractor-result', // a location to store screen shots.
docTitle: 'Protractor Demo Reporter',
docName: 'protractor-demo-tests-report.html'
});
exports.config = {
framework: 'jasmine',
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['invoice.js'],
capabilities: {
browserName: 'chrome',
},
jasmineNodeOpts: {
showColors: true, // Use colors in the command line report.
},
onPrepare: function() {
jasmine.getEnv().addReporter(reporter);
}
}
I tried run this using command protractor conf.js and there's no folder generated containing test results. If I use command, protractor specs\configurations.js following error occurs.
ERROR - failed loading configuration file specs/conf.js
C:\Users\Manuli\AppData\Roaming\npm\node_modules\protractor\lib\configParser.js:
204
throw e;
^
Error: Cannot find module 'D:\My Work\Protractor\Financial\specs\conf.js'
at Function.Module._resolveFilename (module.js:339:15)
at Function.Module._load (module.js:290:25)
at Module.require (module.js:367:17)
at require (internal/module.js:16:19)
at ConfigParser.addFileConfig (C:\Users\Manuli\AppData\Roaming\npm\node_modu
les\protractor\lib\configParser.js:195:22)
at Object.init (C:\Users\Manuli\AppData\Roaming\npm\node_modules\protractor\
lib\launcher.js:103:18)
at Object.<anonymous> (C:\Users\Manuli\AppData\Roaming\npm\node_modules\prot
ractor\lib\cli.js:140:23)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
Why can't I generate reports?
Thanks in advance. :)

I changesd my conf.js as this.
var HtmlScreenshotReporter = require('protractor-jasmine2-screenshot-reporter');
var reporter = new HtmlScreenshotReporter({
dest: 'D:/My Work/Protractor/Financial/screenshots',
filename: 'my-report.html'
});
exports.config = {
framework: 'jasmine',
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['invoice.js'],
capabilities: {
browserName: 'chrome',
},
// Setup the report before any tests start
beforeLaunch: function() {
return new Promise(function(resolve){
reporter.beforeLaunch(resolve);
});
},
// Assign the test reporter to each running instance
onPrepare: function() {
jasmine.getEnv().addReporter(reporter);
},
// Close the report after all tests finish
afterLaunch: function(exitCode) {
return new Promise(function(resolve){
reporter.afterLaunch(resolve.bind(this, exitCode));
});
}
}
Then I used npm install protractor-jasmine2-screenshot-reporter --save-dev command to install npm.
Working now. :)

Related

How to lint a typescript types file?

are there any ways to lint or otherwise debug a types file?
I have a index.d.ts file of all my types, but it seems to crash my app at startup.
using tsc with some basic options works fine
using tslint works fine.
but when running with the webpack compiler I get the following error.
the file contents are a lot but basically like the below.
I had some issues with exporting enums before but basically not getting any actual errors I can understand.
// we SEND to Boto
export enum MsgTypeOut {
TEXT = 0,
IMAGE = 1,
URL_LINK = 2,
FILE = 3,
}
export interface BotoTextMsg {
chatId: string
messageType: MsgTypeOut.TEXT
token?: string
payload: {
text: string
}
}
nodemon:watch early exit on watch, still watching (1) +14s
/Users/dc/dev/tix/recobot/stack/backend/server.js:2663
throw new Error("Module build failed: Error: Typescript emitted no output for /Users/dc/dev/tix/recobot/stack/shared/typezoo/index.d.ts.\n at successLoader (/Users/dc/dev/tix/recobot/stack/backend/node_modules/ts-loader/dist/index.js:47:15)\n at Object.loader (/Users/dc/dev/tix/recobot/stack/backend/node_modules/ts-loader/dist/index.js:29:12)");
^
Error: Module build failed: Error: Typescript emitted no output for /Users/dc/dev/tix/recobot/stack/shared/typezoo/index.d.ts.
at successLoader (/Users/dc/dev/tix/recobot/stack/backend/node_modules/ts-loader/dist/index.js:47:15)
at Object.loader (/Users/dc/dev/tix/recobot/stack/backend/node_modules/ts-loader/dist/index.js:29:12)
at Object.__awaiter (/Users/dc/dev/tix/recobot/stack/backend/server.js:2663:7)
at __webpack_require__ (/Users/dc/dev/tix/recobot/stack/backend/server.js:20:30)
at Object.defineProperty.value (/Users/dc/dev/tix/recobot/stack/backend/server.js:2551:19)
at __webpack_require__ (/Users/dc/dev/tix/recobot/stack/backend/server.js:20:30)
at Object.__awaiter (/Users/dc/dev/tix/recobot/stack/backend/server.js:867:16)
at __webpack_require__ (/Users/dc/dev/tix/recobot/stack/backend/server.js:20:30)
at Object.<anonymous> (/Users/dc/dev/tix/recobot/stack/backend/server.js:1306:18)
at Object.<anonymous> (/Users/dc/dev/tix/recobot/stack/backend/server.js:1343:30)
at __webpack_require__ (/Users/dc/dev/tix/recobot/stack/backend/server.js:20:30)
at Object.__awaiter (/Users/dc/dev/tix/recobot/stack/backend/server.js:1028:15)
at __webpack_require__ (/Users/dc/dev/tix/recobot/stack/backend/server.js:20:30)
at Object.defineProperty.value (/Users/dc/dev/tix/recobot/stack/backend/server.js:63:18)
at Object.<anonymous> (/Users/dc/dev/tix/recobot/stack/backend/server.js:66:10)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
[nodemon] app crashed - waiting for file changes before starting...
webpack config is pretty much vanilla based on create-react-app.
const fs = require("fs")
// const path = require("path")
const NodemonPlugin = require("nodemon-webpack-plugin");
const nodeModules = {};
fs.readdirSync("node_modules")
.filter(function (x) {
return [".bin"].indexOf(x) === -1;
})
.forEach(function (mod) {
nodeModules[mod] = "commonjs " + mod;
});
module.exports = {
entry: "./server/server.ts",
output: {
filename: "server.js",
// path: path.join(__dirname, "/build"),
},
externals: nodeModules,
// needed to fix https://github.com/webpack/webpack/issues/1599
node: {
__dirname: true
},
module: {
loaders: [
{
loader: "ts-loader",
test: /\.tsx?$/,
},
],
},
plugins: [new NodemonPlugin()],
resolve: {
extensions: [".webpack.js", ".web.js", ".ts", ".tsx", ".js"],
},
target: "node",
};
For anyone watching, the error is related to importing enums.
You can export an enum from a types.d.ts file... but it won't import and blows up in this weird way.
https://lukasbehal.com/2017-05-22-enums-in-declaration-files/
How to refer to Typescript enum in d.ts file, when using AMD?

Failed loading config.ts due to import protractor

I am trying to start a new protractor project to test an angular site. I installed node.js, typescript, protractor globally and jasmine. I go to the project folder and do webdriver-manager update. Then I do webdriver-manager start. I also build the config.ts using tsc config.ts. Everything works fine until i try protractor config.ts. Here i will provide my config.ts and my package.json.
{
"name": "protractortests",
"version": "1.0.0",
"description": "Automated tests for a game platform",
"main": "index.js",
"dependencies": {
"#types/jasmine": "^3.3.12",
"#types/node": "^12.0.2",
"jasmine": "^3.4.0",
"protractor": "^5.4.2"
},
"devDependencies": {},
"scripts": {
"test": "protractor config.ts"
}
and my config.ts:
import { ProtractorBrowser, Config } from "protractor";
export let config: Config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
capabilities: {
'browserName': 'chrome'
},
framework: 'jasmine',
specs: ['./FirstSpec.ts'],
jasmineNodeOpts: {
defaultTimeoutInterval: 90000
},
onPrepare: () => {
let globals = require('protractor/built');
let browser = globals.browser;
browser.manage().window().maximize();
browser.manage().timeouts().implicitlyWait(5000);
}
}
E/configParser - Error code: 105
[11:40:53] E/configParser - Error message: failed loading configuration file config.ts
[11:40:53] E/configParser - C:\Users\Victor\Documents\ProtractorTests\config.ts:1
(function (exports, require, module, __filename, __dirname) { import { ProtractorBrowser, Config } from "protractor";
^
SyntaxError: Unexpected token {
at new Script (vm.js:80:7)
at createScript (vm.js:274:10)
at Object.runInThisContext (vm.js:326:10)
at Module._compile (internal/modules/cjs/loader.js:664:28)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
at Module.load (internal/modules/cjs/loader.js:600:32)
at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
at Function.Module._load (internal/modules/cjs/loader.js:531:3)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
npm ERR! Test failed. See above for more details.
By referring to example at link https://github.com/angular/protractor/tree/5.4.1/exampleTypescript
You don't need to import ProtractorBrowser. You can work with browser directly with object Browser.
Commenters pointed out that you can't give Protractor a config file in native Typescript, and need to compile it to config.js then pass that. There's really no point in writing the file in Typescript at all, it just adds an extra step that provides no value to you. If you want editor autocomplete, you can decorate your JS with type annotations:
const { join } = require("path");
const { register } = require("ts-node");
const { SpecReporter, StacktraceOption } = require("jasmine-spec-reporter");
/** #type {import("protractor").Config} */
const config = {
directConnect: true,
baseUrl: "http://localhost:8080",
framework: "jasmine",
noGlobals: true,
specs: [ "./src/**/*.e2e.ts" ],
onPrepare() {
register({
project: join(__dirname, "./tsconfig.json")
});
jasmine.getEnv().addReporter(new SpecReporter({
spec: {
displayStacktrace: StacktraceOption.PRETTY
}
}));
}
};
module.exports = { config };
I adapted my config from this excellent example.

How do i re-write this gulpfile.js in gulp version 4.0

My goal is to automatically push files when edited with the help of gulp by executing "clasp push" on the terminal on my behalf.
I got this error when I wrote the following in gulpfile.js
const gulp = require("gulp");
const exec = require("child_process");
gulp.task('push', function () {
exec("clasp push")
});
gulp.task('watch', function () {
gulp.watch([
'**/* .js',
"**/* .html"
], ['push'])
});
gulp.task('default', ['watch']);
The Error:
Task function must be specified
at Gulp.set [as _setTask] (/Users/micklo/Desktop/AppsScriptProjects/AppsScriptAppName/node_modules/undertaker/lib/set-task.js:10:3)
at Gulp.task (/Users/micklo/Desktop/AppsScriptProjects/AppsScriptAppName/node_modules/undertaker/lib/task.js:13:8)
at Object.<anonymous> (/Users/micklo/Desktop/AppsScriptProjects/AppsScriptAppName/gulpfile.js:15:6)
at Module._compile (internal/modules/cjs/loader.js:701:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
at Module.load (internal/modules/cjs/loader.js:600:32)
at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
at Function.Module._load (internal/modules/cjs/loader.js:531:3)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
Then I realized I am using Gulp Version 4.0.0
Then I changed the code to the one below: compatible with Gulp V 4.0.0
const gulp = require("gulp");
const exec = require("child_process");
gulp.task('push', gulp.series('', function(){
exec("clasp push")
}));
gulp.task('watch', gulp.series('push',function () {
gulp.watch([
'**/* .js',
"**/* .html"
])
}));
gulp.task('default', gulp.series('watch', function(){
gulp.watch([
'**/* .js',
"**/* .html"
]);
}));
But then I still got this error:
assert.js:350
throw err;
^
AssertionError [ERR_ASSERTION]: Task never defined:
at getFunction (/Users/micklo/Desktop/AppsScriptProjects/AppsScriptAppName/node_modules/undertaker/lib/helpers/normalizeArgs.js:15:5)
at map (/Users/micklo/Desktop/AppsScriptProjects/AppsScriptAppName/node_modules/arr-map/index.js:20:14)
at normalizeArgs (/Users/micklo/Desktop/AppsScriptProjects/AppsScriptAppName/node_modules/undertaker/lib/helpers/normalizeArgs.js:22:10)
at Gulp.series (/Users/micklo/Desktop/AppsScriptProjects/AppsScriptAppName/node_modules/undertaker/lib/series.js:13:14)
at Object.<anonymous> (/Users/micklo/Desktop/AppsScriptProjects/AppsScriptAppName/gulpfile.js:4:24)
at Module._compile (internal/modules/cjs/loader.js:701:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
at Module.load (internal/modules/cjs/loader.js:600:32)
at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
at Function.Module._load (internal/modules/cjs/loader.js:531:3)
What am i doing wrong?
Some info:
OS: Mac Os (Mojave)
Gulp Versions -> CLI version: 2.1.0, Local version: 4.0.0
Node: v10.15.3
Clasp: 2.1.0
The quick fix to that particular error is that you have called gulp.series on an empty/non-existant task in your push task. gulp.series is expecting either a list of strings corresponding to tasks you've declared (such as push, watch, and default) or task functions.
Getting rid of the the '' task in the series will fix it:
gulp.task('push', gulp.series(function(){
exec('clasp push')
}));
However you now have some other problems:
None of your tasks have callbacks. Each Gulp task is asynchronous so you either have to use callbacks or return a stream/promise/event emitter/child process/observable (examples of which are located in the docs here). As an example:
gulp.task('push', function(done){
exec('clasp push', function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
done(err);
});
});
You're not passing in a function or series/parallel sequence to gulp.watch so it's not doing anything. If you're trying to run the push task whenever any .js or .html files are changed, you will want to change it to:
gulp.task('watch', function(done) {
gulp.watch([
'**/*.js',
'**/*.html'
], gulp.series('push'));
done();
});
Your glob patterns have an extra space in the watch command before the file extension: '**/*.js' instead of '**/* .js'
You likely want require("child_process").exec (with the extra .exec tagged on) to allow you to execute shell commands using an exec(command) syntax.
You don't need to repeat the watch command when calling it in the default task:
gulp.task('default', gulp.series('push', 'watch'));
You can remove a lot of the gulp.series calls to remove the <anonymous> task calls and simplify the tasks. Each task only needs one function and you should probably aim to use gulp.series and gulp.parallel with sets of named tasks.
Changing those points, the code should look something like:
const gulp = require('gulp');
const exec = require('child_process').exec;
gulp.task('push', function(done){
exec('clasp push', function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
done(err);
});
});
gulp.task('watch', function(done) {
gulp.watch([
'**/*.js',
'**/*.html'
], gulp.series('push'));
done();
});
gulp.task('default', gulp.series('push', 'watch'));
You can rewrite this using the gulp v4 recommended pattern of exporting tasks:
const { series, watch } = require('gulp');
const { exec } = require('child_process');
function push(done) {
exec('clasp push', function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
done(err);
});
}
function watchPush() {
return watch(['**/*.js', '**/*.html'], push);
}
exports.push = push;
exports.default = exports.watch = series(push, watchPush);
For re-write this gulpfile.js in gulp version 4.0 Please updated your
gulpfile.js according to your requirement.
this solution for assert.js:350 throw err; Bootstarp 4, SASS, gulp 4.
////////////////////////////////////////////////////////////////////////////////
var gulp = require('gulp');
var browserSync = require('browser-sync').create();
var sass = require('gulp-sass');
// Compile sass into CSS & auto-inject into browsers
gulp.task('sass', function() {
return gulp.src(['node_modules/bootstrap/scss/bootstrap.scss',
'src/scss/*.scss'])
.pipe(sass())
.pipe(gulp.dest("src/css"))
.pipe(browserSync.stream());
});
// Move the javascript files into our /src/js folder
gulp.task('js', function() {
return gulp.src(['node_modules/bootstrap/dist/js/bootstrap.min.js',
'node_modules/jquery/dist/jquery.min.js',
'node_modules/popper.js/dist/umd/popper.min.js'])
.pipe(gulp.dest("src/js"))
.pipe(browserSync.stream());
});
// Static Server + watching scss/html files
gulp.task('serve', gulp.series('sass', function() {
browserSync.init({
server: "./src"
});
gulp.watch(['node_modules/bootstrap/scss/bootstrap.scss',
'src/scss/*.scss'], gulp.series('sass'));
gulp.watch("src/*.html").on('change', browserSync.reload);
}));
gulp.task('default', gulp.parallel('js','serve'));

SpecReporter is not a constructor error on jasmine

I try to configure simple project on jasmine using node.js. I got following files:
/*global jasmine */
var SpecReporter = require('jasmine-spec-reporter');
exports.config = {
allScriptsTimeout: 11000,
specs: [
'**/*.testdev.ts'
],
capabilities: {
'browserName': 'chrome'
},
directConnect: true,
baseUrl: 'foo',
framework: 'jasmine',
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 60000,
print: function() {}
},
useAllAngular2AppRoots: true,
beforeLaunch: function() {
require('ts-node').register({
project: 'e2e'
});
},
onPrepare: function() {
jasmine.getEnv().addReporter(new SpecReporter());
}
};
Then a test file:
import {} from 'jasmine';
describe ("test", function() {
it ("should work", function() {
console.log('============ Main Workflow file starts');
});
});
And I receive error when I'm running npm test:
C:\newcheckproject>npm test
> newcheck#1.0.0 test C:\\newcheckproject
> protractor
(node:7492) DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead.
[12:47:12] I/launcher - Running 1 instances of WebDriver
[12:47:12] I/direct - Using ChromeDriver directly...
[12:47:15] E/launcher - Error: TypeError: SpecReporter is not a constructor
at onPrepare (C:\Users\OSP\WebstormProjects\newcheckproject\protractor.conf.js:30:38)
at q_1.Promise (C:\Roaming\npm\node_modules\protractor\lib\util.ts:48:39)
at Function.promise (C:\Roaming\npm\node_modules\protractor\node_modules\q\q.js:682:9)
at Object.runFilenameOrFn_ (C:\Roaming\npm\node_modules\protractor\lib\util.ts:39:10)
at plugins_.onPrepare.then (C:\Roaming\npm\node_modules\protractor\lib\runner.ts:103:21)
at _fulfilled (C:\Roaming\npm\node_modules\protractor\node_modules\q\q.js:834:54)
at self.promiseDispatch.done (C:\Roaming\npm\node_modules\protractor\node_modules\q\q.js:863:30)
at Promise.promise.promiseDispatch (C:\Roaming\npm\node_modules\protractor\node_modules\q\q.js:796:13)
at C:\Roaming\npm\node_modules\protractor\node_modules\q\q.js:556:49
at runSingle (C:\Roaming\npm\node_modules\protractor\node_modules\q\q.js:137:13)
[12:47:15] E/launcher - Process exited with error code 100
npm ERR! Test failed. See above for more details.
All answers says that I should replace in the protractor file a line: var SpecReporter = require('jasmine-spec-reporter');, but I do have it. What might also a problem here?
Since 3.0.0, jasmine-spec-reporter module exports SpecReporter and DisplayProcessor.
According to the documentation, you need to configure it like this:
const SpecReporter = require('jasmine-spec-reporter').SpecReporter;
jasmine.getEnv().addReporter(new SpecReporter());

AssertionError: path must be a string

require([
'common',
// Libs
'jquery',
'parse',
'i18n',
// Modules
'modules/login/controllers/login',
'modules/page/controllers/page',
// Styles
'css!../assets/css/bootstrap.min.css',
'css!../assets/css/tablesorter-bootstrap-theme.css',
'css!../assets/css/common.css',
],
function(common, $, Parse, i18n, Login, Page) {
// Defining the application router, you can attach sub routers here.
var Router = Parse.Router.extend({
routes : {
'' : 'index'
},
index : function() {
var currentUser = Parse.User.current(),
view, container;
// Load either login screen or navigation bar,
// depending on the login state of current user.
if(currentUser){
view = new Page.Views.Navbar();
container = '#navbar';
} else {
view = new Login.Views.Login();
container = '#main';
$('#navbar').html(null); // Remove the navbar
}
view.render(function(el) {
$(container).html(el);
});
}
});
$(function() {
// Initialize internationalization
i18n.init({
saveMissing: true,
debug: true,
//preload: ['dk', 'en'],
getAsync: false
});
Parse.initialize('****','****');
// Initialize the Router
var router = new Router();
Parse.history.start({ pushState: false });
});
$(document).on( 'click', 'a:not([data-bypass])', function(evt) {
// Get the anchor href and protcol
var href = $(this).attr('href');
var protocol = this.protocol + '//';
if (href && href.slice(0, protocol.length) !== protocol && href.indexOf('javascript:') !== 0) {
evt.preventDefault();
Parse.history.navigate(href, { trigger: true });
}
});
});
Got error:
assert.js:85
throw new assert.AssertionError({
^
AssertionError: path must be a string
at Module.require (module.js:482:3)
at require (internal/module.js:20:19)
at Object. (/home/historiejagt.portaplay.dk/public_html/app/app.js:4:1)
at Module._compile (module.js:556:32)
at Object.Module._extensions..js (module.js:565:10)
at Module.load (module.js:473:32)
at tryModuleLoad (module.js:432:12)
at Function.Module._load (module.js:424:3)
at Module.runMain (module.js:590:10)
at run (bootstrap_node.js:394:7)
Read the error:
AssertionError: path must be a string
at Module.require (module.js:482:3)
at require (internal/module.js:20:19)
at Object. (/home/historiejagt.portaplay.dk/public_html/app/app.js:4:1)
Look at your code:
require([
An array is not a string.
I think I worked out what's going on, though it would have been a lot easier if someone had been more specific about where they're copy-pasting code from.
The function require(array, callback) is part of RequireJS. NodeJS doesn't use that and has require(string) instead. If you want to use RequireJS in NodeJS you need to install and require requirejs first.

Resources