How to get nightwatchjs screenshots working? - selenium-webdriver

I am trying to generate a screenshot with nightwatch js , it saves a file to my location but the size is 1kb and when I try to open this there is no image. The config file is the one I got from https://www.npmjs.com/package/learn-nightwatch.
What could be the culprit?

Before you launch the screenshot, you need to be sure that the page is "ready". If you already checked that, please make sure that you added an image extension to the file name.
I'm sharing a working example:
module.exports = {
"Do a screenshot task" : function (browser) {
browser
.url("http://example.com")
.waitForElementPresent('body', 1000, 'Page loaded')
.resizeWindow(900, 3000)
.saveScreenshot('/home/yourName/path/imageName.png')
.end();
}
};
Hope it helps you.

As it stands this is how you can set up automatic screenshots in nightwatch.conf.js
"screenshots": {
"enabled": true,
"path": "./tests_output/screenshots", // location to save
"on_failure": true,
"on_error": true
}

Related

Mozilla addon loading too late to block a resource

I'm trying to cancel requests from studio.code.org to www.google.com/jsapi to help page loads go faster. In my locale, google is blocked, but the browser waits for 75 seconds before giving up. I'd like to prevent the delay by blocking the request (and the page seems to work fine without jsapi).
I followed the example from https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/webRequest/onBeforeRequest, installed the addon. I included a console.log statement to see that my code is called, but it only shows up after the browser waits another 75 seconds trying to load the resource that I hoped to block.
I'm open to other approaches if this isn't going to work.
manifest.json:
{
"manifest_version": 2,
"name": "cancel-google",
"version": "1.0",
"permissions": [
"webRequest",
"webRequestBlocking"
],
"content_scripts": [
{
"matches": ["https://studio.code.org/*"],
"js": ["cancel-google.js"]
}
]
}
cancel-google.js:
// match pattern for the URLs to block
var pattern = "*www.google.com/jsapi";
console.log("cancelator script loaded");
// cancel function returns an object
// which contains a property `cancel` set to `true`
function cancel(requestDetails) {
console.log("Cancelling: " + requestDetails.url);
return {cancel: true};
}
// add the listener,
// passing the filter argument and "blocking"
browser.webRequest.onBeforeRequest.addListener(
cancel,
{urls: [pattern]},
["blocking"]
);
cancel-google.js should be loaded as a background script, which is true for most of the WebExtension APIs.
{
"name": "Your Addon",
"manifest_version": 2,
"background": {
"scripts": ["cancel-google.js"]
}
}
Then it should work.
Smile4ever's answer is correct but I found some other issues with my original code.
First - the 'timing' issue of my original content-script was a red herring. Although the original content script will write to the log of the page, it has no effect on loading resources. The same script, as a background script, will not write anything (that I have noticed) into the console log, but it will work.
Second - the background script needs more permissions than I had originally (more than are described in the mozilla.org link).
"permissions": [
"http://*/*",
"https://*/*",
"webRequest",
"webRequestBlocking" ]
The above permissions are adequate/excessive; you can also replace "http(s)://*/*" with the actual urls of the pages requesting the resource and the resource to be blocked.

SAPUI5 FIORI launchpad customIcon on BusyDialog is not working

