I am involving in designing a image upload on protractor test in my local machine And i am having difficulties to get the image on the popup window to be uploaded. here is my e2e test code,
this.uploadnewprofilepage = function () {
var EC = protractor.ExpectedConditions;
browser.wait(EC.elementToBeClickable(clickuploadonprofpage), 5000);
clickuploadonprofpage.click();
var EC = protractor.ExpectedConditions;
browser.wait(EC.elementToBeClickable(selectapicture), 5000);
selectapicture.click();
var path = require('path');
var fileToUpload = '../Resourcefiles/filupimage.jpg',
absolutePath = path.resolve(__dirname, fileToUpload);
element(by.id("save-btn")).sendKeys(absolutePath);
however I could not get sendkeys to be worked to get the image on the image upload window.
my code snippets is like this.Any comments on this is appreciated.thanks
Related
I need to download an image URL to my project folder's file. I have tried below code for that:
var a = document.createElement('a');
a.download = './files';
a.href = 'https://www.google.co.in/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png';
a.style.display = 'none';
document.body.appendChild(a);
a.click();
But it gives error as ReferenceError: document is not defined.
How can we solve this or how can I download an image URL to a specified folder?
Thanks in advance.
In Steps definition, i declare 'chai' and use to debug:
var chai = require('chai');
var chaiAsPromised = require('chai-as-promised');
chai.usexpece(chaiAsPromised);
var expect = chai.expect;
module.exports = function() {
this.Given(/^I go on "([^"]*)"$/, function (arg1, callback) {
browser.driver.get(arg1);
browser.manage().timeouts().pageLoadTimeout(10000);
var answer = 43;
expect(answer).to.equal(42);
console.log("this text will be displayed");
callback();
});
}
When i run the script, text this text will be displayed does not appear ,in console but when i comment this line //expect(answer).to.equal(42);, the text appear as normal.
I know there is a wrong in expect of chai object but cannot find out the solution. Anyone can help me to resolve the issue. Thank so much
cucumber-js supports steps that return promises.
When using chai-as-promised, i need to return the expectation (which is a promise)
this.When(/^I test async code$/,function() {
return expect(true).to.be.true;
});
I've been checking others threads about this common error and trying to apply what they recommend but still getting same error. I warn you I'm totally newbie at PROTRACTOR.
This it's the first test I'm writting:
describe('Just some shitty test', function(){
'use strict';
it('Testing some shitty test', function(){
beforeEach(function () {
browser.get(browser.baseUrl);
});
/*
Purpose:
1. Getting in "HEALTH CARE PARTNER / ORGANISATION (KND. NR.: 438)" panel
2. Edit content
3. Save it
*/
// First, I find elements I want to test
//ANCHOR Bearbeiten
var $a = $('a','div.m-pane__control');
//INPUT Name
var $name = $('input[placeholder="Name"]');
//SELECT
var $select = $('select','m-form__select ng-scope');
//INPUT Yearly births
var $yearly = $('input[placeholder="Yearly births"]');
//INPUT Homepage
var $homepage = $('input[placeholder="Homepage"]');
//INPUT Email
var $email = $('input[placeholder="Email"]');
//TEXTAREA. two ways to find it
var $textarea1 = $('textarea[ng-model="model[field.name]"]');
var $textarea2 = element(by.model('model[field.name]'));
//BUTTON Speichern
var $speichern = $('button[ng-click="savebtn()"]');
// Sequence of actions
//Is bearbeiten button displayed?
//expect($a.isDisplayed()).toBe(true);
//Click on it!
//$a.click();
//Settings
//$name.sendKeys('John Smith').submit();
//$yearly.sendKeys('42');
//$homepage.sendKeys('something');
//$email.sendKeys('tschues#baba.at');
//$textarea1.sendKeys('fahren lassen');
//Save
//$speichern.click(); });});
I don't know if elements I've searched are ok but every time I call getText() function or either as click(), sendKeys or whatever, I always get Error while waiting for Protractor to sync with the page: {}.
What I'm forgetting or doing wrong?
Thank you
Try something like this
describe('Just some test', function(){
var ptor;
beforeEach(function () {
browser.get(browser.baseUrl);
ptor = protractor.getInstance();
ptor.waitForAngular();
});
it('should do something', function(){
var aLink = element(by.css('div.m-pane__control'));
aLink.click();
});
});
Biggest differences are I ask protractor to wait for angular, since it takes some time to get ready and I used the protractor style of finding elements on the page.
I have this google app script which should
show file upload dialog
store file in google drive
write the url of the file into the current cell
All goes well except step 3, where the cell updated is always cell A1 in the first sheet. But the cursor is on sheet #3 on another cell.
function onOpen(e) {
var ss = SpreadsheetApp.getActiveSpreadsheet()
var menuEntries = [];
menuEntries.push({name: "File...", functionName: "doGet"});
ss.addMenu("Attach ...", menuEntries);
}
function doGet(e) {
var app = UiApp.createApplication().setTitle("Attach file to sheet");
var form = app.createFormPanel().setId('frm').setEncoding('multipart/form-data');
var formContent = app.createVerticalPanel();
form.add(formContent);
formContent.add(app.createFileUpload().setName('thefile'));
formContent.add(app.createSubmitButton('Submit'));
app.add(form);
SpreadsheetApp.getActiveSpreadsheet().show(app);
return app;
}
function doPost(e) {
var fileBlob = e.parameter.thefile;
var doc = DocsList.getFolderById('0B0uw1JCogWHuc29FWFJMWmc3Z1k').createFile(fileBlob);
var app = UiApp.getActiveApplication();
var label = app.createLabel('file uploaded successfully');
var value = '=hyperlink("' + doc.getUrl() + '","' + doc.getName() + '")'
app.add(label);
app.close();
SpreadsheetApp.getActiveSheet().getActiveCell().setValue(value);
return app;
}
I tried SpreadsheetApp.getActiveSheet().getActiveCell().setValue(value); outside of the doPost() function and this works when called in a normal context. What am I missing here?
judging from this answer, it is not possible to get the current spreadsheet/cell from the doPost function, the way I got it working is to get it in the doGet function via hidden fields and pass it via the form. Full blown working example here.
I'm trying to make a photo organizing Facebook application without using server-side process.
Now I can preview photos by using FileReader object's readAsDataURL method, such as...
var file = e.dataTransfer.files[0];
var reader = new FileReader();
reader.onload = function(e) {
var imgObj = $(document.createElement('img')).attr('src',reader.result).appendTo('#image_preview_wrapper');
};
reader.readAsDataURL(file);
}, false);
The question is how to post the image data to Facebook.
I'm trying to do something like
var reader = new FileReader();
reader.onload = function(e) {
var data = reader.result;
FB.api('/me/photos','post',{ image : data },function(res){
alert(res);
});
}
reader.readAsBinaryString(file);
In this case, I can't set enctype="multipart/form-data" and I'm getting 400 Bad Request.
Can anybody help me?