w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Testing file uploading
I have used this helper for integrations tests in rspec: module PathHelpers def file_path(name) File.join("spec", "support", "files", name) end end RSpec.configuration.include PathHelpers Then, put your test files in the spec/support/files and you can use it inside your tests: scenario "create new estimate" do visit new_estimate_path fill_in 'Title', with: 'Cool estimate' attach_file 'CSV', file_path('estimate_items.csv') expect { click_button "Create estimate" }.to change(Estimate, :count).by(1) end For FactoryGirl factories, I have something like this: FactoryGirl.define do factory :estimate_upload do estimate excel File.open(File.join(Rails.root, 'spec', 'support', 'files', 'estimate_items.csv')) end end Hope that everything is clear!

Categories : Ruby On Rails

Is protractor Angular's new scenario runner?
In the AngularJS 1.2 and Beyond meetup last night they talked about Protractor and said that they are migrating all of their end to end tests to Protractor. It sounded like this is in the early stages but is the direction they are going. The slides are at: https://docs.google.com/presentation/d/1WHCcp3G3HxoE7b_ut_ERKJF4zQK_P4qFlESjE2E9AUQ/edit and I assume the video will be available in a couple of days. Here's the link to the meetup: http://www.meetup.com/AngularJS-MTV/events/120927882/ btw, there was a ton of really interesting info in the meetup -- well worth the watch.

Categories : Angularjs

Can protractor test a login that is not angular based
After placing the issue on github I received the answer I was looking for. This can be found HERE! Protractor requires that Angular be present on the page and the way around this is to use the driver directly. Following the link above should stear anyone stuck on the same issue in the right direction. Kudos to JulieMR and the others who helped out with this issue.

Categories : C#

Angular JS/Karma Unit Testing with Angular UI-Router
At first glance I would say it looks like the $stateProvider is telling you you need to put an empty state in there. Add this to the list of states. state( '', { ... } )

Categories : Unit Testing

Image uploading using codeigniter file uploading class
try this one say your input file like <input type="file" name="image" id="image"> now change the following line !$this->upload->do_upload() with !$this->upload->do_upload('image') please let me know if you face any problem. UPDATE if you want to sent it to the template then do like this if (!$this->upload->do_upload()) { $error = array('error' => $this->upload->display_errors()); $this->session->set_flashdata('msg',$error['error']); redirect('controller_name/function_name','refresh'); } try this and let me know.

Categories : Image

HttpPostedFileBase is null when uploading files with Angular
That's because you've given the form data the name of uploadedFile, yet your action takes a parameter named file. Change the parameter name, like so: public void UploadDocuments(HttpPostedFileBase uploadedFile) { }

Categories : C#

Angular e2e testing ng-show
Have you tried adding wait time to the test to allow the UI to catch up with the script? input('test.pname').enter('cakes`'); expect(element('#pnameValidate:visible').count()).toBe(1); expect(element('#pnameValidate:visible').text()).toMatch(/up to 30 characters/); input('test.pname').enter('cakes are good'); setTimeout(function() { expect(element('#pnameValidate:visible').count()).toBe(0); expect(element('#pnameValidate:visible').text()).toBe(''); }, 500);

Categories : Validation

Testing angular with karma: how to set scope
Short story: change the compiled element to <div hy-plugin-window content="content"></div> and I think it should work. The directive has an ISOLATE scope, which means it does not prototypically inherit from the "regular" scope. In your test, you are defining content on the regular scope, but the directive itself is encapsulated - it has isolated scope and therefore does not see the content property defined on the regular scope. You need to communicate that through the explicit interface of the component, which is content attribute.

Categories : Angularjs

