Set screen resolution in CapserJS/SlimerJS - casperjs

Im using CasperJS 0.10.1 SlimerJS 1.1.3 Firefox 45 on CentOS 7.2 Im trying to set the window.screen properties as seen by the code below by the screenshot of the website still says 640x480
var casper = require('casper').create({ verbose: true, logLevel: 'debug' });
casper.on('page.initialized', function (page) {
page.evaluate(function () {
(function() {
window.screen = {
width: 1600,
height: 900
};
})
});
});
casper
.start()
.thenOpen('http://www.whatismyscreenresolution.com/')
.wait(5000, function() { this.capture('/cas/_test_screenres.jpg',{top:0,left:0,width:1600,height:900}); })
.run();

You can set the viewport size:
casper.viewport(1600, 900);
Or even more:
function on_init (page){
page.viewportSize = {width:1600,height:900}
page.evaluate(function (){
window.screen = {width:1600,height:900,availWidth:1600,availHeight:900};
window.innerWidth=1600; window.innerHeight=900; window.outerWidth=1600; window.outerHeight=900;
window.navigator = {
plugins: {length: 2, 'Shockwave Flash': {name: 'Shockwave Flash', filename: '/usr/lib/flashplugin-nonfree/libflashplayer.so', description: 'Shockwave Flash 11.2 r202', version: '11.2.202.440'}},
mimeTypes: {length: 2, "application/x-shockwave-flash": {description: "Shockwave Flash", suffixes: "swf", type: "application/x-shockwave-flash", enabledPlugin: {name: 'Shockwave Flash', filename: '/usr/lib/flashplugin-nonfree/libflashplayer.so', description: 'Shockwave Flash 11.2 r202', version: '11.2.202.440'}}},
appCodeName: "Mozilla",
appName: "Netscape",
appVersion: "5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 Safari/537.36",
cookieEnabled: 1,
languages: "en-US,en",
language: "en",
onLine: 1,
doNotTrack: null,
platform: "Linux x86_64",
product: "Gecko",
vendor: "Google Inc.",
vendorSub: "",
productSub: 20030107,
userAgent: "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 Safari/537.36",
geolocation: {getCurrentPosition: function getCurrentPosition(){},watchPosition: function watchPosition(){},clearWatch: function clearWatch(){}},
javaEnabled: function javaEnabled(){return 0} };});};
casper.on('page.initialized', on_init);
it's just simple realization of the navigator object: plugins could look better, but usually it's not needed.

Related

Unable to use Google Play Developer API even after server to server authentication

