Firefox extension - Share common state between two or more windows - firefox

I am developing firefox extension.
Problem is that when i open second window (Ctrl + N) my extension has new state for new opened window.
If I reacts or changes on second window it never affect on first window or vice versa.
Ex
Installed extension on Firefox
first window opened. My extension proper functioning, change state, login, view data etc
then opened second. My extension goes new state I cant get previous states (first window states).
How can maintain same state between first and second or other firefox opened windows.?

Am I correct to assume you're developing a XUL overlay add-on, and not an SDK add-on?
One way to share state between windows is to use Javascript code modules. A code module will only be loaded once (unless explicitly unloaded) and therefore will expose the same data to multiple windows. Be sure to read the "Sharing objects using code modules"., However, please note that therefore when closing a window, any state associated with it and stored within the code module must be cleaned up, or would leak otherwise.
If you're using the SDK instead, your main.js module is already the equivalent of a code module. Content scripts may use message passing to store and retrieve state from your module.

Related

Selectors only work when webpage is opened in Internet Explorer

I created a login sequence and my selectors for the input email, password, click login and element exists are valid. But only when I have the Internet Explorer page open on the website I'm working with.
I did that sequence again, and I ran it, initially it worked but when I ran the hole project it broke again, I tried "repair" and "indicate", I tried to eliminate the title but nothing is working.
As far as I can see, you are using selector attribute:
"title=ACME System 1 - Dashboard"
Try using a wildcard: title='ACME System 1*', so it can work when you leave the dashboard.
This worked for me when I took those UiPath Academy courses.
In order to automate tasks within a browser with UiPath, the browser must be open. There is an activity called Open Browser that's included in the default activities for every project. You need to add this activity to the beginning of your sequence and pass in the appropriate parameters, (ie. URL, browser type) you can then pass the outputted browser variable to an attach browser sequence and execute your browser automation acivities within that.
Browser activity sceenshot
In addition, the selector that you have shared does not look like a stable selector. There may be other 'H1' elements on the screen that will cause your automation to fail. I would use the UI explorer to help you build a better, more stable selector.
Did you initially use IE to indicate screen elements and then changed the BrowserType property to use a different browser? Please share the sequence to suggest you a fix for your issue.
I would also suggest you to modify the selector to 'title='ACME System *'.
In order for selector to work the application needs to be open and the desired element needs to be available. So when you close the browser the selector disappears.
You may consider swithching to 'Modern Design Experience' and use 'Use Application/Browser' scope to make this more intuitive, and it will also automatically open the browser for you if it is closed.

parent & child browsers view got switched during automated execution by HP UFT

