I have encountered an issue when trying to execute two spec files for Angular.js. The problem arises when I attempt to run both files consecutively - the browser initially opens for angular.js, then switches to angularCal.js without executing angular.js at all. I also tried using 'src/test/*.js' and suites, but encountered the same issue. Interestingly, when I executed the spec files separately, they worked fine.
// Configuration
import { Config, browser } from 'protractor';
import { testConfig, platform } from 'protractor-html-reporter-2'
let HtmlScreenshotReporter = require('protractor-html-reporter-2');
let jasmineReporters = require('jasmine-reporters');
let reportsDirectory = './reports';
let dashboardReportDirectory = reportsDirectory + '/dashboardReport';
// Example configuration file
exports.config = {
directConnect: true,
capabilities: {
browserName: 'chrome'
},
specs: ['src/test/angularCal.js'],
jasmineNodeOpts: {
showColors: true,
}, onPrepare: function () {
// xml report generated for dashboard
browser.manage().timeouts().implicitlyWait(5000);
jasmine.getEnv().addReporter(new jasmineReporters.JUnitXmlReporter({
consolidateAll: true,
savePath: reportsDirectory + '/xml',
filePrefix: 'xmlOutput'
}));
var fs = require('fs-extra');
if (!fs.existsSync(dashboardReportDirectory)) {
fs.mkdirSync(dashboardReportDirectory);
}
jasmine.getEnv().addReporter({
specDone: function (result) {
if (result.status == 'failed') {
browser.getCapabilities().then(function (caps) {
var browserName = caps.get('browserName');
browser.takeScreenshot().then(function (png) {
var stream = fs.createWriteStream(dashboardReportDirectory + '/' + browserName + '-' + result.fullName + '.png');
stream.write(new Buffer(png, 'base64'));
stream.end();
});
});
} else if (result.status == 'passed') {
browser.getCapabilities().then(function (caps) {
var browserName = caps.get('browserName');
browser.takeScreenshot().then(function (png) {
var stream = fs.createWriteStream(dashboardReportDirectory + '/' + browserName + '-' + result.fullName + '.png');
stream.write(new Buffer(png, 'base64'));
stream.end();
});
});
}
}
});
},
onComplete: function () {
var browserName, browserVersion;
var capsPromise = browser.getCapabilities();
capsPromise.then(function (caps) {
browserName = caps.get('browserName');
browserVersion = caps.get('version');
var HTMLReport = require('protractor-html-reporter-2');
let testConfig = {
reportTitle: 'Protractor Test Execution Report',
outputPath: dashboardReportDirectory,
outputFilename: 'index',
screenshotPath: './',
testBrowser: browserName,
browserVersion: browserVersion,
modifiedSuiteName: false,
screenshotsOnlyOnFailure: false,
};
new HTMLReport().from(reportsDirectory + '/xml/xmlOutput.xml', testConfig);
});
},
};
//angular.js =spec 1
import { browser, by, element } from "protractor";
import { BaseTest } from "../common/BaseTest";
import { angularsite } from "../pageobjects/angular_site";
describe('Angular site', function () {
let base = new BaseTest()
browser.get("https://material.angular.io/components/autocomplete/overview")
let ang = new angularsite();
it('Scroll down', function () {
ang.scrollSettingSeparate();
})
it('Select Text (Alert)', function () {
ang.autocom(2, 2);
})
it('Checkbox', function () {
ang.checkboxtab();
ang.clickcheckbox();
})
it('DatePicker', function () {
ang.clickdatetab();
ang.clickdatemenu();
ang.clickcurrentdate()
})
it('Radiobutton', function () {
ang.clickradiobuttontab();
ang.clickradiobutton();
})
it('Slider', function () {
ang.clickslidertab()
ang.clicksliderop(3, 2, 3, 3)
})
it('Switch Alert', function () {
browser.get("http://www.way2automation.com/angularjs-protractor/banking/#/manager/addCust")
ang.alert(2)
})
it('Switch windows', function () {
browser.ignoreSynchronization = true;
browser.get("https://skpatro.github.io/demo/links/")
ang.switch_windows()
})
})
angularCal.js = spec2
import { browser, element, by } from "protractor";
import { BaseTest } from "../common/BaseTest";
import { datatable } from "../pageobjects/table_data";
import { calculator } from "../pageobjects/calculator_page";
describe('Calculator Page', function () {
let base = new BaseTest()
let calcu = new calculator();
beforeEach(function() {
calcu.clear_num1()
calcu.clear_num2()
});
afterEach(function() {
calcu.clear_num1()
calcu.clear_num2()
});
browser.get(base.StartTest(1))
it('Validate Calculator Page Addition feature', function () {
calcu.enter_num1(2)
calcu.addition_Operator()
calcu.enter_num2(3)
calcu.click_Button();
calcu.validate_OutPut(4);
})
it('Validate Calculator Page Subtraction feature', function () {
calcu.enter_num1(2)
calcu.subtract_Operator()
calcu.enter_num2(3)
calcu.click_Button();
calcu.validate_OutPut(5);
})
it('Validate Calculator Page Multiplication', function () {
calcu.enter_num1(11)
calcu.multi_Operator()
calcu.enter_num2(12)
calcu.click_Button();
calcu.validate_OutPut(4);
})
it('Validate Calculator Page Division', function(){
calcu.enter_num1(2)
calcu.division_Operator()
calcu.enter_num2(3)
calcu.click_Button();
calcu.validate_OutPut(7);
})
it('Validate Calculator Page Modulo', function(){
calcu.enter_num1(2)
calcu.modulo_Operator()
calcu.enter_num2(3)
calcu.click_Button();
calcu.validate_OutPut(8);
})
it('Get Table data', function () {
let table = new datatable()
table.get_dataTable();
})
})