How to test in SAPUI5 with OPA5 if a dialog is successfully closed? (Negative testing) - sapui5

I wonder how to test with OPA5 if a Dialog is successfully closed after pressing the corresponding button.
This is how I test if the dialog is open:
{
// ...
iShouldSeeTheSortDialog: function () {
return this.waitFor({
controlType: "sap.m.ViewSettingsDialog",
id: "sortDialog",
fragmentId: "sortFragment",
success: function () {
Opa5.assert.ok(true, "The sort dialog is open");
},
errorMessage: "Did not find the sort dialog control"
});
},
}
Now I'm looking for the exact opposite test case. I would like to search for the sortDialog and throw a success if it is not found anymore.
Could you please suggest a solution?

I found the answer myself, maybe it will be helpful for someone else.
If you want to check if a dialog has been closed but not destroyed, you can do it this way:
{
//..
iShouldNotSeeDialog: function () {
return this.waitFor({
id: "dialogID",
visible: false,
success: function (oDialog) {
Opa5.assert.notOk(oDialog.getVisible(), "Dialog is not visible -- OK");
},
errorMessage: "Checking Field: dialogID -- Assertion Failed"
});
}
}
If you want to check if a dialog has been destroyed, you can do this as follows:
{
//..
iShouldNotSeeDialog: function () {
return this.waitFor({
success: function () {
var bExists = (Opa5.getJQuery()("#" + "dialogID").length > 0);
Opa5.assert.notOk(bExists, "Dialog doesn't exist -- OK");
},
errorMessage: "-- Assertion Failed"
});
}
}

Related

How to add custom logs in Protractor test reports