Testing angular services in rails
You can use $injector to get the service and then inject it to the actual test like this describe("AuthService", function () { var httpBackend, AService, apiPrefix; beforeEach(module('app')); beforeEach(function () { angular.mock.inject(function ($injector) { httpBackend = $injector.get('$httpBackend'); apiPrefix = angular.mock.module('apiPrefix'); // I assume you have apiPrefix module defined somewhere in your code. AService = $injector.get('AuthService', {apiPrefix: apiPrefix}); }) }); it("should login the user", inject(function (AService) { // test here })); }); I assume you have apiPrefix module defined somewhere in your code.

Categories : Testing

Testing angular factories with jasmine
The problem is In your production code var dataLoadedPromise = $http.get('myData.xml', {transformResponse: transformResponse}); you expect the return from the server is XML data not json, so when you mock the HTTP, you should use XML instead of Json. Here is the working code: describe("controller: MyController", function () { beforeEach(function () { module("myApp"); }); var dataFactory; beforeEach(inject(function ($injector, $controller, $rootScope, $location, $httpBackend) { this.$location = $location; this.$httpBackend = $httpBackend; this.scope = $rootScope.$new(); dataFactory = $injector.get('dataFactory'); this.$httpBackend.expectGET('myData.xml').respond( "<?xml version="1.0" encoding="UTF-8" ?

Categories : Unit Testing

Testing Angular Directives with their own controllers
The way you'll end up accessing the controller in this case is by using the function the controller is placing in its scope from the HTML snippets that will form your test inputs. Note: The use of a jasmine spy may be overkill here, and I didn't take the time to look up the right methods for matching the arguments to $location.path() and/or $location.search(), but this should be enough to help you find the hook into a place for observation that you're looking for. 'use strict'; describe('Directive: Search', function() { var element, $location; // Load your directive module with $location replaced by a test mock. beforeEach( function() { module('myapp.directives'), function() { $provide.decorator('$location', function($delegate) { $delega

Categories : Angularjs

How to set jasmine for karma e2e for testing angular app?
Angular e2e tests with Karma don't and can't use the JASMINE adapter. Instead you have the ANGULAR_SCENARIO_ADAPTER which has a similar feel to writing Jasmine tests. All commands in the adapter's API are asynchronous anyway. For example element('#nav-items').count() doesn't return a number, it returns a Future object. Future objects are placed in a queue and executed asynchronously as the runner progresses. To quote the API docs: expect(future).{matcher}: [...] All API statements return a future object, which get a value assigned after they are executed. If you need to run your own asynchronous test code, you can extend the adapter's DSL, this is easier than it might sound. The idea is that you return your own Future which can be evaluated by a matcher such as toBe(). There ar

Categories : Testing

Unit testing angular ng-resource
You are not using $httpBackend correctly. First, the definition of the mock response: $httpBackend.whenGET('/api/clients').respond(mockResponse); Then, later, the expectation: $httpBackend.expectGET('/api/clients'); $httpBackend.flush();

Categories : Angularjs

Testing angular services with controllers
Solution that I've found seems to be very easy and nice: beforeEach(function () { inject(function ($rootScope) { scope = $rootScope.$new(); scope.$apply(function () { scope.value = true; }); $name.bind(scope, 'value'); scope.$apply(function () { scope.value = false; }); }); }); beforeEach(function () { value = $name.get('value'); }); it('should have $scope value', function () { expect(value).toBeFalsy(); });

Categories : Javascript

Angular UI-Router testing scope inheritance
Scope inheritance is a feature of Angular. I therefore think that it is not necessary to test in my tests. My workaround is to test that the AccountCtrl works and then just put the values in the other tests: it("should set scope when account Ctrl loaded", inject(['$controller', 'security', function($controller, security){ // Add your behavior testing code here var $scope = $rootScope.$new(); var user = { first: 'First', last: 'Last', email: 'testuser@test.com', gender:'male', birthday:'password'}; security.currentUser = user; $controller('AccountCtrl', { $scope: $scope}); $rootScope.$digest(); // verify the initial setup expect($scope.user).toEqual(user); expect($scope.account).toEqual(user); }])); Then in the other tests I manually populate the values: it('should

Categories : Angularjs

Testing Angular Controllers: Controller Not Defined
Same way you did the last one describe('evCalcApp controllers', function(){ beforeEach(module('evCalcApp.controllers')); var scope, ctrl, ctrl2; beforeEach(inject(function($controller, $rootScope) { scope = $rootScope.$new(); scope2 = $rootScope.$new(); ctrl = $controller('MyMileageCalcController', {$scope: scope}); ctrl2 = $controller('MyCtrl2', {$scope: scope2}); }));

Categories : Javascript

Unit Testing Angular js with bootstrap-ui dialog
I changed the test code to this: describe('deletion confirmation modal', function() { var $scope, ctrl, $dialog, fakeDialog, provider, resolveCallback; //this fake object replaces the actual dialog object, as the functions are not visible to the test runner. fakeDialog = { isOpen: false, open: function() { fakeDialog.isOpen = true; return { then: resolveCallback }; }, close: function() { return true; } }; resolveCallback = function(callback) { } beforeEach(function() { module(function($dialogProvider) { provider = $dialogProvider; }); inject(function(_$httpBackend_, $rootScope, $routeParams, $controller,

Categories : Javascript

Angularjs E2E Testing with Angular-UI Select2 Element
I was unable to get this to work within the Karma test runner, however this became significantly easier within the protractor test suite. To accomplish this within the protractor test suite I used the following to select the first select2 box on the page and select the first option within that box: var select2 = element(by.css('div#s2id_autogen1')); select2.click(); var lis = element.all(by.css('li.select2-results-dept-0')); lis.then(function(li) { li[0].click(); }); The next select2 on the page has an id of s2id_autogen3

Categories : Angularjs

Best practices for unit testing angular directives
The question is that directive is meant to bind together user, DOM and Scope. All scope handling shall be done inside a controller (probably bound to your directive through controller: property). So, you should have a unit testing separated for you controller, without even touching the directive part. Then you shall test your directive. As it's mainly about DOM handling, you might want to test your real template, not a mocked one. In order to get the elements, as you need, you can use find() method. If you don't use jQuery at all, you can load it (before your AngularJs dependency) on unit testing and use element.find('#one'), for example. All AngularJs elements are extended jQuery elements, if you don't have jQuery on your project, then Angular uses jQLite, and you'll not have the select

Categories : Unit Testing

Testing repsonse of angular service with $http get
Have you tried to inject your httpBackend? Try this on your "beforeEach" call: beforeEach(inject(function(subscribeService, _$controller_, _$rootScope_, _$httpBackend_){ subscribeServiceMock = subscribeService; $scope = _$rootScope_.$new(); $controller = _$controller_('MyCtrl', { $scope: $scope }); $httpBackend = _$httpBackend_; })); UPDATE As I found out here: AngularJS Issues mocking httpGET request It seems there's in fact a difference between these two "injection methods"

Categories : Javascript

How can I solve Error during testing Angular Js in netbeans?
You need to add the JsTestDriver jar to your lib folder, as listed in the resources table. The file is available here: https://code.google.com/p/js-test-driver/downloads/list

Categories : Unit Testing

Unit testing Angular js Directive with Dependencies
I figured it out using the below stackoverflow thread Testing angularjs directive with dependencies Below is the code: describe('Directive: AppVersion', function () { beforeEach(module('MyApp')); var element; it('should have element text set to config value', inject(function ($rootScope, $compile, x,y) { var scope = $rootScope; element = $compile('<div class="someClass" xDirective >some Content</div>')(scope); expect($(element).find('.someClass').css('height')).toBe(config.version); })); }); inside the it block i'm injecting 'x' and 'y' modules which are dependencies to the directive Thanks

Categories : Unit Testing

testing Angular directive scope with jQuery loaded
I found the problem. I'm running my tests in PhantomJS and was pulling in jQuery 2.0.3. Downgrading to jQuery 1.10.2 made everything work again. I'm kind of surprised that PhantomJS would have a compatibility issue but that seems to have been the problem.

Categories : Angularjs

Testing inside the Angular-UI Bootstrap dialog promise
You can use an actual promise as the return value of open: it('sets result to foobar', function() { // Arrange var deferred; dialogMock.dialog.andCallFake(function () { return dialogMock; }); dialogMock.open.andCallFake(function () { deferred = $q.defer(); return deferred.promise; }); // Act $scope.openDialog(); deferred.resolve('foobar'); $scope.$digest(); // Assert expect($scope.result).toBe('foobar'); }); Check out the full code in this Plunker script.

Categories : Angularjs

Angular e2e testing. How to click dom elements ? (buttons links)
You can use generic jquery selectors to find elements.. here's some code from my e2e tests. Note especially the :eq(3) selector for taking the 4th anchor tag. it('The cancel button should close the form and revert the info', function() { input("ci.customer.name").enter("Tom Selleck") element('#customerinfo input[value="Cancel"]').click(); // check pdfdata to make sure it got reflected element('.navbar a:eq(3)').click(); expect(element('.navbar a:eq(2)').text()).not().toBe("Customer (Tom Selleck)"); });

Categories : Angularjs

PhantomJS integration testing with angular against live backend
For E2E testing with a real back end, I would consider using Protractor. As far as I know, ngMock and ngMockE2E are both made to fake a connection to a real server. With these libraries you can unit test your Angular project so that it works isolated. Note that it is a bit more work to setup E2E testing with Protractor if you start from scratch. There are however also starter projects (Yeoman), which already have this setup for you. You could use generator-angular-gulp for example for your application, or you could have a look how they have set things up.

Categories : Angularjs

Angular.js Unit/Integration Testing - Trigger Link Function
It turns out that I have to initialize the module containing the factories stringEntryGenerateTemplate and stringEntryGenerateLinkFn, which is the same module that contains the userWrapperUsername directive by adding this into my test case: beforeEach(module('userWrapper', function() {})); where userWrapper is the name of the module. So the test case becomes: describe('UserWrapper Table string entry', function() { var $scope , $compile; beforeEach(module('userWrapper', function() {})); beforeEach(inject(function($rootScope, _$compile_) { $scope = $rootScope.$new(); $compile = _$compile_; })); it('should be in stateDisplay if the value is non empty', function() { var userWrapper = { orgData: { student

Categories : Javascript

Angular unit testing directive that uses transclusion not working as expected
The reason why the directive that uses transclude does not trigger the alert is because it has an isolated scope : scope: {} and you defined your callback in it : post: function(scope, element, attributes) { scope.func = function($event) { alert('the unit test should trigger this'); } } Due the transclusion, the directive and the transclude do not share the same scope but inherit from the same parent (see the doc even it is difficult to understand). If you want that the transclude element access to an element that is added to the scope by the directive, the directive must not create a new scope and add this function in the parent scope : scope: false, ... post: function(scope, element, attributes) { scope.func = function($event) { alert('the unit test should trigger t

Categories : Angularjs

Angular Unit Testing on Controller using a Service - Breaking on Inject
I think this is a problem of the dependencies of the module influences.controllers not being loaded. I tried a rather scaled down version of your program and got the exact same error as you. It was only after consulting this question here that I managed to get it. Do read the answer by the author, I think it'll be very helpful. Anyways, this is what you should probably do to load the actual ui.bootstrap and influences.services modules in the Test file: 'use strict'; /* jasmine specs for controllers go here */ describe('influences controllers', function() { // Change is here. Notice how the dependencies of the influences.controllers // module are specified separately in another beforeEach directive beforeEach(module('influences.controllers')); beforeEach(function() { module(

Categories : Angularjs

Uploading small .sql file to MySQL database file returns error (XAMPP on OS X)
Solved within the file uploads section of your php.ini there resides this: ;upload_tmp_dir = To allow for uploads uncomment and give the tmp dir a home: upload_tmp_dir = "/tmp" The the most recent default installation of XAMPP on Lion has a couple of very important lines commented out (in regards to phpmyadmin/mysql). Not sure why, but I would love to learn the reasoning behind it.

Categories : Mysql

HTML 5 File API uploading a file in browser and saving contents as a string
The script has no context to the file, you are calling the code inline. You should be using a change event or a form submission. var file = this.target; console.log(file); //look at what the "target" is var reader = new FileReader();

Categories : Javascript

Unit Testing Angular Service that uses $timeout with Jasmine's Mock Clock
Do not make your test Async by using Jasmine's clock. Instead, use $timeout.flush() to synchronously maintain the flow of the test. It may be a bit tricky to setup, but once you get it then your tests will be faster and more controlled. Here's an example of a test that does it using this approach: https://github.com/angular/angular.js/blob/master/test/ngAnimate/animateSpec.js#L618

Categories : Javascript

What are the configurations required for Apache (HTTPD) for enabling directory/file writing and file uploading?
I was doing everything right. The only problem was CentOS SELinux. It was not allowing apache to write files into the web directory. Using the command "setenforce 0" , i closed it down and everything started working. Later, I added an exception into my SELinux policies to fix issues.

Categories : PHP

How to check file size of each file before uploading multiple files in ajaxtoolkit ajaxfileupload control in asp.net?
See the code below: public void afuUpload_UploadedComplete(object sender, AsyncFileUploadEventArgs e) { try { string savePath = MapPath("~/Uploads/" + Path.GetFileName(e.filename)); if (int.Parse(e.filesize) > 3000000) { return; } afuUpload.SaveAs(savePath); } catch (Exception ex) { throw ex; }}

Categories : Asp Net

File in use by another process error when uploading a file using server but not localhost
maxRequestLength is specified in KB but requestLengthDiskThreshold specifies the limit for the input stream buffering threshold, in bytes. Therefore you need to change requestLengthDiskThreshold to 543744 (531KB x 1024) Also check any of the following settings that apply to your scenario <httpRuntime executionTimeout = "HH:MM:SS" maxRequestLength = "number" requestLengthDiskThreshold = "number" useFullyQualifiedRedirectUrl = "[True|False]" minFreeThreads = "number" minLocalRequestFreeThreads = "number" appRequestQueueLimit = "number" enableKernelOutputCache = "[True|False]" enableVersionHeader = "[True|False]" apartmentThreading = "[True|False]" requireRootedSaveAsPath = "[True|False]" enable = "[True|False]" sendCacheControlHeader = "[

Categories : C#

How to check file extension while uploading a file in multifile.js
This script should be put as a validation before file is submitted. It should also work for filenames which already contains '.'(dot) eg.. myfile.ms.xls etc... var splitLength = parseInt($('#file').val().split('.').length) var extensionCaseInsensitive = $('#file').val().split('.')[splitLength-1] if (extensionCaseInsensitive.toUpperCase() == 'DOC' || extensionCaseInsensitive.toUpperCase() == 'XLS') { // allow upload } But remember one thing if a user is literally naming a png image as doc file then we cannot check the contents to validate or probably it will a much longer and complicated exercise.

Categories : Javascript

Manually trigger Angular data binding for an input field (for unit testing purposes only)
This is not right approach to do this in angular. You should do like this. Working DEMO Create function inside the $scope and change your variable value so that angular itself will update your input field as well as at all places where you have used(bind) this variable. Angular Function $scope.changeInput = function() { $scope.value="barfoo"; }

Categories : Angularjs

Is there a max file size when uploading as a Multipart File
Try this in your config: @Bean public MultipartResolver multipartResolver() { return new StandardServletMultipartResolver(); } @Bean MultipartConfigElement multipartConfigElement() { MultiPartConfigFactory factory = new MultiPartConfigFactory(); factory.setMaxFileSize(env.getRequiredProperty("MAX.FILE.SIZE")); factory.setMaxRequestSize(env.getRequiredProperty("MAX.FILES.SIZE")); factory.setFileSizeThreshold(env.getRequiredProperty("MAX.MEMORY.SIZE")); factory.setLocation(env.getRequiredProperty("IMAGE.PROCESSOR.UPLOADTMP")); return factory.createMultipartConfig(); } I assume that env is Spring configuration environment variables. Or just put values instead.

Categories : Java

Uploading file on change of file input
You need to sent the data as a FormData object function uploadFile(file){ var formData = new FormData(); formData.append('formData', file); $.ajax({ url: 'inc/ajax/uploadFile.php', //Server script to process data type: 'POST', data: formData, //Ajax events success: function(html){ alert(html); } }); } http://blog.new-bamboo.co.uk/2012/01/10/ridiculously-simple-ajax-uploads-with-formdata

Categories : PHP

File uploading in MVC 4
The path you are attempting to save your file to looks wrong. Try with MapPath: [HttpPost] public ActionResult Upload(HttpPostedFileBase file) { string path = Server.MapPath("~/Content/Upload"); if (file != null) { file.SaveAs(Path.Combine(path, file.FileName)); } return Content("Sucess"); } Also make sure that you have used the correct enctype attribute in your form: enctype = "multipart/form-data" instead of: enctype = "multipart/from- data"

Categories : Asp Net Mvc



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.