Unable to upload the image in protractor - angularjs

Facing following error:
Failed: No element found using locator: By(css selector, input[type="images"])
Protractor code:
it("image upload",function(){
browser.ignoreSynchronization = true;
browser.sleep(4000);
element( by.css('[ng-click="imagePost()"]') ).click();
browser.sleep(3000);
var ele = element(by.model("files")).click();
browser.wait(EC.visibilityOf(ele),8000,'Ele is not presented');
var fileToUpload = "C:\Users\Shiva\Desktop\mdkg.jpg;"
console.log(fileToUpload);
var absolutePath = path.resolve(fileToUpload);
console.log(absolutePath);
$('input[type="images"]').sendKeys(absolutePath);
element(by.buttonText('Post Image')).click();
browser.sleep(5000);
});
HTML code to upload image:
<div ngf-drop ng-model="files" ngf-pattern="image/*" data-ngf-multiple="true" ng-repeat="image in images1" ngf-size>
<img src="{{image}}" width = "100%" height = "100%" class="m-l img-responsive img-rounded m-b" alt="post images">
</img-crop>
<span ng-show="loading" class="text-center col-xs-12" ></span>
</div>
</div>
<div class="modal-actions ">
<button type="submit " class="btn-link modal-action ">
<strong><span class="icon icon-user "></span>postImg</strong>
</button>
<button type="button" id="fileinput" ng-model="files" ngf-select accept="image/* " data-ngf-multiple="true" class="btn-link modal-action">Upload Image
Here I am uploding image, when I click on upload image it navigates to local system and it should upload the image. And after uploading it should post.

here is my answer using page objects:
this.uploadImage = function(){
var path = require('path');
var remote = require('../../../../node_modules/protractor/node_modules/selenium-webdriver/remote');
browser.setFileDetector(new remote.FileDetector());
var fileToUpload = '../../mdkg.jpg';
var absolutePath = path.resolve(__dirname, fileToUpload);
var fileElem = element(by.css('input[type="file"]'));
// Unhide file input
browser.executeScript("arguments[0].style.visibility = 'visible'; arguments[0].style.height = '1px'; arguments[0].style.width = '1px'; arguments[0].style.opacity = 1", fileElem.getWebElement());
fileElem.sendKeys(absolutePath);
// take a breath
browser.sleep(4000);
element(by.buttonText('Post Image')).click();
browser.sleep(4000);
};
post_text.uploadImage();

Related

To display the selected pdf file in angular js while uploading

Hi Here I have to upload single/multiple files in angular js . I have used the below link for uploading files. In this they have uploaded the images but instead I have to upload pdf and image.
<div class="container">
<div ng-controller="MyCtrl" class="row">
<button class="btn btn-primary pull-right" ng-hide="images.length == 0" ng-click="clearAll()">Clear All</button>
<h3 ng-bind="name"></h3>
<input type="file" ng-click="$event = $event" ng-model="display" multiple onchange="angular.element(this).scope().upload(event)" accept="image/png, image/jpeg, image/gif" />
<div class="row">
<div class="col-md-12"> <span ng-repeat='img in images'> <a href="#" ng-click="setImage($index)">
<img ng-src="{{img}}"
alt="Generic placeholder thumbnail" style="max-height:100px;" class="thumbnail"/>
</a>
</span>
</div>
</div>
<img ng-src="{{display}}" ng-hide="!display" />
<h4>You have upload {{images.length}} images this session.
</h4>
</div>
</div>
var myApp = angular.module('myApp', []);
myApp.controller('MyCtrl', function ($scope) {
$scope.name = "Select Files to Upload";
$scope.images = [];
$scope.display = $scope.images[$scope.images.length - 1];
$scope.setImage = function (ix) {
$scope.display = $scope.images[ix];
}
$scope.clearAll = function () {
$scope.display = '';
$scope.images = [];
}
$scope.upload = function (obj) {
var elem = obj.target || obj.srcElement;
for (i = 0; i < elem.files.length; i++) {
var file = elem.files[i];
var reader = new FileReader();
reader.onload = function (e) {
$scope.images.push(e.target.result);
$scope.display = e.target.result;
$scope.$apply();
}
reader.readAsDataURL(file);
}
}
})
Thanks in advance.
In this I can able to see the selected images on clicking choose file. But, if it is PDF format i cant able to see the image. Pls provide the solution for PDF.
You can use javascript and PDF.JS.
Example like this:
How to Convert PDF to Image (JPEG / PNG) with Javascript using PDF.JS