I am trying to call Purchases.Subscriptions: get from my local server, but I am getting an error message saying Error: Login Required.
I have already created a service account with a role of Project Owner as described here. I then set the GOOGLE_APPLICATION_CREDENTIALS environment variable and made it point to the JSON file that was downloaded as mentioned here.
Lastly, I tried running some example code that was meant for server-to-server authentication based off the website docs example to see if I could authenticate successfully:
import { google } from 'googleapis'
async function main() {
try {
const auth = new google.auth.GoogleAuth({
scopes: ['https://www.googleapis.com/auth/androidpublisher']
})
const authClient = await auth.getClient()
const project = await auth.getProjectId()
const publisher = google.androidpublisher('v3')
const result = await publisher.purchases.subscriptions.get({
packageName: 'com.mywebsite.subdomain',
subscriptionId: 'com.mywebsite.subscription_name',
token: '...my purchase token...'
})
console.log(result)
} catch (error) {
console.error(error)
}
}
main()
I just used the Billing API instead of the Compute API, otherwise my example is the same as the one given in the docs. I am not sure why I am having issues, any help would be appreciated!
Full error:
{ Error: Login Required
at Gaxios.request (/Users/squadri/Desktop/googlenode/node_modules/gaxios/src/gaxios.ts:86:15)
at process._tickCallback (internal/process/next_tick.js:68:7)
response:
{ config:
{ url:
'https://www.googleapis.com/androidpublisher/v3/applications/com.mywebsite.subdomain/purchases/subscriptions/com.mywebsite.subscription_name/tokens/...my%20purchase%20token...',
method: 'GET',
paramsSerializer: [Function],
headers: [Object],
params: [Object: null prototype] {},
validateStatus: [Function],
retry: true,
responseType: 'json',
retryConfig: [Object] },
data: { error: [Object] },
headers:
{ 'alt-svc': 'quic=":443"; ma=2592000; v="46,43,39"',
'cache-control': 'private, max-age=0',
connection: 'close',
'content-encoding': 'gzip',
'content-type': 'application/json; charset=UTF-8',
date: 'Tue, 20 Aug 2019 04:41:29 GMT',
expires: 'Tue, 20 Aug 2019 04:41:29 GMT',
server: 'GSE',
'transfer-encoding': 'chunked',
vary: 'Origin, X-Origin',
'www-authenticate': 'Bearer realm="https://accounts.google.com/"',
'x-content-type-options': 'nosniff',
'x-frame-options': 'SAMEORIGIN',
'x-xss-protection': '1; mode=block' },
status: 401,
statusText: 'Unauthorized' },
config:
{ url:
'https://www.googleapis.com/androidpublisher/v3/applications/com.mywebsite.subdomain/purchases/subscriptions/com.mywebsite.subscription_name/tokens/...my%20purchase%20token...',
method: 'GET',
paramsSerializer: [Function],
headers:
{ 'x-goog-api-client': 'gdcl/3.1.0 gl-node/10.16.1 auth/5.2.0',
'Accept-Encoding': 'gzip',
'User-Agent': 'google-api-nodejs-client/3.1.0 (gzip)',
Accept: 'application/json' },
params: [Object: null prototype] {},
validateStatus: [Function],
retry: true,
responseType: 'json',
retryConfig:
{ currentRetryAttempt: 0,
retry: 3,
retryDelay: 100,
httpMethodsToRetry: [Array],
noResponseRetries: 2,
statusCodesToRetry: [Array] } },
code: 401,
errors:
[ { domain: 'global',
reason: 'required',
message: 'Login Required',
locationType: 'header',
location: 'Authorization' } ] }
Try this code snippet for example.
Print apks list of specific packageName using googleapi, androidpublisher and service account authentication (v3).
const {google} = require('googleapis');
const key = require('./privateKey.json')
const packageName = "com.company.example"
let client = new google.auth.JWT(
key.client_email,
undefined,
key.private_key,
['https://www.googleapis.com/auth/androidpublisher']
)
const androidApi = google.androidpublisher({
version: 'v3',
auth: client
})
async function getApksList() {
let authorize = await client.authorize();
//insert edit
console.log('authorize :', authorize);
let res = await androidApi.edits.insert({
packageName: packageName
})
//get edit id
let editId = res.data.id
const res = await androidApi.edits.apks.list({
editId: editId,
packageName: packageName
});
console.log(`Result ${(JSON.stringify(res))}`);
}
getApksList().catch(console.error);
You need to add your JSON key file to google.auth.GoogleAuth:
const auth = new google.auth.GoogleAuth({
keyFile: process.env.GOOGLE_APPLICATION_CREDENTIALS,
scopes: ['https://www.googleapis.com/auth/androidpublisher']
});
See: https://github.com/googleapis/google-api-nodejs-client/blob/master/samples/jwt.js
You need to pass the auth field (authClient) to google.androidpublisher
const publisher = google.androidpublisher({
version: 'v3',
auth: authClient
})

FullCalendar change color new event

