Unable to auto-push newly generating scripts in the custom folder - protractor

Instead of custom-folder, the json data is still populated under allure-results
onPrepare: function () {
var AllureReporter = require('jasmine-allure-reporter');
jasmine.getEnv().addReporter(new AllureReporter({
allureReport : {
resultsDir : 'custom-folder'
}
}));
};

can you try using absolute path and check whether you can able to generate the reports in custom path.
onPrepare: function () {
var AllureReporter = require('jasmine-allure-reporter');
var path = require('path');
jasmine.getEnv().addReporter(new AllureReporter({
allureReport : {
resultsDir : path.resolve("./") + '/custom-folder'
}
}));
};

Related

Suggestion popup doesnt appear for multi input control

I have dynamically attached live search event for my Multi Input control (please refer the below code). Even after attaching the .bindAggregation function for suggestionItems, the suggestion popup doesn't appear.
onAfterRendering: function(oEvent){
var that = this;
var oFacetFilters = sap.ui.getCore().byId
("xyzID").getContent()[0].getContent();
var oCapTreeFilter = oFacetFilters[6].getContent()[1];
oCapTreeFilter.attachLiveChange(function(oEvt){
//build filter array
var aFilter = [];
var sQuery = oEvt.getParameter("value");
if (sQuery) {
aFilter.push(new sap.ui.model.Filter("RootID",
sap.ui.model.FilterOperator.Contains, sQuery));
}
that.oModel.read("/RootName", {
async : false,
filters : aFilter,
success : function(oData, response){
var oJSONModel = new sap.ui.model.json.JSONModel();
oJSONModel.setData(oData);
oCapTreeFilter.setModel(oJSONModel);
oCapTreeFilter.bindAggregation("suggestionItems",{
path: "/results",
template: new sap.ui.core.Item({text: "{RootID}"})
});
},
error : function(response){
sap.m.MessageBox.show("Error occurred");
}
});
});

Uploading a file using the File Uploader module

I am trying to upload a file using the FileUploader module in SAPUI5. The code I am trying to follow is from a blog https://blogs.sap.com/2016/11/08/step-by-step-on-how-to-use-the-sapui5-file-upload-feature/ however the code does not seem to execute the reader.onload function? It gets to reader.readAsDataURL(file) and dose not do anything? I am not sure where the problem lies and how to get it to work? Hekp will be much appreciated, there is a similar issue in the blog response but no help has been given.
XML
<u:FileUploader
id="VRCFileUploader"
value="{VRCFileUpload}"
placeholder="Please Attach document"
fileType="jpg,png,pdf"
style="Emphasized"
useMultipart="false" >
</u:FileUploader>
JS
function upload(evnt) {
var token;
var oView = this.getView();
var oFileUploader = this.byId("VRCFileUploader");
var sFileName = oFileUploader.getValue();
if (sFileName === "") {
sap.m.MessageToast.show("Please select a File to Upload");
return;
}
var file = jQuery.sap.domById(oFileUploader.getId() + "-fu").files[0];
var base64_marker = "data:" + file.type + ";base64,";
var reader = new FileReader();
//on load
reader.onLoad = (function(theFile){
return function(evt) {
//locate base64 content
var base64Index = evt.target.result.indexOf(base64_marker) + base64_marker.lenght;
// get base64 content
var base64 = evt.target.result.substring(base64Index);
var sTasksService = "SOME URL";
var sService2 = "SOME URL";
var oViewModel = oView.getModel();
var oContext = oView.getBindingContext();
var oTask = oViewModel.getProperty(oContext.getPath());
var oDataModel = sap.ui.getCore.getModel();
var sWorkitemId = JSON.stringify(oTask.wiId);
var service_url = sService2;
$.ajaxsetup({
cache: false
});
jQuery.ajax({
url: service_url,
asyn: false,
datatype: "json",
cache: false,
data: base64,
type: "post",
beforeSend: function(xhr) {
xhr.setRequestHeader("x-csrf-Token", token);
xhr.setRequestHeader("content-Type", file.type);
xhr.setRequestHeader("slug", sFileName);
xhr.setRequestHeader("WorkitemId", oTask.WiId);
},
success: function(odata) {
sap.m.MessageToast.show("file successfully uploaded");
oFileUploader.setValue("");
},
error: function(odata) {
sap.m.MessageToast.show("file Upload error");
}
});
};
})(file);
//Read file
reader.readAsDataURL(file);
}
In reply to Vortex:
Why is there an IIFE on the method being used on the onLoad Property?
Try to do somenthing like this:
reader.onload = event => {
let fileAsDataUrl = event.target.result;
....
};

Protractor-Jasmine2-HTML-Report

I am working on report execution part in Protractor and using Jasmine2 Html Reporter. I am able to generate a report but when my test passes completely without any failure still report shows status as 0.00%. I am not sure why this is happening. I am also attaching the snap shot for the reference.
The code is :
var HtmlReporter = require('protractor-jasmine2-html-reporter');
var reporter = new HtmlReporter({
plugins: [{
package: 'jasmine2-protractor-utils',
showSummary: true,
reportTitle: "Clinicare Report",
filename: 'Clinicarereport.html',
disableHTMLReport: false,//disableHTMLReport
disableScreenshot: false,
captureOnlyFailedSpecs: true,
screenshotPath:'./reports/screenshots',
screenshotOnExpectFailure:true,
screenshotOnSpecFailure:true,
dest: 'protractor-reports',
filename: 'protractor-report.html',
takeScreenshots: true,
ignoreSkippedSpecs: true,
takeScreenshotsOnlyOnFailures: true
// screenshotsFolder: 'F:\\Screeshots'
}]
});
exports.config =
{
directconnect: true,
capabilities: {'browserName': 'chrome'},
framework: 'jasmine',
specs: ['example1.js'],
jasmineNodeOpts: {
defaultTimeoutInterval: 300000
},
onPrepare: function() {
// Add a screenshot reporter and store screenshots to `/tmp/screenshots`:
jasmine.getEnv().addReporter(reporter);
}
}
The spec code is:
var Excel = require('exceljs');
var XLSX = require('xlsx');
var os = require('os');
var TEMP_DIR = os.tmpdir();
var wrkbook = new Excel.Workbook();
describe('Open the clinicare website by logging into the site', function () {
it('Should Add a text in username and password fields and hit login button', function () {
console.log("hello6");
var wb = XLSX.readFile('E:\\Demo\\Generate a test report\\Data_Login.xlsx');
var ws = wb.Sheets.Sheet1;
var json = XLSX.utils.sheet_to_json(wb.Sheets.Sheet1);
console.log("json", json);
//var json = XLSX.utils.sheet_to_json(wb.Sheets.Sheet1);
//console.log("json", json);
for(var a = 0; a < json.length ; a++){
console.log("Test_URL", json[a].Test_URL);
console.log("User_Name", json[a].User_Name);
console.log("Password", json[a].Password);
browser.get(json[a].Test_URL);
//Perform Login:UserName
element(by.model('accessCode')).sendKeys(json[a].User_Name);
//Perform Login:Password
element(by.model('password')).sendKeys(json[a].Password);
//Perform Login:LoginButton
element(by.css('.btn.btn-primary.pull-right')).click();
//Clicking on New Tab
element(by.xpath('/html/body/div[3]/div[1]/div[17]/div/div/table[2]/thead/tr/th[1]/i')).click();
//Clicking on Image for Logout
element(by.css('.user-auth-img.img-circle')).click();
browser.driver.sleep(2000)
//Clicking on LogOut Button
element(by.xpath('/html/body/div[3]/div[1]/div[16]/div[1]/div/div[2]/nav/div[2]/ul/li[4]/ul/li[5]/a/span')).click();
browser.driver.sleep(2000)
//Clicking on Ok for confirmation
element(by.id('logout')).click();
console.log(json[a].User_Name + "Passed the Test");
};
})
});
Try with below spec file it's working fine.
Results you can see
describe("basic test", function () {
beforeAll(function () {
console.log('beforeAll');
});
beforeEach(function () {
console.log('beforeEach');
});
afterAll(function () {
console.log('afterAll');
});
afterEach(function () {
console.log('afterEach');
});
it("Test Case 1: to verify see the global functions hierarchy", function () {
console.log('Sample Test 1');
});
it("Test Case 2: to verify see the global functions hierarchy", function () {
browser.get('http://www.angularjs.org');
element(by.model('todoText')).sendKeys('write a protractor test');
element(by.css('[value="add"]')).click();
var todoList = element.all(by.repeater('todo in todos'));
expect(todoList.count()).toEqual(3);
});
it('should greet the named user', function() {
browser.get('http://www.angularjs.org');
element(by.model('yourName')).sendKeys('Julie');
var greeting = element(by.binding('yourName'));
expect(greeting.getText()).toEqual('Hello Julie!');
});
});

Unable to use page objects in my spec file in protractor

//This is my AngularPage.cs page object file
var AngularPage= function()
{
var nameInput= element(by.model('yourName'));
var greeting = element(by.binding('yourName'));
this.get=function()
{
browser.get('http://www.angularjs.org');
};
this.setName= function(name)
{
nameInput.sendKeys(name);
};
this.getGreeting= function()
{
return greeting.getText();`
};
};
module.exports = new AngularPage();
//This is my AngularHome_spec.js file
var angularPage = require('./AngularPage.js');
describe('angularjs homepage',function()
{
var angular_page;
beforeEach(function()
{
angular_page= new AngularPage();
});
it('greetings for new user', function()
{
// var angular_page= new AngularPage();
angular_page.get();
angular_page.setName('Rahul');
expect(angular_page.getGreeting()).toEqual('Hello Rahul!');
}
);
}
);
//I am unable to use page objects in my spec file as it is throwing an error
:AngularPage is not defined
In your code, object has been created twice. First time on page "AngularPage.js" and second time on spec "AngularHome_spec.js" level.
Do following on page "AngularHome_spec.js"
module.exports = AngularPage;
Change the
var AngularPage = require('./AngularPage.js');//Capital the 'A'

shardTestFiles not working with gulp

I am using gulp wrapper for protractor for my tests. ShardTestFiles option specified below in my main protractor protractor file (under multicapabilities) is not working. My browser is still running as only 1 instance and my tests are still taking same amount of time.
I am using protractor version 4.0.9.
Below is how my conf file inside project folder is set-up.
var ProtractorConfig = require('../../ProtractorConfig');
exports.config = new ProtractorConfig({
suites: {test: ['./spec/**/censusCat*.spec.js']},
siteName: '',
isAngular: true,
params: require('./params'),
allScriptsTimeout: 25000,
jasmineNodeOpts: {
defaultTimeoutInterval: 500000,
}
});
This is how my main protractor file is set-up:
'use strict';
require('dotenv').load();
var _ = require('lodash');
var path = require('path');
function ProtractorConfig(options, isMobile) {
// Protractor options
this.seleniumAddress = process.env.SELENIUM_ADDRESS;
this.multiCapabilities = [{
browserName: 'chrome',
maxInstances : 2,
shardTestFiles: true,
}];
this.framework = 'jasmine2';
this.params = require('./params');
this.jasmineNodeOpts = {print: function() {}};
this.plugins = [{path: '../../plugins/protractor-extensions/index.js'}];
this.onPrepare = function() {
var siteName = this.siteName || '';
var isAngular = this.isAngular;
if (isAngular) {
browser.ignoreSynchronization = false;
} else {
browser.ignoreSynchronization = true;
}
browser.resize(1280, 1040);
// Set up globally available objects
global._ = _;
global.params = browser.params;
global.EC = protractor.ExpectedConditions;
browser.params.baseUrl = '';
}.bind(this);
_.merge(this, options);
}
module.exports = ProtractorConfig;
Below is how my gulp file is structured:
var env = require('envalid');
var gulp = require('gulp');
var path = require('path');
var util = require('gulp-util');
var simpleCommand = require('simple-command');
var binPath = './node_modules/.bin/';
gulp.task('test', function(cb) {
testSite('sites/' + util.env.site, cb);
});
gulp.task('default', ['test']);
function runModule(name, params, cb) {
new simpleCommand(path.join(binPath, name), params, process.cwd()).run(cb);
}
function runProtractor(params, cb) {
runModule('protractor', params, cb);
}
function testSite(site, cb) {
var params = [
site + '/protractor.conf.js','--suite=test', '--params.siteName=registry.ngccoin.com'
];
runProtractor(params, function(err) {
cb();
});
}
Can someone please suggest why my shardTestFiles option is not working?