i have some problem in firefox add-on/jetpack.
There its the event listener:
tab.on('deactivate', cleardata);
I need delete the deactivate event listener.
I guess i need something like that
tab.removeListener('deactivate', cleardata);
But something was worng in the code, dont stop the listener.
Grettings, Marcos.
The following snippet works as expected for me:
var count = 0;
function myListener(tab) {
count++;
console.log("Event number " + count);
if (count == 3)
{
console.log("Removing listener after third event");
tab.removeListener('deactivate', myListener);
}
}
function setupTabTest(tab) {
tab.on('deactivate', myListener);
}
(You need to call setupTabTest with some existing Tab object.)
Does this code work for you? If so, please give more information about the part of your code which is not working. Try to reduce it to the simplest example which illustrates the error.
Related
For some time now, our team has been using the Protractor/Jasmine combo in order to do E2E testing and it has worked out great for us.
Recently, I've been assigned the task of improving the logging and have noticed 2 areas in our code where the logging could be improved.
One of these areas is with using browser.wait(). We're currently using the method in the form of browser.wait(condition, timeOut) and excluding the third parameter which is a message to be written to the console in case of a failure.
I decided to comb the code and insert a message into each of these methods and the result has been OK. Although the code works, I'm wondering if there is a more elegant way of doing this.
I'm currently saving the XPath of whatever element I'm waiting on and then if that fails, displaying a message in the form: getWait() timeout due to <element_name> { XPath = <element_XPath> } being not visible or enabled such that you can click it. The pattern changes if we're using isPresent(), elementToBeClickable(), visibilityOf(), etc.
Is there a way of getting the current context of the code I'm executing when browser.wait() is executed? Can I instead display the element or more information on what caused the timeOut?
Let me know if I can clarify further. Thanks
Even I came faced the same problem when using browser.wait where it won't show any detailed log on time out. So what I have done is, I created a wrapper class for waitHandling and added failure messages based on the wait type. Kindly have a look at below code.
var browserWaitHandler = function () {
var expectedConditions = protractor.ExpectedConditions;
var defaultWaitTime = 5000;
this.waitForElementPresent = function (_element,customWaitTime) {
return browserWait(expectedConditions.presenceOf(_element),customWaitTime,"Wait timeout after waiting for element to be Present with locator "+_element.locator().toString());
};
this.waitForElementVisible = function (_element,customWaitTime) {
return browserWait(expectedConditions.visibilityOf(_element),customWaitTime,"Wait timeout after waiting for element to be Visible with locator "+_element.locator().toString());
};
this.waitForElementClickable = function (_element,customWaitTime) {
return browserWait(expectedConditions.elementToBeClickable(_element),customWaitTime,"Wait timeout after waiting for element to be clickable with locator "+_element.locator().toString())
};
this.waitForElementContainsText = function (_element,expectedText,customWaitTime) {
return browserWait(expectedConditions.textToBePresentInElement(_element,expectedText),customWaitTime,"Wait timeout after waiting for element to Contain text as "+expectedText+" with locator "+_element.locator().toString())
};
var browserWait = function (waitCondition,customWaitTime,timeoutMessage) {
return browser.wait(waitCondition,customWaitTime | defaultWaitTime,timeoutMessage);
};
};
And also in protractor we have a method called locator() which can be used with ElementFinder and ElementArrayFinder objects to get the locator that is used to find the element.Refer below example code,
var loginButton = element(by.buttonText("Login"));
console.log("Locator used for login button is:"+loginButton.locator().toString());
*OUTPUT:*
Locator used for login button is:by.buttonText("Login")
I've been having this issue for a while and can't figure it out. Basically I'm trying to trigger an Angular Modal if there is one person in the 'Room', and remove it when another person comes into that 'Room'. The problem I'm having is that the 'socket.in(room).emit('join', room)' is being fired twice on one connect which is freezing the modal. Any ideas would be greatly appreciated. I can post more code if I need to.
io.sockets.on('connection', function (socket) {
initcount += 1;
if (initcount % 2 === 1) {
roomcount += 1;
room = roomcount.toString();
roomList[room] = {user1: socket.id};
} else {
roomList[room].user2 = socket.id
}
socket.join(room);
socket['room'] = room;
socket.in(room).emit('join', room) //being triggered twice and freezing.
...
For future reference this was occurring because I was setting my angular controller in both my HTML and under my $routeProvider. This was then triggering everything twice.
The test can be found here. I would like to be able to pass my plugin a new option string of 'false' and have my timer stop. http://www.jsfiddle.net/j78nk/2/
There is no element with the class gallery2 on that page, so pressing the button won't do anything.
Also, you are not checking the set options, only the defaults. And you return right away, before you do anything:
if (!defaults.running) {
return;
console.log('timer is inactive');
}
That code needs to be:
if (!options.running) {
console.log('timer is inactive');
return;
}
I've build a livesearch with the jQuery.ajax() method. On every keyup events it receives new result data from the server.
The problem is, when I'm typing very fast, e.g. "foobar" and the GET request of "fooba" requires more time than the "foobar" request, the results of "fooba" are shown.
To handle this with the timeout parameter is impossible, I think.
Has anyone an idea how to solve this?
You can store and .abort() the last request when starting a new one, like this:
var curSearch;
$("#myInput").keyup(function() {
if(curSearch) curSearch.abort(); //cancel previous search
curSearch = $.ajax({ ...ajax options... }); //start a new one, save a reference
});
The $.ajax() method returns the XmlHttpRequest object, so just hang onto it, and when you start the next search, abort the previous one.
Assign a unique, incrementing ID to each request, and only show them in incrementing order. Something like this:
var counter = 0, lastCounter = 0;
function doAjax() {
++counter;
jQuery.ajax(url, function (result) {
if (counter < lastCounter)
return;
lastCounter = counter;
processResult(result);
});
}
You should only start the search when the user hasn't typed anything for a while (500ms or so). This would prevent the problem you're having.
An excellent jQuery plugin which does just that is delayedObserver:
http://code.google.com/p/jquery-utils/wiki/DelayedObserver
Make it so each cancels the last. That might be too much cancellation, but when typing slows, it will trigger.
That seems like an intense amount of traffic to send an ajax request for every KeyUp event. You should wait for the user to stop typing - presumably that they are done, for at least a few 100 milliseconds.
What I would do is this:
var ajaxTimeout;
function doAjax() {
//Your actual ajax request code
}
function keyUpHandler() {
if (ajaxTimeout !== undefined)
clearTimeout(ajaxTimeout);
ajaxTimeout = setTimeout(doAjax, 200);
}
You may have to play with the actual timeout time, but this way works very well and does not require any other plugins.
Edit:
If you need to pass in parameters, create an inline function (closure).
...
var fun = function() { doAjax(params...) };
ajaxTimeout = setTimeout(fun, 200);
You will want some kind of an ajax queue such as:
http://plugins.jquery.com/project/ajaxqueue
or http://www.protofunc.com/scripts/jquery/ajaxManager/
EDIT:Another option, study the Autocomplete plug-in code and emulate that.(there are several Autocomplete as well as the one in jquery UI
OR just implement the Autocomplete if that serves your needs
I'm using Flex in Flash Player 10 on Windows, using FileReference to load a file into memory, as below.
My issue is that when a file is locked by Windows, my FileReference is not giving me any feedback that the file is inaccessible--it simply never dispatches any events after my calling load().
Does anyone have insight into how to tell that Flash Player is unable to open the file?
var fileReference:FileReference = new FileReference();
private function onClick():void {
fileReference = new FileReference();
fileReference.addEventListener(Event.SELECT, onSelect);
fileReference.addEventListener(Event.COMPLETE, onComplete);
fileReference.addEventListener(Event.CANCEL, onOther);
fileReference.addEventListener(IOErrorEvent.IO_ERROR, onOther);
fileReference.addEventListener(ProgressEvent.PROGRESS, onOther);
fileReference.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onOther);
// I've tried adding all of the other declared events
// for FileReference here as well
fileReference.browse();
}
private function onSelect(event:Event):void {
trace(fileReference.name);
try {
fileReference.load();
} catch (e:Error) {
trace(e);
}
}
private function onComplete(event:Event):void {
trace(fileReference.data.length);
}
private function onOther(event:Event):void {
trace("other:" + event.toString());
}
A possible (dirty) workaround might be to wait for -let say- 10 seconds, and suppose that the file isn't available if no event has triggered then.
Using a setTimeout (and clearing it with clearTimeout in your COMPLETE and *_ERROR events handlers) might do the trick.
I'll be glad if someone could come up with a nicer solution, though.
EDIT: Of course you might want to listen to HTTP_STATUS event (waiting for a 202 answer - if I understood this documentation correctly) rather than waiting for COMPLETE or *_ERROR.