Here is my protractor conf file
exports.config = {
framework: 'jasmine',
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['../../e2e/smoke-test/*.spec.js'],
ignoreSynchronization: 'true',
jasmineNodeOpts: {
defaultTimeoutInterval: 2500000,
allScriptsTimeout: 25000000
}
};
Here is my gulp conf file
'use strict';
var path = require('path');
var gulp = require('gulp');
// Protractor configurations to open browser
var protractor = require("gulp-protractor").protractor;
var spawn = require('child_process').spawn;
var browserSync = require('browser-sync');
var $ = require('gulp-load-plugins')();
// Downloads the selenium webdriver
gulp.task('webdriver-update', $.protractor.webdriver_update);
gulp.task('webdriver-standalone', $.protractor.webdriver_standalone);
// Protractor with selenium configuration to open browser
//run webdriver method
function runWebdriver(callback) {
spawn('webdriver-manager', ['start'], {
stdio: 'inherit'
}).once('close', callback);
}
//run protractor configurations method
function runProtractorSeleniumConfig() {
gulp.src('./**/*-page.spec.js')
.pipe(protractor({
configFile: './e2e/conf/smoke-test-conf.js'
}))
.on('error', function (e) {
throw e;
});
}
//execute protractor.config after webdriver is executed
function runWebdriverProtractor(){
// runWebdriver(runWebdriver);
runWebdriver(runProtractorSeleniumConfig);
}
//put them into
gulp.task('e2e:smoke-test', runWebdriverProtractor);
// run on dist
//gulp.task('e2e:dist', ['serve:e2e-dist', 'webdriver-update'], runProtractor);
right now I defined one task for gulp which is
gulp e2e:smoke-test
I runs all specs under smoke-test what can I do if I want to run a single smoke spec file or if I want to run a single spec/test
I solved this by passing an individual file through gulp configuration.
function runProtractorSeleniumConfig(path) {
gulp.src(getFile(path))
.pipe(protractor({
configFile: 'ProtractorConfigFile'
}))
.on('error', function (e) {
throw e;
});
}
function getFile(ext){
if(ext == '--regression'){
return 'RegressionTestCaseFilePath'
}
else{
return 'TestCaseFilePath'
}
}
//execute protractor.config after webdriver is executed
function runWebdriverProtractor(str){
// runWebdriver(runWebdriver);
runWebdriver(runProtractorSeleniumConfig(str));
}
//run smoke test commands configurations
gulp.task('e2e:smoke-test', function(){
runWebdriverProtractor(process.argv[3])
});
now I can run regression/smokde file by simply using this
gulp e2e:smoke-test --smoke
cheers!!
With jasmine2 you can filter tests using a regular expression. Maybe you can add something like #smoke, #regressions to your tests and then only run those ones by passing the grep flag:
describe('Test Spec #smoke', function () {
...
})
and in protractor.conf.js:
exports.config = {
jasmineNodeOpts: {
grep: '#smoke',
}
};
Related
I'm working with Protractor for the first time and I've installed some modules with NPM for protractor, protractor-trx-reporter, jasmine-trx-reporter, and webdriver-manager. Selenium server is running at the default 4444 port, and the tests seem to run fine when I run it locally through command line (opens a browser, test passes).
Everything seems to not give any errors, but I can't find the trx file published by the protractor-trx-reporter. When I run protractor conf.js, the test starts, and the command line output says that it's exporting the trx reporter and setting the output file to ProtractorTestResults.trx but a .trx file doesn't show up anywhere so I suspect it's not publishing a file but not throwing errors.
Any ideas if protractor-trx-reporter hasn't exported a trx file?
Here's what my config and spec files look like (both taken as samples from Protractor and protractor-trx-reporter sites)
//conf.js
exports.config = {
framework: 'jasmine',
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['spec.js'],
onPrepare: function () {
console.log('Adding TRX reporter');
require('protractor-trx-reporter');
jasmine.getEnv().addReporter(new jasmine.TrxReporter('ProtractorTestResults.trx'));
}
}
//spec.js
describe('angularjs homepage todo list', function() {
it('should add a todo', function() {
browser.get('https://angularjs.org');
element(by.model('todoList.todoText')).sendKeys('write first protractor test');
element(by.css('[value="add"]')).click();
var todoList = element.all(by.repeater('todo in todoList.todos'));
expect(todoList.count()).toEqual(3);
expect(todoList.get(2).getText()).toEqual('write first protractor test');
// You wrote your first test, cross it off the list
todoList.get(2).element(by.css('input')).click();
var completedAmount = element.all(by.css('.done-true'));
expect(completedAmount.count()).toEqual(2);
});
});
I ended up using jasmine-trx-reporter, here's what the conf.js looked like:
// conf.js
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
directConnect: true,
specs: ['spec.js'],
capabilities: {
'browserName': 'chrome'
},
onPrepare: function () {
var trx = require('jasmine-trx-reporter');
return browser.getCapabilities().then(function (caps) {
var browserName = caps.get('browserName').toUpperCase();
var jasmineTrxConfig = {
reportName: 'Protractor Test Results',
folder: 'testResults',
outputFile: 'Test.trx',
browser: browserName,
groupSuitesIntoSingleFile: false
};
jasmine.getEnv().addReporter(new trx(jasmineTrxConfig));
});
}
};
I think this may be the answer:
"...short term we will not add support for Jasmine 2.0. Later on maybe
yes, but I can't promise you a date."
So that's upsetting. I'm having the same problem. And jasmine-trx-reporter isn't working for me either.
Source: [https://github.com/hatchteam/protractor-trx-reporter/issues/2]
I'm consistently getting the following error when running Protractor end to end UI tests on Jenkins. (OS on the boxes are CentOS 6.7). Firefox browser is used. Xvfb server is started before the build.
Error: Timeout - Async callback was not invoked within timeout by jasmine.DEFAULT_TIMEOUT_INTERVAL.
The same tests consistently pass locally on Windows 10 machine with Firefox 38. I deliberately chose 10-15 already stabilized tests to fix this but no luck. From the logs it seems like the tests go through with every assertion successfully and hang after that.
I use 'done' param in every test and call it after assertion to finish the test. Here is an example of a single test in one of my 2 specs:
page.getWaitForRows(function () {
expect(browser.getCurrentUrl()).toContain(HISOTRY_PATH);
commons.verifyElementDisplayed(commonPage.getNewNumberMenuItem());
commonPage.clickNumberMenuItem().then(function () {
commonPage.clickOnOrderMenuLabel();
commons.waitForUrlToChangeTo(new RegExp(ORDER_MENU)).then(function () {
done();
});
});
});
The time of running is 100 seconds for most of them.
Here is most of my config file (ignoreSynchronization=true is used since synchronization fails for our Angular app because it uses $timeout):
exports.config = {
allScriptsTimeout: 30000,
getPageTimeout: 30000,
troubleshoot: true,
capabilities: {
'browserName': 'firefox'
},
baseUrl: 'http://admin.localhost:9002',
framework: 'jasmine2',
jasmineNodeOpts: {
defaultTimeoutInterval: 50000,
showColors: true
},
onPrepare: function () {
browser.ignoreSynchronization = true;
browser.driver.manage().window().maximize();
var disableNgAnimate = function () {
angular.module('disableNgAnimate', []).run(['$animate', function ($animate) {
$animate.enabled(false);
}]);
};
browser.addMockModule('disableNgAnimate', disableNgAnimate);
var HtmlScreenshotReporter = require('protractor-jasmine2-screenshot-reporter');
jasmine.getEnv().addReporter(new HtmlScreenshotReporter({
captureOnlyFailedSpecs: true,
filename: 'failure-report.html',
dest: '.test-results/html',
pathBuilder: function (currentSpec, suites, browserCapabilities) {
return 'chrome/' + currentSpec.fullName;
}
}));
var jasmineReporters = require('jasmine-reporters');
return browser.getProcessedConfig().then(function (config) {
var cap = config.capabilities;
var prePendStr = cap.browserName.toUpperCase() + '-';
if (cap.version) {
prePendStr += 'v' + cap.version + '-';
}
var junitReporter = new jasmineReporters.JUnitXmlReporter({
consolidateAll: false,
savePath: '.test-results/protractor',
modifySuiteName: function (generatedSuiteName, suite) {
return generatedSuiteName;
}
});
jasmine.getEnv().addReporter(junitReporter);
});
Please note that synchronization is enabled for some time later in the tests to do the log in, but after that it is once again set to false. Here is the beforeAll method for my tests:
beforeAll(function (done) {
commons.loginAndChooseAccount().then(function () {
browser.ignoreSynchronization = true;
done();
});
});
What I tried:
Connecting directly to Firefox using directConnect: true,
Updating protractor version to 3.1.1
Specifically setting
browser.ignoreSynchronization to "true" in each 'it' test or in
'beforeEach'
and a lot other stuff.
Nothing worked. Each 'it' in the 2 specs I run fail with this error. And there are consistently 0 failures locally for the same tests. I tried switching to Chrome but is does not officially support CentOS 6.7 so I'm stuck with Firefox and have been battling with this issue for more than a week now. Will appreciate any help greatly!
I tried all variations mentioned in this Q&A:
first one
element(by.css('[ng-click="vm.openNewPage()"]')).click().then(function () {
expect(element(by.css('[ng-click="vm.submitButtonOfThatPage()"]')).isPresent()).toBe(true);
});
second one
element(by.css('[ng-click="vm.openNewPage()"]'));
browser.waitForAngular();
expect(element(by.css('[ng-click="vm.submitButtonOfThatPage()"]')).isPresent()).toBe(true);
third one:
element(by.css('[ng-click="vm.openNewPage()"]'));
browser.sleep(1)
browser.waitForAngular();
expect(element(by.css('[ng-click="vm.submitButtonOfThatPage()"]')).isPresent()).toBe(true);
none of them passes test: Expected false to be true.
except this one with browser.sleep(1000)
element(by.css('[ng-click="vm.openNewPage()"]'));
browser.sleep(1000)
expect(element(by.css('[ng-click="vm.submitButtonOfThatPage()"]')).isPresent()).toBe(true);
Putting some seconds for sleep time is obviously not a solution.
What am I missing or what should I do to evaluate test successfully
Protractor version is: Version 2.1.0 with Jasmine2 framework
This is my command to start test:
C:\projects\eucngts\e2e\app>protractor conf.js --baseUrl=http://localhost:56225/euc/
And these are my relevant codes:
// conf.js
exports.config = {
directConnect: true,
seleniumAddress: 'http://localhost:4444/wd/hub',
framework: 'jasmine2',
specs: [
'./views/account/loginSpec.js'
,'./views/inStudents/inStudentsSpec.js'
]
}
//Spec File
describe('Testing Students Page', function () {
var inStudents: InStudents = require('./inStudents.js');
var defs: Defs = require('../defs.js');
it('should check cell 2 2 ', function () {
inStudents.createNewInStudent()
});
});
//Testing file
class InStudents {
createNewInStudent() {
element(by.css('[ng-click="vm.openNewPage()"]'));
browser.sleep(1000)
expect(element(by.css('[ng-click="vm.submitButtonOfThatPage()"]')).isPresent()).toBe(true);
}
}
module.exports = new InStudents();
Instead of a browser.sleep() delay, make it explicit with browser.wait() and wait for the element to become present:
var submitButton = element(by.css('[ng-click="vm.submitButtonOfThatPage()"]'));
var EC = protractor.ExpectedConditions;
browser.wait(EC.presenceOf(submitButton), 5000);
I'm testing an Ionic application. When the app is run in the browser, the console does show that cordova.js is missing - which is right, but it doesn't break the application.
As long as I run my tests with a single browser instance, the missing files does not cause my tests to fail. Here is my configuration and spec files:
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
framework: 'jasmine2',
suites: {
test: 'e2e/test.spec.js'
},
allScriptsTimeout: 60000,
capabilities: {
'browserName': 'chrome',
'chromeOptions': {
binary: '/Applications/Google\ Chrome\ Stable.app/Contents/MacOS/Google\ Chrome',
args: [],
extensions: [],
}
},
onPrepare: function() {
browser.driver.get('http://localhost:8100');
}
};
Here is the test file:
describe('First test', function(){
it('just verifies that everything loads correctly', function() {
expect(1).toEqual(1);
});
});
The above works without errors. But opening a second browser instance causes a fail:
describe('First test', function(){
var browser2 = browser.forkNewDriverInstance();
browser2.get('http://localhost:8100');
var element2 = browser2.element;
it('just verifies that everything loads correctly', function() {
expect(1).toEqual(1);
});
});
With the error message:
/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/atoms/error.js:113
var template = new Error(this.message);
^
UnknownError: unknown error: cordova is not defined
I am using gulp to compile my typescript files and create the output.js file.
Is it possible to have a single task which compiles typescript file and concatenates it with angular libraries?
Here's what my current file looks like (below). First it's running a typescript task which creates the output.js file and then it runs a scripts task which concats the script plugin files and output.js.
'use strict';
var gulp = require('gulp')
var paths = {
distScriptsDir: '../../Themes/mastter/Scripts',
srcScriptsPlugins: [
'node_modules/jquery/dist/jquery.min.js',
'node_modules/angular/angular.min.js',
'node_modules/angular-route/angular-route.min.js',
'node_modules/angular-translate/dist/angular-translate.min.js',
'node_modules/angular-translate/dist/angular-translate-loader-url/angular-translate-loader-url.min.js',
'node_modules/angular-bootstrap/dist/ui-bootstrap-tpls.js',
'Scripts/angular-sticky.min.js',
'Scripts/dragme.js',
'Scripts/jasny-bootstrap.min.js',
'node_modules/lodash/dist/lodash.min.js',
'node_modules/angular-google-maps/dist/angular-google-maps.min.js'
],
srcScriptsFile: [
'output.js'
]
};
//typescript
gulp.task('typescript', function () {
var ts = require('gulp-typescript');
var tsResult = gulp.src( 'all.ts')
.pipe(ts({
noImplicitAny: true,
out: 'output.js'
}));
return tsResult.js.pipe(gulp.dest(''));
});
// scripts task
gulp.task('scripts', function () {
var concat = require('gulp-concat'),
plumber = require('gulp-plumber'),
uglify = require('gulp-uglify');
return gulp.src(paths.srcScriptsPlugins.concat(paths.srcScriptsFile))
.pipe(plumber({
errorHandler: function (e) {
console.log(e.toString());
this.emit('end');
}
}))
// .pipe(uglify())
.pipe(concat('main.js'))
.pipe(gulp.dest(paths.distScriptsDir));
});
// default task
gulp.task('default', [
'typescript',
'scripts'
]);
I use a watch tasks for this that has a bunch of gulp.watch inside it. One for watching the .ts change and run the typescript compiler that will output a js file in whatever location and another gulp.watch that watches the .js files and run script task. In that case, things will get automated by the watch and you don't have to combine the task into one task.
gulp.task('watch', function() {
gulp.watch(['dir/*.ts','otherdir/*.ts',...], ['typescript']);
gulp.watch(['dir/*.js','otherdir/*.js',...], ['scripts']); //make sure to include the .ts result folder...
});
try run-sequence. Below is a simple example.
gulp.task('task1', function(callback) {
setTimeout(function() {
console.log('task1 is done');
callback()
}, 1000);
});
gulp.task('task2', function(callback) {
setTimeout(function() {
console.log('task2 is done');
callback()
}, 2000);
});
gulp.task('tk12', function(callback) {
return runSequence('task1', 'task2', callback);
});