I am tring to add animation to a busyDialog , i can see it well in my development environment but not on FIORI launchpad.
see attached code.
can anyone think why it's not working?
Thanks!
sap.ui.getCore().AppContext._oWaitDialog = new sap.m.BusyDialog({
// text: "Please wait...",
customIcon: "images/LogoLoader_WhiteCircle.gif",
customIconRotationSpeed:0
});
sap.ui.getCore().AppContext._oWaitDialog.open();
you have to include this folder in component.js file, component.js initializes all these folders when app run from Launchpad.return UIComponent.extend("com.yourapp.namspace.Component", {
metadata : {
manifest: "json", /* if you using manifest json file */
includes: ["css/style.css", "images/LogoLoader_WhiteCircle.gif"] /* all folders file that need to be accessed in app, css in case custom css*/
},
I would say you are trying to get UI5 source of an old or local source in index.html
Try
src="https://sapui5.hana.ondemand.com/1.50.6/resources/sap-ui-core.js"

How to change kik bot config?

It seems like after initial config POST request I can't change any properties (webhook and features), what is the way to change those? is this a temporary bug? :)
{
"webhook": "http://example.com/api/kik",
"features": {}
}
what I get
{
"webhook": "http://example.com/incoming",
"features": {
"receiveReadReceipts": false,
"receiveIsTyping": false,
"manuallySendReadReceipts": false,
"receiveDeliveryReceipts": false
}
}
The python library has a set_configuration function, that if called with a Config object with just a webhook set, will set the webhook. See http://kik.readthedocs.org/en/latest/user.html#configuration, though there’s a bug in those docs right now, the seconds function is set_configuration
If you aren't using that library can you show me what code you are using. Blank out your bot-name and api-key

Cordova + Sencha Touch: Delete file after it has been used

So I'm using Cordova + Sencha Touch for an app and Antair's SQLitePlugin (https://github.com/Antair/Cordova-SQLitePlugin) to import and use an SQLite database in it.
I managed to import my (kinda big) prepopulated database using Antair's importPrepopulatedDatabase ( window.sqlitePlugin.importPrepopulatedDatabase({file:"mydb.db",importIfExists:false}) ) method and it works just fine. The thing is I noticed the app is using twice the size it really needs as it keeps the file after importing it.
I checked and the app works just fine if I delete the file from /cordova/www/db and build again, it keeps the actual db in the app's filesystem I guess, but I can't find a way to programmatically delete that file after it has been imported.
I looked around and found cordova file plugin (https://github.com/apache/cordova-plugin-file/blob/master/doc/index.md), but from what I saw from the docs it only grants read permissions on the www folder, so that won't do it.
Does anyone have any workaround for this? I could really use that extra space.
By using cordova file plugin api you can do this,
please refer this :
deleteFile: function(fileName) {
var that = this;
if (!fileName) {
console.error("No fileName specified. File could not be deleted.");
return false;
}
window.requestFileSystem(LocalFileSystem.TEMPORARY, 0, function(fileSystem){ // this returns the tmp folder
// File found
fileSystem.root.getFile(fileName, {create: false}, function(fileEntry){
fileEntry.remove(function(success){
console.log(success);
}, function(error){
console.error("deletion failed: " + error);
});
}, that.get('fail'));
}, this.get('fail'));
}

How to UPLOAD a file into my JS application?

I am working on extjs 4.2 application. Trying to create a menu toolbar where I can add and delete files. For example:
When I press Open, I want to see the file browser window. And when I finish choosing the file and click "open", I will see something like this:
I know that I need to use onItemClick() function to open the browser. But I have no idea how to call that window. Also how can you program so only certain file extensions can be chosen.
I am guessing that once you press "open" on the file browser window, the file tree in the left panel will dynamically add that file. But have no idea how can I connect "open" to my tree.
Just to clarify - this is going to be user based app, it is not going to be a webapp. This will be opened in user's browser and that is it. No need to get some info from server or send something to client.
EDIT: I have been able to solve the part where you click on Open the file browser dialog pops up. Then when I select a file and press "open", it displays a message box with file's name.
Here is the code for that part:
var item = Ext.create('Ext.form.field.File', {
buttonOnly: true,
buttonText: 'Open',
hideLabel: true,
listeners: {
'change': function(fb, v){
Ext.Msg.alert('Status', v);
}
}
});
var mainmenu = Ext.create('Ext.menu.Menu', {
width: 200,
margin: '0 0 10 0',
items: [item]
});
Now the problem is that I need to get the FULL PATH of the file. This message only shows file's name. Any help?
Using files on the web can be tricky, so you're going to have to be patient, diligent, and be prepared for some self-learning.
A. If you want to be compatible with all browsers, you need to upload the file to a server, and have the server return info about the file. Or you can try Sencha Desktop Packager, flash, or signed Java Applets.
If you are okay with only modern browsers, you will need to read and learn the HTML5 File API. Here's a start:
https://developer.mozilla.org/en-US/docs/Web/API/FileReader?redirectlocale=en-US&redirectslug=DOM%2FFileReader
B. Start with a filefield button for now, and add it as a menuitem later, just to keep things simple. You will want to listen to the filefield's change event if you want to read the file.
C. To restrict file types (only modern browsers allow this), you'll need to do something like this (audio/* is just an example):
{
xtype:'filefield',
listeners:{
afterrender:function(cmp){
cmp.fileInputEl.set({
accept:'audio/*'
});
}
}
}
D. After you get the file, you will want to add it's info to the tree's TreeStore.

Resources