How to search data with ng-click in angular js

I want to search data with ng-click function in angularJS, but when I try this code, it doesn't work.
First my button code:
<button id="veg" ng-click="myFilter = {type: 1}" title="veg">
My data display code:
<div class="side-body padding-top fade in tab-pane" id="<?php echo $tt3->id; ?>">
<div class="row">
<div ng-if='r.pro_category == <?php echo $tt3->id; ?>'
ng-repeat = "r in groups | filter : searchGroups | filter:myFilter">
<div>
<div class="thumbnail">
<div>
<img src="../#{{r.image }}" alt="" />
</div>
<div class="caption">
<div>#{{r.pro_name }}</div>
<div>#{{r.price}}</div>
</div>
</div>
</div>
</div>
My script code:
var GroupsApp = angular.module('GroupsApp',[]);
GroupsApp.controller('GroupsController', function ($scope, GroupsService) {
getGroups();
function getGroups() {
GroupsService.getGroups()
.success(function (grps) {
$scope.groups = grps;
return (val.type != 2);
console.log($scope.groups);
})
.error(function (error) {
$scope.status = 'Unable to load Product data: ' + error.message;
console.log($scope.status);
});
}
});
var url = window.location.pathname;
var productid = url.substring(url.lastIndexOf('/') + 1);
GroupsApp.factory('GroupsService', ['$http', function ($http) {
var GroupsService = {};
GroupsService.getGroups = function () {
return $http.get('../showproduct/'+productid);
};
return GroupsService;
}]);
When I run above code it doesn't show anything.
<button href="#" id="veg" ng-click="myFilter = {active: 1}" title="All Menu Items" class="bbb1 btn btn-info btn-lg " >

ng-repeat inside ng-repeat in angularjs

Iam
routerApp.controller('HomePageCtrl',['$scope','$rootScope','searchFood','$timeout','$cookies',function($scope,$rootScope,searchFood,$timeout,$cookies){
var a=[];
$scope.fooditems= {};
$scope.Fn_LoadTimeslotWise = function(ts){
$scope.tsfooditems = {};
var longitude = $cookies.longitude;
var latitude = $cookies.latitude;
var sdate = $cookies.date;
var timeslot1 = ts;
var timeslot2 = timeslot1.substr(0,5);
var timeslot3 = timeslot1.substr(9,2);
var timeslot4 = timeslot2 + timeslot4;
var timeslot5 = timeslot1.substr(14,5);
var timeslot6 = timeslot1.substr(23,2);
var timeslot7 = timeslot5 + timeslot6;
var timefrom = sdate +" "+ timeslot2;
var timeto = sdate +" "+ timeslot5;
// console.log(timefrom);
//console.log(timeto);
$scope.tim = '.' + ts;
$timeout(function(){
searchFood.ChangeTimeSlot(latitude,longitude,sdate,timefrom,timeto).then(function(d){
$scope.tsfooditems ={};
$scope.tsfooditems = d[0];
});
});
}
}]);
<div ng-repeat = "timeslot in timeslots">
<h1 class="title"> {{ timeslot.date_time }} </h1>
<div class="row product-list-wrap" ng-init = "Fn_LoadTimeslotWise(timeslot.date_time)">
<h2 ng-show="showsearchmsg" ng-bind="searchresult"></h2>
<div class="col-md-4" ng-repeat="tsfooditem in tsfooditems ">
<div class="product-box view view-third">
<div class="product_img"> <span class="favourite"> <i class="fa fa-heart"> </i> </span>
<span class="veg"> <img src="images/veg.png"></span><img ng-src="{{tsfooditem.picture}}" width="200px" height="150px" ng-click="Fn_fooddetails(tsfooditem.menu_id)"> </div>
<div class="product-content">
<div class="product-title">
<h2 ng-bind="tsfooditem.menu_name | uppercase"></h2>
<h3 ng-bind="tsfooditem.chef_name"></h3>
</div>
<div class="product-rate"><b ng-bind="currency"></b>. <span ng-bind="tsfooditem.cost "></span> </div>
<div class="product-add"> <span class="bg"> - </span> <span ng-bind="tsfooditem.todays_menu_qty"></span> <span class="bg"> + </span> </div>
</div>
</div>
</div>
</div>
</div>
using angularjs version1.2.13.I need the below specified output
o/p
Timeslot 12.30-4.30pm
oil,
vegetable
Timeslot 1.30-3.30pm
oil,
meat
I am using two ng-repeat one inside another.But always the array displays only secondtime slot,.ie second overrides firstone .please help,Thanks in advance
It looks like your problem is that with your first ng-repeat, tsfooditems is not an array, it is an object literal. Ng-repeat will only work with arrays. Try changing
$scope.tsfooditems ={};
$scope.tsfooditems = d[0];
to
$scope.tsfooditems = [];
$scope.tsfooditems.push(d[0]);

