My add-on involves the user interface, and so to test it I decided to simply have a html page which will load and the tester can follow some instructions on the page.
Here is an example of loading the page:
exports["test interaction"] = function(assert, done) {
require("sdk/tabs").tabs.open({
url: "./tests/test-page.html",
onClose: function(tab) {
assert.pass("Done page test");
done();
});
};
However, after about 16 seconds the tests will always fail with two error messages:
fail:
Timed out (after: START)
and
fail:
Should not be any unexpected tabs open
Furthermore, and more importantly, my addon does not work at all using cfx test, while it works using cfx run on the same test pages.
Is there a way to load some HTML testing pages using cfx test?
Adding tab.close() before done() will fix the "Should not be any unexpected tabs open" error.
I think what you need to do is listen for messages from the tab you opened and then manually close the tab. You can send messages by injecting a content script into the tab, and communicating back. Something like:
page is opened
page runs some tests, and on completion or error, sends data via window.postMessage to the content script
the content script relays these results back to the tab worker
the tab worker closes the tab
Related
my gulp file:
var gulp = require('gulp');
var browserSync = require('browser-sync').create();
//server
gulp.task('run', function() {
browserSync.init({
proxy: "http://localhost/test-site/"
});
gulp.watch("./*.php").on('change', browserSync.reload);
});
when running gulp run from terminal it's fire the browser and shows the page as expected but without the "connected to browserSync" msg and when saving some changes the gulp watch fires and the terminal shows [BS] Reloading Browsers... but the browser not refreshing the page
now on the other hand when i'm changing the file extension to "html" and gulp watch to gulp.watch("./*.html").on('change', browserSync.reload);
it all work as expected: when running the task it's fire the browser, this time with the "connected to browserSync" msg and when saving some changes it refresh the page.
early today i did manage to refresh the page on php file change but i lost it and can't find the reason why it's not working any more, i couldn't find any post about it on google
any ideas ?
Create reload and projectPHPWatchFiles objects
var projectPHPWatchFiles = './**/*.php'; // Path to all PHP files.
var reload = browserSync.reload; // For manual browser reload.
Then in your watch process, add this
gulp.watch( projectPHPWatchFiles, reload); // Reload on PHP file changes.
And it will start refreshing on changes.
If you use WordPres, I have a handy repo for WPGulp which takes care of all this.
I am using Jetty server with embedded web app. However, whenever I hit any resource which is not present it serves a default page which shows a message "Powered by Jetty".
This page is being served from org.eclipse.jetty.server.handler.DefaultHandler.handle.
I want write a custom handler for this, however while trying to register custom Handler in jetty.xml file, I am getting syntax exception and server doesn't start anymore.
I was able to resolve this issue by doing some tweaks along with changes mentioned in Deactivate Jetty's default 404 error handler.
I'm trying to test some Joomla!'s output from phpstorm by using the inner "test RESTful web services" as known as "Rest client".
Basically the URL I would like to test asks for the component to load and task to perform. The loaded model by the controller reads the body of the POST request for performing some task.
To test it, I set my "Rest client" up: POST option, URL and body content are properly filled and then I run my request. Unfortunately, Joomla! seems not to read my URL parameters and because of this the home page is returned instead of loading the component, view and running the requested task.
Here is a snapshot of my settings:
Has anybody bumped into this issue? Any suggestion?
I did it: I placed a new header item Content-Type to application/x-www-form-urlencoded and it worked smoothly.
I found an interesting issue when attempting to login using PhantomJS. I'm at a loss as to why it's actually occurring.
Basically you start up a remote debugger like so:
/usr/local/bin/phantomjs --web-security=no --remote-debugger-port=13379 --remote-debugger-autorun=yes /tmp/test.js
Within the remote debugger:
> location.href = "https://www.mysite.com/login"
> $('input[name="username_or_email"]').val('blah#email.com')
> $('input[name="password"]').val('wrongpassword')
> $('button[type="submit"]').submit()
Doing this in Chrome will give me the correct "wrong password" message after the XHR request, whereas using phantomjs gives me a generic error as no cookie is sent with phantomjs (I examined the headers).
I'm quite confused on why phantomjs doesn't send the cookie with the POST request. Does anyone know how we can get phantomjs to send the cookie with ALL requests as it should? Setting a cookie-file doesn't make any difference either.
Ok, this seems to be something related with session cookies and not regular cookies.
Heres a huge thread on the developer in charge of the cookies feature of phantomjs and some guys with the same issue as yours.
https://groups.google.com/forum/#!msg/phantomjs/2UbPkIibnDg/JLV9jBKxhIQJ
If you dont want to skirm through the entire file, basically:
Phantomjs behaves like a regular browser, and it deletes all session cookies when browser closes, in your case, when your script execution ends.
So, even if you set the --cookies-file=/path/to/cookies.txt option you will only store regular cookies on it, for subsecuent executions.
There are two possible approaches for you. One, is to make all requests within the same script, or the other is to store and restore the cookies manually.
On the thread there are a couple of functions that you can use to do this.
function saveCookies(sessionCookieFile, page) {
var fs = require("fs");
fs.write(sessionCookieFile, JSON.stringify(page.cookies));
}
function restoreCookies(sessionCookieFile, page) {
var fs = require("fs");
var cookies = fs.read(sessionCookieFile);
page.cookies = JSON.parse(cookies);
}
var page = require('webpage').create();
And, if everything fails...
You could download source code and recopile phantomjs
You will need to edit src/cookiejar.cpp and remove or comment purgeSessionCookies();
Hope, this helps.
I am trying to setup ember.js with QUnit to write integration tests.
Following the directions on http://emberjs.com/guides/testing/integration/ I have:
document.write('<div id="ember-testing-container"><div id="ember-testing"></div></div>');
App.rootElement = '#ember-testing';
App.setupForTesting();
App.injectTestHelpers();
module("Integration Tests", {
setup: function() {
App.reset();
}
});
test("root lists first page of posts", function(){
visit("/").then(function() {
equal(find(".post").length, 5, "The first page should have 5 posts");
// Assuming we know that 5 posts display per page and that there are more than 5 posts
});
});
However when I run QUnit I get the following error:
Assertion failed: You have turned on testing mode, which disabled the
run-loop's autorun. You will need to wrap any code with asynchronous
side-effects in an Ember.run
This assertion error is triggered because I am making a http request in the app initializer to check if there is a current user session. This returns a 401 error if there is no valid user. (If I force the app to always return 200 for this request, this assertion error does not occur and the tests continue as expected).
I believe the app and API is behaving correctly by returning a http error for an invalid user, and I don't want to change to response to a 200 just to get my tests working. What do I need to do to get ember and QUnit to handle a http error and assertion? From what I've read I need to wrap something with Ember.run, but I can't figure out what.
Your unit and integration tests should ideally run in isolation from external resources (like an HTTP API), so mocking HTTP requests is the easiest pattern.
To get truly full-stack smoke testing, you'll want to exercise the app with browser automation tools like PhantomJS.