Getting Error message "RegistrationPO is not a constructor" on log using Protractor - angularjs

When i am executing my spec file(given below) ,I am getting the error message "RegistrationPO is not a constructor" ,Plz help me to solve my query.Thanks in advance.
//Registration_spec//
'use strict';
var FunLib = require('/Users/acer/AppData/Roaming/npm/node_modules/protractor/FFAutomation/Function_Lib.js'); //Write the location of your javascript file
var RegistrationPO = require('/Users/acer/AppData/Roaming/npm/node_modules/protractor/FFAutomation/Registration_PO.js'); //Write the location of your javascript file
var testData = require('./FFtestdata_Dev_p.json');
describe('Registration: ', function() {
var FuncLib;
var Registration;
var URL;
var EC = protractor.ExpectedConditions;
FuncLib = new FunLib();
Registration = new RegistrationPO();
beforeEach(function () {
browser.ignoreSynchronization = true;
});
//Scenario 1: Open browser :working
it('1-Open the web browser',function(){
browser.ignoreSynchronization = true;
browser.get('Http://dev.forfirm.com:3000');
browser.sleep(200000);
});
});

var FunLib = require('/Users/acer/AppData/Roaming/npm/node_modules/protractor/FFAutomation/Function_Lib.js'); //Write the location of your javascript file
var RegistrationPO = require('/Users/acer/AppData/Roaming/npm/node_modules/protractor/FFAutomation/Registration_PO.js'); //Write the location of your javascript file
Why do you trying to find your pageObjects in node_modules/protractor?
With this you will lose everything on every node_modules reinstall.
I believe this is the reason why you getting errors - you cant import, because file does not exist there
Create more plain structure, something like
node_modules/...all your dependencies will be installed here
utils/Function_Lib.js
pageobjects/Registration_PO.js
specs/registration.spec.js
package.json
protractor.config.js
Then your imports in specs/registration.spec.js will be something like this:
var FunLib = require('../utils/Function_Lib.js');
var RegistrationPO = require('../pageobjects/Registration_PO.js');
Also check what you are exporting in Registration_PO.js and Function_Lib.js

Related

My gulp.js file is only running the first time and then it won't watch

I made a gulp.js file that is meant to be observing my changes and rebuilding so that my react code can update after the scss gets converted to css with each change. Here's what I have:
'use strict';
//dependencies
var gulp = require('gulp');
var sass = require('gulp-sass');
var minifyCSS = require('gulp-clean-css');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var changed = require('gulp-changed');
//////////////
// - SCSS/CSS
//////////////
var SCSS_SRC = './src/assets/scss/**/*.scss';
var SCSS_DEST = './src/assets/css';
// Compile SCSS
gulp.task('compile_scss', function(){
gulp.src(SCSS_SRC)
.pipe(sass().on('error', sass.logError))
.pipe(minifyCSS())
.pipe(rename({ suffix: '.min'}))
.pipe(changed(SCSS_DEST))
.pipe(gulp.dest(SCSS_DEST));
});
//detect changes in SCSS
gulp.task('watch_scss', function(){
gulp.watch(SCSS_SRC, gulp.series('compile_scss'));
});
//Run tasks
gulp.task('default', gulp.series(['watch_scss'], function(){
}));
This is the first time I do this but from what I can tell it is correct. There's no error being thrown and it works sometimes. However, when I make 2 changes to my default.scss file, the 1st one gets converted to css but for the second one I need kill the task and run gulp again. What might I be missing?

Splitting all.js into multiple files - Angular JS