TypeError: Cannot read property 'Scroll' of undefined firebase

Am using firebase.util to create infiniteScroll. I downloaded firebase util using bower.Then i try this code:
In my HTML file :
<div class="list">
<div ng-repeat="e in events " class="item" >
<div class="list" >
<a class="item item-thumbnail-left" ui-sref='eventDetail({eventId:e.$id})'>
<img src="img/ionic.png">
<h2>{{e.name}}</h2>
<h2>Categerie: {{e.categorie.label}}</h2>
</a>
</div>
</div>
<ion-infinite-scroll ng-if="!noMoreItemsAvailable" on-infinite="loadMore()" distance="10%"></ion-infinite-scroll>
In my controller:
var baseRef = new Firebase('https://event-application.firebaseio.com/event');
var scrollRef = new Firebase.util.Scroll(baseRef, 'name');
$scope.events = $firebaseArray(scrollRef);
scrollRef.scroll.next(3);
$scope.loadMore = function() {
scrollRef.scroll.next(2);
$scope.$broadcast('scroll.infiniteScrollComplete');
};
Any help is appreciated.

Angular controller value seeming to revert to original value

After originally setting my controller weddingPrice value a change caused by a function does not seem to change the variable. Its probably a simple error- can anyone help?
When sendWeddingQuoteInfo() is called it seems to send the original weddingPrice, not the one which has been updated when the return journey toggle has been checked.
What should happen is that the wedding price should be set at the start through the local setup function. Then if the return journey toggle is switched to on, the returnJourneyChange() should be fired, changing the global weddingPrice. When the Submit Quote button is pressed this should take the updated weddingPrice and send it to the next page. Currently this does not happen- no idea why.
//wedding.html
<ion-view view-title="Wedding Pax Num" can-swipe-back="true">
<ion-content ng-controller="WeddingPaxCtrl">
<div class="card">
<div class="item centerText" style="background-color: brown;">
<h2>CALCULATE WEDDING</h2>
</div>
</div>
<div class="padding20Top padding20Bottom">
<h2 class="centerText">Select number of Passengers</h2>
<input ng-model="passengerNo" class="col col-50 col-offset-25 quoteTFieldWithListItems" type="textfield">
<h6 class="centerText">PASSENGERS</h6>
</div>
<ion-toggle ng-model="returnJourney.checked" ng-change="returnJourneyChange()">Return Journey
</ion-toggle>
<ion-toggle ng-show="returnJourney.checked" ng-model="midnightReturn.checked" ng-change="midnightReturn()">Return Journey After Midnight</ion-toggle>
<div>
<h6 class="logText centerText"> {{ getCostBreakDown() }}</h6>
</div>
</ion-content>
<div class="endOfPageButton">
<a href="#/app/home/tester">
<button class="button button-full button-clear" ng-click="sendWeddingQuoteInfo()">Submit Quote</button>
</a>
</div>
</ion-view>
//controller.js
app.controller('WeddingPaxCtrl', function($scope, $stateParams, PassData, WhichQuote, CostOfMarriage, StoreQuoteData, WeddingData, DataThrow) {
var item = WeddingData.getWeddingDataObject();
$scope.passengerNo = 49;
$scope.returnJourney = { checked: false };
$scope.midnightReturn = { checked: false };
var weddingPrice;
$scope.returnJourney;
$scope.midnightReturn;
setup();
var sendInfo;
function setup() {
console.log("setup called");
weddingPrice = CostOfMarriage.getPrice(item[0], $scope.passengerNo, $scope.returnJourney.checked, $scope.midnightReturn.checked);
}
$scope.returnJourneyChange = function() {
console.log("return j called");
weddingPrice = 1000;
console.log("wedding price is now" + weddingPrice);
}
$scope.midnightReturn = function() {
}
$scope.getCostBreakDown = function() {
}
$scope.sendWeddingQuoteInfo = function() {
// var weddingPrice = $scope.weddingPrice;
console.log("WeddingPrice is " + weddingPrice + weddingPrice);
var sendInfo = ["Wedding Hire", item[0], $scope.passengerNo, "Extra", weddingPrice];
StoreQuoteData.setQuoteData(sendInfo);
WhichQuote.setInfoLabel("Wedding");
}
})
I think your ng-controller attribute is not at the right place. So the scope of your submit button is different.
I've moved the controller to ion-view element then the click is working as expected.
Please have a look at the demo below or here at jsfiddle.
(I've commented a lot of your code just to make the demo work.)
var app = angular.module('demoApp', ['ionic']);
app.controller('WeddingPaxCtrl', function($scope, $stateParams) { //, WeddingData, DataThrow) {
//var item = WeddingData.getWeddingDataObject();
$scope.passengerNo = 49;
$scope.returnJourney = {
checked: false
};
$scope.midnightReturn = {
checked: false
};
var weddingPrice;
$scope.returnJourney;
$scope.midnightReturn;
setup();
var sendInfo;
function setup() {
console.log("setup called");
weddingPrice = 100; //CostOfMarriage.getPrice(item[0], $scope.passengerNo, $scope.returnJourney.checked, $scope.midnightReturn.checked);
}
$scope.returnJourneyChange = function() {
console.log("return j called");
weddingPrice = 1000;
console.log("wedding price is now" + weddingPrice);
}
$scope.midnightReturn = function() {
}
$scope.getCostBreakDown = function() {
}
$scope.sendWeddingQuoteInfo = function() {
// var weddingPrice = $scope.weddingPrice;
console.log("WeddingPrice is " + weddingPrice + weddingPrice);
//var sendInfo = ["Wedding Hire", item[0], $scope.passengerNo, "Extra", weddingPrice];
//StoreQuoteData.setQuoteData(sendInfo);
//WhichQuote.setInfoLabel("Wedding");
}
})
<script src="http://code.ionicframework.com/nightly/js/ionic.bundle.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.15/angular-ui-router.js"></script>
<link href="http://code.ionicframework.com/nightly/css/ionic.css" rel="stylesheet" />
<ion-view ng-app="demoApp" view-title="Wedding Pax Num" can-swipe-back="true" ng-controller="WeddingPaxCtrl">
<ion-content>
<div class="card">
<div class="item centerText" style="background-color: brown;">
<h2>CALCULATE WEDDING</h2>
</div>
</div>
<div class="padding20Top padding20Bottom">
<h2 class="centerText">Select number of Passengers</h2>
<input ng-model="passengerNo" class="col col-50 col-offset-25 quoteTFieldWithListItems" type="textfield">
<h6 class="centerText">PASSENGERS</h6>
</div>
<ion-toggle ng-model="returnJourney.checked" ng-change="returnJourneyChange()">Return Journey
</ion-toggle>
<ion-toggle ng-show="returnJourney.checked" ng-model="midnightReturn.checked" ng-change="midnightReturn()">Return Journey After Midnight</ion-toggle>
<div>
<h6 class="logText centerText"> {{ getCostBreakDown() }}</h6>
</div>
</ion-content>
<div class="endOfPageButton">
<!---<a href="#/app/home/tester">-->
<button class="button button-full button-clear" ng-click="sendWeddingQuoteInfo()">Submit Quote</button>
<!--</a>-->
</div>
</ion-view>

Resources