I use fullcalendar and I need to now how to change the color of the new event, to differentiate it from the loaded events into the database. The person who puts the new event, has to difference from others by color.
The calendar uses everyone, no user control and events are stored in a database.
Your question leaves some questions of its own. Do you expect for the color of the new event to be rendered later? or is the color completely disposable and used only for differentiating between a new and old event?
Given the questions though - remember that you can set color is MANY different ways. You can set a static color for all items loaded from the database in your ajax call:
events: {
url: 'php/get-events.php',
error: function() {
$('#ajax-warning').show();
},
color: "yellow"
},
That will set the default color for all the events loaded from JSON.
In the json data itself, you can set the backgroundColor attribute to change the color of an individual item, e.g
{
"id": "999",
"title": "Repeating Event",
"start": "2016-05-09T16:00:00-05:00",
"backgroundColor": "purple"
},
You can set the event color in a form (if that is how you allow a user to create an event)
If you have a set of static events that can be added you can cycle through a list of colors and provide each one in the list with a different background.
--
If this doesn't answer your question, try poviding more information on what you have currently and what you'd like to accomplish.
/* initialize the calendar
-----------------------------------------------------------------*/
$('#calendar').fullCalendar({
events: JSON.parse(json_events),
height:447,
utc: true,
allDaySlot:false,
header: {
left: 'prev,next today',
center: 'title',
right: 'agendaWeek,agendaDay'
},
eventConstraint: {
start: moment().format('YYYY-MM-DD'),
end: '2100-01-01'
},
firstDay: 1,
monthNames: ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'],
monthNamesShort: ['Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul', 'Ago', 'Sep', 'Oct', 'Nov', 'Dic'],
dayNames: ['Domingo', 'Lunes', 'Martes', 'Miercoles',
'Jueves', 'Viernes', 'Sábado'],
dayNamesShort: ['Dom', 'Lun', 'Mar', 'Mie', 'Jue', 'Vie', 'Sab'],
minTime:'09:00:00',
maxTime:'13:30:00',
buttonText: {
today: 'hoy',
month: 'mes',
week: 'semana',
day: 'dia'
},
eventStartEditable: false,
eventTextColor: '#AE413F',
defaultView: 'agendaWeek',
hiddenDays: [6, 0],
editable: true,
droppable:true,
eventDurationEditable:false,
slotDuration: '00:30:00',
defaultEventMinutes: 30,
defaultTimedEventDuration:'00:30:00',
forceEventDuration:true,
eventReceive: function(event){
var title = prompt('Nombre y Apellidos:');
var start = event.start.format("YYYY-MM-DD[T]HH:mm:SS");
var end = event.end.format("YYYY-MM-DD[T]HH:mm:SS");
var antena = 'ANTENA1';
var ssid = 'E18D93D0-B4B2-4802-8D04-CD2154B88A18';
if(title!=null){
$.ajax({
url: 'process.php',
data: 'type=new&title='+title+'&start='+start+'&end='+end+'&antena='+antena+'&SSID='+ssid+'&zone='+zone,
type: 'POST',
dataType: 'json',
success: function(response){
event.title = title;
$('#calendar').fullCalendar('updateEvent',event);
alert("Añadido: Atención NO marcar la casilla inferior si quiere guardar correctamente los datos");
},
error: function(e){
console.log(e.responseText);
if(error='true'){
alert('CITA YA ASIGNADA: Atención NO marcar la casilla inferior si quiere un funcionamiento correcto');
}//location.reload();
}
});}else{
location.reload();}
$('#cafireflendar').fullCalendar('updateEvent',event);
console.log(event);
//location.reload();
},

Error using addInitialFiles Method

I am having an issue trying to use the addInitialFiles method listed here:
http://docs.fineuploader.com/branch/master/api/methods.html#addInitialFiles
I get a javascript error in my chrome dev console that says:
1032:381 Uncaught TypeError: uploader.addInitialFiles is not a function
This is the code I use to initialize Fine Uploader, and make the call the addInitialFiles():
<script type="text/javascript">
$(function () {
var uploader = $('#fine-uploader').fineUploaderS3({
request: {
endpoint: "myfineuploaderbucket.com.s3.amazonaws.com",
accessKey: "XXXXXXXXXXXXXXXXXXXXXXXX",
},
signature: {
endpoint: "/SignatureHandler",
version: 4
},
validation: {
allowedExtensions: ["gif", "jpeg", "jpg", "png", "bmp"],
acceptFiles: "image/gif, image/jpeg, image/png, image/bmp",
sizeLimit: 5000000,
itemLimit: 3
},
retry: {
enableAuto: true
},
deleteFile: {
enabled: true,
endpoint: "/DeleteImage/?id=#Model.Id",
method: 'POST',
},
paste: {
targetElement: $(document),
promptForName: true
},
uploadSuccess: {
endpoint: "/UploadSuccessful/?id=#Model.Id"
},
iframeSupport: { //This path needs to be a blank HTML page and is used for fine-uploader to support IE9 and older
localBlankPagePath: "/Blank"
},
objectProperties: {
acl: "public-read",
key: function (fileId) {
var re = /(?:\.([^.]+))?$/;
fileExt = re.exec($("#fine-uploader").fineUploader("getName", fileId))[0];
uuid = $("#fine-uploader").fineUploader("getUuid", fileId);
filename = uuid + fileExt;
key = "/#ViewBag.Id + "/" + filename;
return key;
}
},
scaling: {
hideScaled: true,
sizes: [
{ name: "small", maxSize: 350 },
{ name: "large", maxSize: 800 },
]
},
callbacks: {
onDelete: function (id) {
if (id == 2) {
$("#fine-uploader").fineUploader("deleteFile", 0);
$("#fine-uploader").fineUploader("deleteFile", 1);
}
},
},
});
uploader.addInitialFiles([
{
"name": "a3ef2360-881d-452c-a5f6-a173d5291066.jpg",
"uuid": "a3ef2360-881d-452c-a5f6-a173d5291066",
"size": "66000",
"thumbnailUrl": "https://s3.amazonaws.com/myfineuploaderbucket.com/1032/ecdca7bb-fb02-4072-b526-4e51cedb1f2b.jpg",
"s3Key": "1032/a3ef2360-881d-452c-a5f6-a173d5291066.jpg",
"s3Bucket": "myfineuploaderbucket.com"
}
]);
Is there something that I am doing wrong? Is addInitialFiles not a method, but an option that needs to be initialized when creating the Fine Uploader instance? I have tried adding "addInitialFiles" to the options of the Fine Uploader instance as well, and I do not receive a javascript error, but it does not load the initial file either.
I am using the latest version, 5.7.1.
Just like any other jQuery plug-in, the Fine Uploader jQuery wrapper returns a jQuery-wrapped element. This means that you are attempting to call an addInitialFiles method on a jQuery object. Of course, this method does not exist. If you really want to continue using the jQuery wrapper, you must change uploader.addInitialFiles(...) to uploader.fineUploaderS3('addInitialFiles', ...).
But you should know that you don't need jQuery for any of this, especially when using Fine Uploader. There is no benefit to using the jQuery wrapper with Fine Uploader, and you can fix your code simply by forgoing the wrapper (and saving a few bytes) and changing the first couple lines of your Fine Uploader initialization to:
var uploader = new qq.s3.FineUploader({
element: document.querySelector('#fine-uploader'),
...
})
Now, uploader.addInitialFiles works as you would expect.

jasmine-reporters option for Protractor's multiCapabilities option

I am using [jasmine-reporters] for xml report with Protractor.
Protractor's configuration for [jasmine-reporters] look like below,
onPrepare: function() {
require('jasmine-reporters');
jasmine.getEnv().addReporter(new jasmine.JUnitXmlReporter('../e2e_test_out', true, true, 'testresults.e2e.'));
},
above config working fine and gettting the result in 'e2e_test_out' directory with 'testresults.e2e.' prefix.
But when I use protractor's multiCapabilities option,
multiCapabilities: [{
'browserName': 'chrome'
}, {
'browserName': 'internet explorer'
}],
I am getting only one set of report. From that I could not understand the individual browser's result.
Is there any way to generate two diff reports / combined reports for both the browsers?
I found a solution that solved the same problem for me here:
https://github.com/angular/protractor/issues/60
In your protractor.conf file:
onPrepare: function(){
require('jasmine-reporters');
var capsPromise = browser.getCapabilities();
capsPromise.then(function(caps){
var browserName = caps.caps_.browserName.toUpperCase();
var browserVersion = caps.caps_.version;
var prePendStr = browserName + "-" + browserVersion + "-";
jasmine.getEnv().addReporter(new
jasmine.JUnitXmlReporter("protractor_output", true, true,prePendStr));
});
}
This will result in reports like:

Updating Child Panels in Sencha Touch MVC App

Developing a Sencha Touch MVC app that pulls data from json store (thats set up to a DB pulling out content from a Wordpress Blog).
Everything works up until my "detail" panel. Instead of it listening to the TPL, its just dumping some data. The data looks similar to my blog post, but is filled with other code and doesn't make much sense.
Here is a lean version of my list:
myApp.views.PostListView = Ext.extend(Ext.Panel, {
postStore: Ext.emptyFn,
postList: Ext.emptyFn,
id:'postlistview',
layout: 'card',
initComponent: function () {
/* this.newButton = new Ext.Button({
text: 'New',
ui: 'action',
handler: this.onNewNote,
scope: this
});*/
this.topToolbar = new Ext.Toolbar({
title: 'All Posts',
/* items: [
{ xtype: 'spacer' },
this.newButton
],*/
});
this.dockedItems = [ this.topToolbar ];
this.postList = new Ext.List({
store: myApp.stores.postStore,
grouped: true,
emptyText: '<div style="margin:5px;">No notes cached.</div>',
onItemDisclosure: true,
itemTpl: '<div class="list-item-title">{title}</div>' +
'<div class="list-item-narrative"><small>{body}</small></div>',
});
this.postList.on('disclose', function (record) {
this.onViewPost(record);
}, this),
this.items = [this.postList];
myApp.views.PostListView.superclass.initComponent.call(this);
},
onViewPost: function (record) {
Ext.dispatch({
controller: myApp.controllers.masterController,
action: 'viewpost',
post: record
});
},
});
And here is the "detail" view that is called on disclosure:
myApp.views.PostSingleView = Ext.extend(Ext.Panel, {
title:'Single Post',
id:'postsingleview',
layout:'card',
style:'background:grey;',
initComponent: function () {
this.new1Button = new Ext.Button({
text: 'Back',
ui: 'back',
handler: this.onViewList,
scope: this,
dock:"left"
});
this.top1Toolbar = new Ext.Toolbar({
items: [
this.new1Button
],
title: 'Single Posts',
});
this.postSinglePanel = new Ext.Panel({
layout:'fit',
flex:1,
scroll: 'vertical',
style:'padding:10px;background:yellow;',
itemTpl: '<tpl for=".">' +
'<div class="list-item-narrative">{body}</div>' +
'</tpl>',
});
this.dockedItems = [ this.top1Toolbar, this.postSinglePanel ];
myApp.views.PostSingleView.superclass.initComponent.call(this);
},
onViewList: function () {
Ext.dispatch({
controller: myApp.controllers.masterController,
action: 'viewlist',
});
},
});
And here is the controller that its talking to:
Ext.regController('masterController', {
'index': function (options) {
if (!myApp.views.mainView) {
myApp.views.mainView = new myApp.views.MainView();
}
myApp.views.mainView.setActiveItem(
myApp.views.postView
);
},
'viewpost': function (options) {
myApp.views.postSingleView.postSinglePanel.update(options.post);
myApp.views.postView.setActiveItem(
myApp.views.postSingleView,
{ type: 'slide', direction: 'left' }
);
},
});
myApp.controllers.masterController = Ext.ControllerManager.get('masterController');
When the data comes out, it looks similar to this:
http://i.imgur.com/QlQG8.png
(the black boxes are "redacted" content, no error code there).
In closing, I believe that the controller is "dumping" the data into "MyApp.views.PostSingleView" rather than formatting it as I request in the TPL, though I'm not sure how to fix it. Any and all help MUCH appreciated!
UPDATE: As requested, here is the RegModel:
Ext.regModel("CategoryModel", {
fields: [
{name: "id", type: "int"},
{name: "title", type: "string"},
{name: "body", type: "string"},
],
hasMany: {
model: 'Post',
name: 'posts'
}
});
And here is a sample of the json:
{
   "status":"ok",
   "post":{
      "id":1037,
      "type":"post",
      "slug":"post-title",
      "url":"http:\/\/localhost:8888\/jsontest\/PostTitle\/",
      "status":"publish",
      "title":"Post Title",
      "title_plain":"Post Title",
      "content":"<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.<br \/>\nLorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.<\/p>\n<!-- PHP 5.x -->",
      "excerpt":"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat [...]",
      "date":"2011-07-29 14:17:31",
      "modified":"2011-08-30 01:33:20",
      "categories":[
         {
            "id":87,
            "slug":"the-category",
            "title":"The Category",
            "description":"",
            "parent":17,
            "post_count":5
         }
      ],
      "tags":[
      ],
      "author":{
         "id":2,
         "slug":"tom",
         "name":"tom",
         "first_name":"tom",
         "last_name":"",
         "nickname":"",
         "url":"",
         "description":""
      },
      "comments":[
      ],
      "attachments":[
      ],
      "comment_count":0,
      "comment_status":"open"
   },
   "previous_url":"http:\/\/localhost:8888\/jsontest\/next-post\/",
   "next_url":"http:\/\/localhost:8888\/jsontest\/prev-post\/"
}
Use the tpl config option of the Ext.Panel not the itemTpl which doesn't exist.
As someone has mentioned before, be careful when using a Model instance and the update method, you will need to use the model's data property.
Try using this:
myApp.views.postSingleView.postSinglePanel.update(options.post.data);
the reason is that post does not actually expose the underlying data directly, you need to use the property data for that.
Also any particular reason why you are docking the postSinglePanel? I would be very careful using too many docked items as they are a known source of bugs and layout issues.
A simple way is to write your own method to update child panels (you can also see to override the default update method)
myApp.views.PostSingleView = Ext.extend(Ext.Panel, {
initComponent: function () {
// [...]
},
// [...]
myUpdate: function(data) {
this.postSinglePanel.update(data);
this.doComponentLayout(); // not sure if necessary...
}
});
and from your controller:
Ext.regController('masterController', {
// [...]
'viewpost': function (options) {
myApp.views.postSingleView.myUpdate(options.post.data); // note the .data
// [...]
},
});

Resources