I'm trying to add some custom logs to my protractor test report. I've app log file in my project folder which has the logs captured using log4js. I want these log entries to be shown in my test report as well. Currently I'm using chercher report. Since I'm a beginner to protractor, I'm not sure how to do this. Can anybody help me on this? Thanks in advance!
spec.js
fdescribe('Protractor Perfecto Demo', function () {
it('should pass test', function () {
browser.reportingClient.stepStart('Step 1: Navigate Google');
browser.driver.get('https://www.google.com'); //Navigate to google.com
browser.reportingClient.stepEnd();
//Locate the search box element and insert text
//Click on search button
browser.reportingClient.stepStart('Step 2: Send Keys');
browser.driver.findElement(by.name('q')).sendKeys('PerfectoCode GitHub');
browser.reportingClient.stepEnd();
browser.reportingClient.stepStart('Step 3: Click');
browser.driver.findElement(by.css('#tsbb > div')).click();
browser.reportingClient.stepEnd();
});
//This test should fail
it('should fail test', function () {
browser.reportingClient.stepStart('Step 1: Navigate Google');
browser.driver.get('https://www.google.com'); //Navigate to google.com
browser.reportingClient.stepEnd();
//Locate the search box element and insert text
//Click on search button
browser.reportingClient.stepStart('Step 2: Send Keys');
browser.driver.findElement(by.name('q')).sendKeys('PerfectoCode GitHub');
browser.reportingClient.stepEnd();
browser.reportingClient.stepStart('Step 3: Click');
browser.driver.findElement(by.css('#tsbbbsdasd > div')).click();
browser.reportingClient.stepEnd();
});
afterAll(function(done){
process.nextTick(done);
});
});
conf.js
var reportingClient;
exports.config = {
//Remote address
// seleniumAddress: 'https://MY_HOST.perfectomobile.com/nexperience/perfectomobile/wd/hub',
directConnect: true,
//Capabilities to be passed to the webdriver instance.
capabilities: {
browserName: 'chrome'
// user: 'MY_USER',
// password: 'MY_PASS',
// platformName: 'Android',
//deviceName: '123456',
},
//Framework to use. Jasmine is recommended.
framework: 'jasmine',
// Spec patterns are relative to the current working directly when
// protractor is called.
specs: ['./tests/SignupAutomation_spec.js'],
// Options to be passed to Jasmine.
jasmineNodeOpts: {
showColors: true, // Use colors in the command line report.
defaultTimeoutInterval: 120000 // Time to wait in ms before a test fails. Default value = 30000
},
onComplete: function () {
// Output report URL
return reportingClient.getReportUrl().then(
function (url) {
console.log(`Report url = ${url}`);
}
);
},
onPrepare: function () {
const Reporting = require('perfecto-reporting');
reportingClient = new Reporting.Perfecto.PerfectoReportingClient(new Reporting.Perfecto.PerfectoExecutionContext({
webdriver: browser.driver,
tags: ['javascript driver']
}));
browser.reportingClient = reportingClient;
var myReporter = {
specStarted: function (result) {
reportingClient.testStart(result.fullName);
},
specDone: function (result) {
if (result.status === 'failed') {
const failure = result.failedExpectations[result.failedExpectations.length - 1];
reportingClient.testStop({
status: Reporting.Constants.results.failed,
message: `${failure.message} ${failure.stack}`
});
} else {
reportingClient.testStop({
status: Reporting.Constants.results.passed
});
}
}
}
jasmine.getEnv().addReporter(myReporter);
}
}
While running this I'm getting below error:
An error was thrown in an afterAll
AfterAll JavascriptError: javascript error: end is not defined
(Session info: chrome=90.0.4430.212)
(Driver info: chromedriver=90.0.4430.24 (4c6d850f087da467d926e8eddb76550aed655991-refs/branch-heads/4430#{#429}),platform=Windows NT 10.0.19042 x86_64)

Getting an ' instance.requestPaymentMethod is not a function' in Braintree's sample

I'm getting an instance.requestpaymentmethod is not a function when I was just following along the tutorial for custom-field integration found here:
https://developers.braintreepayments.com/start/tutorial-hosted-fields-node
The error happens when I click on the "Pay" button.
Did anyone solve this problem? My assumption is that the code isn't updated or the script sources changed somewhat. If anyone from Braintree can actually help, that'll be great.
Thanks!
Full disclosure: I work at Braintree. If you have any further questions, feel free to contact support.
I took a look at the example code snippet in the guide you shared and I was able to find the culprit. First off, the error you're getting is expected as the requestPaymentMethod method actually belongs to our Drop-In UI solution and the Hosted Fields JS library doesn't have such module. I informed our Documentation team to get that code example updated.
That being said, you can find a working example in our Hosted Fields guide. If you check the function (hostedFieldsErr, hostedFieldsInstance) callback function, you'll see that the payment nonce is created by the tokenize function of the hostedFieldsInstance.
I also ran into this issue today. Use the following code in <script> tag. It will work for you.
var form = document.querySelector('#hosted-fields-form');
var submit = document.querySelector('input[type="submit"]');
braintree.client.create({
authorization: '<YOUR_TOKENIZATION_KEY>'
}, function (clientErr, clientInstance) {
if (clientErr) {
console.error(clientErr);
return;
}
braintree.hostedFields.create({
client: clientInstance,
styles: {
'input': {
'font-size': '14px'
},
'input.invalid': {
'color': 'red'
},
'input.valid': {
'color': 'green'
}
},
fields: {
number: {
selector: '#card-number',
placeholder: '4111 1111 1111 1111'
},
cvv: {
selector: '#cvv',
placeholder: '123'
},
expirationDate: {
selector: '#expiration-date',
placeholder: '10/2019'
}
}
}, function (hostedFieldsErr, hostedFieldsInstance) {
if (hostedFieldsErr) {
console.error(hostedFieldsErr);
return;
}
form.addEventListener('submit', function (event) {
event.preventDefault();
hostedFieldsInstance.tokenize(function (tokenizeErr, payload) {
if (tokenizeErr) {
console.error(tokenizeErr);
return;
}
console.log('Got a nonce: ' + payload.nonce);
$.ajax({
type: 'POST',
url: '<YOUR_API_URL>',
data: { 'paymentMethodNonce': payload.nonce }
}).done(function (result) {
hostedFieldsInstance.teardown(function (teardownErr) {
if (teardownErr) {
console.error('Could not tear down Drop-in UI!');
} else {
console.info('Drop-in UI has been torn down!');
$('#submit-button').remove();
}
});
if (result.success) {
$('#checkout-message').html('<h1>Success</h1><p>Your Drop-in UI is working! Check your sandbox Control Panel for your test transactions.</p><p>Refresh to try another transaction.</p>');
} else {
console.log(result);
$('#checkout-message').html('<h1>Error</h1><p>Check your console.</p>');
}
});
});
}, false);
});
});

"NoSuchSessionError" encountered when running multiple scenarios using protractor+cucumber

I am getting this error:
NoSuchSessionError: This driver instance does not have a valid session ID (did you call WebDriver.quit()?) and may no longer be used.
In my test, I want to run multiple scenarios in one step file. I have read some questions/answers that I have to re-initialize my elements in step file.
When I try to run my code, I can see that the first scenario is performed and passed. But in my second scenario, I am not able to continue logging in to the page and stops after loginPage.get_url();
My feature file:
Scenario: As an admin I should be able to go to reports
Given Admin is in dashboard page
When Admin goes to Income reports
Then Admin should be able to click Download excel
Scenario: As an admin I should be able to log out
Given Admin goes back to dashboard page
When Admin clicks the logout button
Then Admin is now on login page
Here is my step file:
let chai = require('chai');
let chaiAsPromised= require('chai-as-promised');
chai.use(chaiAsPromised);
let expect = chai.expect;
const { Before, After } = require('cucumber');
var { setDefaultTimeout } = require('cucumber');
setDefaultTimeout(60 * 1200);
Given( 'Admin is in dashboard page', function () {
LoginPage.click_dashboard_button();
} );
When( 'Admin goes to Income reports', function () {
navPage.click_reports_dropdown();
browser.sleep(1000);
navPage.click_incomeReports();
} );
Then( 'Admin should be able to click Download excel', function () {
incomeReportsPage.click_downloadExcelButton();
browser.sleep(3000);
} );
Given( 'Admin go backs to dashboard page', function ( ) {
LoginPage.click_dashboard_button();
});
When( 'Admin clicks the logout button', function () {
LoginPage.click_logout_button();
});
Then( 'Admin is now on login page', function () {
browser.driver.getTitle().then( function ( value ) {
expect( value ).to.equal( "NAGM | Log in" );
});
});
Here is my Page Object file:
exports.init = function init() {
browser.waitForAngularEnabled( false );
}
exports.get_url = function get_url() {
browser.get( "http://nagm.test.pl/login" );
}
exports.input_username = function input_username() {
usernameTextbox.clear();
usernameTextbox.sendKeys("admin#nagm.ct");
}
exports.input_password = function input_password() {
passwordTextbox.clear();
passwordTextbox.sendKeys("password");
}
exports.click_login_button = function click_login_button() {
loginButton.click();
}
exports.click_logout_button = function click_logout_button() {
logoutButton.click();
}
exports.click_dashboard_button = function click_dashboard_button() {
dashboardMenu.click();
}
My hooks.js:
Before (function (){
browser.manage().window().maximize();
loginPage.init();
loginPage.get_url();
loginPage.input_username();
loginPage.input_password();
loginPage.click_login_button();
});

Office js Dialog api 16.13 Word doesn't open dialog next time

I have following code and it's being triggered form a task pane button:
Office.context.ui.displayDialogAsync(
dialogUrl,
{
width: 60,
height: 60,
requireHTTPS: false,
displayInIframe: false
},
asyncResult => {
dialog = asyncResult.value;
if (asyncResult.status === "failed") {
dispatch(MessageActions.showError(asyncResult.error.message));
dialog.close();
} else {
dialog.addEventHandler(Office.EventType.DialogMessageReceived, arg => {
dispatch({ type: LOADED });
dialog.close();
});
dialog.addEventHandler(Office.EventType.DialogEventReceived, arg => {
if (arg && arg.error === 12006) {
dispatch({ type: LOADED });
}
});
}
}
);
Once I called this snippet I get an error
Error code - 12007 .A dialog box is already opened from the task pane.
A task pane add-in can only have one dialog box open at a time.
but really it's not. For previous versions, it worked just fine. Is there anybody who knows what's happened or I might be doing now something wrong?
This is only reproducible on MacOs 10.13.4 and Word v16.13 (18.05.13). Word for
Windows and Word Online work perfectly.

sapui5 opa5 opa script is not identifying View

I have written an OPA Script but it was not identifying the View id's. Can you please help me to solve this?
OPA Script is not able to enter the text "Testing in Description" in the Text Area Field
My Script is getting failed and im seeing below Error.
There was no Input
Opa timeout
This is what Opa logged:
all results were filtered out by the matchers - skipping the check - sap.ui.test.pipelines.MatcherPipeline
Callstack:
at fillDescription (https://webidetesting7755399-w3446edba.dispatcher.int.sap.hana.ondemand.com/webapp/test/integration/pages/ActivitySet.js?eval:58:19)
at Object.eval (https://webidetesting7755399-w3446edba.dispatcher.int.sap.hana.ondemand.com/webapp/test/integration/AllActivitySets.js?eval:32:30)
Expected:
true
Result:
false
Diff:
trufalse
Below is my Code..
Opa5.extendConfig({
viewName : "test",
arrangements: new Common(),
viewNamespace: "com.tools.melody.activityForm.view.",
autoWait: true
});
opaTest("Enter Description", function (Given, When, Then) {
// Arrangements
//Given.iStartMyApp();
//Actions
When.onTheActivitySetPage.fillDescription();
});
fillDescription: function () {
return this.waitFor({
id:"activityFormDescription",
//controlType: "sap.m.TextArea",
actions: new EnterText({
text: "Testing in Description"
}),
success: function() {
Opa5.assert.ok(true, "Testing in Description");
},
errorMessage: "There was no Input"
});
},
View File ID ::
<TextArea id="activityFormDescription" value="{default>/0/Description}" change="handleChange"></TextArea>
Try to pass viewName parameter to the waitFor function.
fillDescription: function () {
return this.waitFor({
id:"activityFormDescription",
viewName : "test",
actions: new EnterText({
text: "Testing in Description"
}),
success: function() {
Opa5.assert.ok(true, "Testing in Description");
},
errorMessage: "There was no Input"
});
},