I have been working on an Angular JS based application. I have written a set of gulp commands to uglify/remove comments from JS code. When I run the web application and monitor the network traffic, I noticed that minified(uglified) 'all.js' file consumes quite a lot of time to be loaded (please forget about the caching).
I believe that splitting the all.js file (before or after processing) in to several pieces (let's say four pieces) will improve the application loading time. Please mention if you think there is/are better way(s).
Still I am struggling to find a way to get an approach to above mentioned method under #1. Still no luck :-( Please advice me.
Gulpfile
// include plug-ins
'use strict';
var gulp = require('gulp');
var concat = require('gulp-concat');
var htmlbuild = require('gulp-htmlbuild');
var plugins = require('gulp-load-plugins')();
var es = require('event-stream');
var clean = require('gulp-clean');
var uglify = require('gulp-uglify');
var strip = require('gulp-strip-comments');
var pump = require('pump');
// pipe a glob stream into this and receive a gulp file stream
var gulpSrc = function (opts) {
var paths = es.through();
var files = es.through();
paths.pipe(es.writeArray(function (err, srcs) {
var fixedFiles = [];
for (var i=0; i < srcs.length; i++)
{
fixedFiles[i] = srcs[i].replace("~", ".");
console.log(fixedFiles[i]);
}
gulp.src(fixedFiles, opts).pipe(files);
}));
return es.duplex(paths, files);
};
var jsBuild = es.pipeline(
plugins.concat('all.js'),
gulp.dest('./Scripts/')
);
gulp.task('clean', function () {
return pump(gulp.src('./Scripts/all.js')
.pipe(clean({ force: true })));
});

How do I wait until an element is visible with Protractor when Angular is not available?

I have a login function that I'm using for a Protractor test, it looks like this:
var config = require("../helpers/config.js");
var login = function() {
browser.driver.get(config.dsp.url);
browser.driver.findElement(by.name("userName")).sendKeys(config.dsp.user);
browser.driver.findElement(by.name("password")).sendKeys(config.dsp.password);
return browser.driver.findElement(by.name("submit")).click().then(function() {
return browser.driver.wait(function() {
return browser.driver.isElementPresent(browser.driver.findElement(by.className("sample-class-name")));
}, 360000);
});
}
module.exports = login;
I can't use any of the protractor specific hooks because Angular is not used on this page, so I have to use the underlying webdriver API. The problem is, I can't seem to figure out how to wait until an element is visible using this wrapped webdriver object. Any help would be appreciated.
Try with the expected conditions from the underlying driver:
var config = require("../helpers/config.js");
var until = require('selenium-webdriver').until;
var login = function() {
var driver = browser.driver;
driver.get(config.dsp.url);
driver.findElement(by.name("userName")).sendKeys(config.dsp.user);
driver.findElement(by.name("password")).sendKeys(config.dsp.password);
driver.findElement(by.name("submit")).click();
return driver.wait(until.elementLocated(by.css(".sample-class-name")), 10000)
.then(e => driver.wait(until.elementIsVisible(e)), 10000);
}
module.exports = login;

Can an "it" block be called multiple times in different spec files using Page Objects

I am fairly new to Protractor and Page Objects. I am trying to get the header to show across multiple pages. I have a header_page.js and a header_spec.js. I can verify that the header is present once within the header_spec.js (which is presently only pointing to the home page). What I would like to do is call the test for the header each time I visit a page.
var HomePage = require('../pages/home_page.js');
var HeaderPage = require('../pages/header_page.js');
describe('When visiting a page'. function(){
var headerPage = new HeaderPage();
var inbox_page = new HomePage();
beforeEach(function () {
inbox_page.visit();
});
it('header menu selector should be present', function(){
header_menu = headerPage.hdr_menu;
header_menu.click();
expect('header_menu').not.toBe(null);
});
});
});
I am not sure how to call this test from page2_spec.js..page3_spec.js as each page is different but should all contain a header. I am trying to avoid code duplication and would like to avoid calling the "it" block from each page. Do I use a helper file or can I move the it block inside the header_page.js..currently looks like this:
module.exports = function(){
this.hdr_menu = element(by.css('#pick-group-btn'));
this.hdr_img = element(by.css('PeopleAdmin logo'));
}
you can call a test spec to other specs by wrapping your spec in a function and exporting it "requiring" that module So in your case you can export header_spec.js to other modules such as page2_spec.js or page3_spec.js by :
var HomePage = require('../pages/home_page.js');
var HeaderPage = require('../pages/header_page.js');
var commHeader = function(){
describe('When visiting a page'. function(){
var headerPage = new HeaderPage();
var inbox_page = new HomePage();
beforeEach(function () {
inbox_page.visit();
});
it('header menu selector should be present', function(){
header_menu = headerPage.hdr_menu;
header_menu.click();
expect('header_menu').not.toBe(null);
});
});
});
}
module.exports = commHeader;
Then in you page2_spec.js file you can import this module like this :
var commHeader = require('your path to spec/commHeader.js');
describe('When visiting page 2 validate Header first'. function(){
var headerTest = new commHeader();
headerTest.commHeader();
it('page 2 element validations', function(){
//here the page 2 test goes
});
});
});

Testing Backbone with JSDOM

I'm trying to figure out how to test backbone using jsdom and nodeunit as the testing framework.
I've got the error: "Error: Calling node's require("text") failed with error: Error: Cannot find module 'text'"
What means, that the context was not able to load requirejs-text plugin.
I've created the DOM context witn:
var assert = require('assert');
var fs = require('fs');
var index_html = fs.readFileSync(__dirname + '/../static/index.html', 'utf-8');
var requirejs = require('requirejs');
var jsdom = require('jsdom');
// require('amdefine/intercept');
var jQuery = require('jquery');
On the test setUp, on trying to open up the backbone view:
exports.setUp = function(callback){
var document = jsdom.jsdom(index_html);
var window = document.parentWindow;
jsdom.getVirtualConsole(window).sendTo(console);
requirejs.config({
baseUrl: __dirname + '/',
packages: [{
name: 'text',
location: '../node_modules/requirejs-text/text.js ',
main: 'text.js'
},
],
});
requirejs([__dirname + '/../lib/views/stackoverflow.js'], function(bb){
callback();
});
};
The exception is raised on before the callback is called. The view that I'm using is just a regular view using requirejs-text to load the template. I've also created a GitHub Repository just to better explain the issue. Just clone it, enter the project dir and type make. It should reproduce all the steps that I've did.
Thanks in advance!

Resources