I am facing a strange issue with my test automation scripts when executed through HP UFT 12.01
Our AUT is a web based application developed in actimize. During my test flow, lets say at 5th step i need to invoke a popup browser (child) from my main page. The new popup browser will not have any menus or back/fwd buttons.
3 out of 10 executions, during 5th step my main browser gets refreshed to invoke the popup and when popup rendered fully, contents and views got switched now. i.e., main browser has the contents which are supposed to display in popup window (with menu bar and back/fwd buttons) and pop-up window has main page contents (without menu bar, back/fwd buttons) & state when i performed click operation.
This is strange and i could not really conclude if its browser issue or UFT issue. I have also checked with functional team and they never faced, so this is happening only through UFT execution and speculating it could be UFT issue.. any help pls?
This sounds like it could be either:
1) an actual bug in your UAT
2) a problem with QTP object identification.
If it's #2, here's some things to check. First, make sure that QTP can correctly and reliably identify the two different "browsers". (i.e. while both are on the screen, use the "Highlight in Application" button found the Object Repository window while each of the objects is selected. I would try this for both a normal run and immediately after the browsers get switched (use a break point if necessary)
If there is a problem with QTP identifying the windows incorrectly, then you might want to add additional Description properties to the test object in the OR so that it can lock onto the right one more reliably. I usually use GUISpy to spy on something on the page, then in Object hierarchy I click on the top object (the browser), then click "Copy identification properties to the Clipboard" button, then paste the results into a notepad. Find one of those properties that uniquely identifies the browser objects from anything else. Sometimes I have to use the URL property (with some REGEX magic to isolate the specific page without making it TOO specific)

How would one display a prompt after installation of an extension?

When my add-on installs it needs to prompt the user to get a username or something like that. After that it stores it and shouldn't ask again. Where would I place this prompt? install.rdf? browser.xul?
There is no explicit mechanism to run code when the extension installs - you should simply do it when your extension runs for the first time. The easiest approach would be checking whether the user name is already set up. If it is not - show the prompt.
It is not recommended to show a modal dialog, those are extremely annoying to users, especially when they suddenly appear during Firefox start-up. You should instead open your page in a tab. A slight complication: Firefox might be restoring a previous session when it starts up. If you open your page too early the session restore mechanism might replace it. So you should wait for the sessionstore-windows-restored notification, something like this should work:
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
Components.utils.import("resource://gre/modules/Services.jsm");
var observer = {
observe: function(subject, topic, data)
{
Services.obs.removeObserver("sessionstore-windows-restored", this);
var browser = window.getBrowser();
browser.loadOneTab("chrome://...", {inBackground: false});
},
QueryInterface: XPCOMUtils.generateQI([
Components.interfaces.nsIObserver,
Components.interfaces.nsISupportsWeakReference
])
};
Services.obs.addObserver("sessionstore-windows-restored", observer, true);
A final complication is that your code is probably running from a browser window overlay - meaning that there will be multiple instances of your code if the session restored contains more than one window. You probably want the code above to run only once however rather than opening your first-run page in every browser window. So you will have to coordinate somehow, maybe via preferences. A slightly more complicated but better solution would be having a JavaScript code module in your extension - code modules are only loaded once so you wouldn't have a coordination issue there.
Try using an addonlistener https://developer.mozilla.org/en/Addons/Add-on_Manager/AddonListener#onInstalling%28%29
Or by using the preferences: https://stackoverflow.com/a/958944/1360985

Problems with implementing Versions

I try to implement Versions in application that already written for Snow Leopard. It is an Document based application with SQLite storage. Each document saves as an SQLite db file.
I have implemented appropriate methods in my NSPersistentDocument subclass:
+ (BOOL)autosavesInPlace {return YES;}
+ (BOOL)preservesVersions {return YES;}
Now I have new File menu in application with "Save a Version" etc. I create new document in my app, save it, make some changes, save again.. When I entering version browser I get:
kCGErrorFailure: CGSDisplayID: App trying to enumerate [0 to CGSGetNumberOfDisplays()] instead of using CGSGetDisplayList(). Compensating...
kCGErrorFailure: Set a breakpoint # CGErrorBreakpoint() to catch errors as they are logged.
In right side of version browser in list of versions I see few versions, but they do not displayed in stack of windows. It looks like windows are in stack but completely transparent. When I clicks on any version in list I get log:
CoreData: error: (8) attempt to write a readonly database
Than if I tried to restore one of versions - version browser normally closed, no window appears and program stops responding.
I can't understand what it all can means. Is it problem in saving version or in restoring? I just have no ideas. Will be grateful for any help.
Each Core Data store is already stored on disk when the versions browser is opened. Have you looked at your overrides for creating the document, and for reading them? Are you sure none of them also edit the document? You might also want to check your awakeFromNib methods, to see that you are not writing / saving anything to a new document.
It can be difficult to debug problems when leaving the version browser. To make it easier, you can edit your current scheme, select the 'Options' tab, and check 'Enable debugging in "Browse all versions" mode'.

Start Internet Explorer 8 in a separate process using vbscript

Due to the recently added "feature" in IE8 where new windows are automatically associated with a single session, some of our code is behaving erratically.
This is because a separate app would launch a new IE window when it was activated, and once the user was finished, close the window. This worked fine in IE7 because the session information in the windows stayed separate. However in IE8, since the session is shared among IE windows, we find that the "pop up" app would corrupt the session on the first app.
I have read about the nomerge switch, so that is a workaround, but I was wondering if there was a way of working the solution into the "CreateObject" of vbscript; i.e:
Dim ieWin As Object
Set ieWin = CreateObject("InternetExplorer.Application")
Is there a way of sending parameters when calling the CreateObject function?
No, there's no way to use COM to create an IE instance that specifies this behavior (or any of the others, e.g. InPrivate, No Add-ons, etc). The only thing you can do is create an automation instance that defaults to MediumIL using the CLSID provided for that purpose. http://blogs.msdn.com/b/ieinternals/archive/2011/08/03/internet-explorer-automation-protected-mode-lcie-default-integrity-level-medium.aspx
If you have control over the web application you are loading with your IE window you can set it's session to "cookieless" (http://msdn.microsoft.com/en-us/library/aa479314.aspx) which will avoid the issues you're having with multiple instances.
The solution we ended up going with, although it's more a work around than anything else - was assigning a new url to the popped up window.
Previously, it worked as follows:
Call centre agents would be using our internal app for other duties
e.g. "http://internalsite/somepage.faces" on a day to day basis.
When they got a phone call, a third party app would fire up
"http://internalsite/customerdetails.faces". This caused the issues mentioned above.
The solution we went with:
We assigned "http://internalsite/customerdetails.faces" it's own url e.g."http://customerdetailminisite/customer.faces".
This way the call center agent could keep their main window open for other stuff and still be able to handle calls when they came in.

Resources