Use selenium IDE to change Firefox Preferences for SDK Addon testing - firefox

I am using Selenium IDE to test some behavior in my FireFox SDK Add-On. For example, I load a page and determine that the content script is executing at intended. In my plugin, I use simple-prefs to set some user defined preferences.
For example, I would like to load a page and then ensure that if a preference is changed, that the content script received the update and made the necessary changes to the page based on the new setting.
when I try to navigate with Selenium-IDE to the plugin configuration page chrome://mozapps/content/extensions/extensions.xul?type=extensions / about:addons. I am able to use Selenium to select an entry (<richlistitem />), but I cannot click any of the buttons within the entry because they are not part of the XUL dom. I have tried using Selenium to send enter, tab, clicks, double clicks to the appropriate <richlistitem /> but there is no way of interacting with the "inner part" of the item.
I have also tried going down the path of using selenium to modify entries via about:config, however, the area with all of the entires is just an XUL <treechildren /> and you have no way of targeting individual entries.
Is there a convenient way to change addon setting as part of an automated workflow with selenium-ide?

It seems you should use Selenium Web driver , by driver you can set preference

Related

Is there a way to launch userscripts directly from browser (Firefox)?

I would like to run some userscripts to backup data.
The same scripts could be used on a variety of websites.
Scripts are basically the same, only some configuration changes from one script to another (what to scrape on the page, and where to save it).
Scripts will not alter the page in any way, just read it then call some REST API with the data
I do not want these scripts to be loaded on every web page, as they won't alter them, and depending on the page there is only one I'd like to run anyway.
So is there a way to launch these scripts directly from the browser (Firefox) ? From a bookmark or something ? Basically I want to click a button and have the script run like if I was running it from the js console.
Best I found for now is the "#run-at context-menu" directive of Tampermonkey. My script appears in a TamperMonkey context menu and is run on click.
However this menu is loaded on every page (#run-at context-menu ignores the #include directive and is applied everywhere), I'm not sure of the performance consequences, and it might be inconvenient if I end up with lots of scripts.
I guess I could also modify my scripts to be run on specific pages so that they add a floating button or something. But I'd rather not modify the pages, and it would be inconvenient on pages where I'd like to have several possible scripts.
I remember using a Greasemonkey script that added options on the context menu a long while ago. Would that be possible with Tampermonkey, implementing an equivalent of the #run-at context-menu myself that would only work on some pages ?
A more native way would be best, but I'm open to options.
Basically I want to click a button and have the script run like if I was running it from the js console.
From above, I assume the userscript does not use any GM API or use #require since those are not available in JS console.
If that is the case, FireMonkey has a feature to inject script (or CSS) from the toolbar popup.
After saving a script and disabling it (so it doesn't run automatically) or enabling on sites that the script MUST run, users can select the script in the toolbar icon popup and click the button to inject the script in the active tab.
For temporary scripts, FireMonkey also has a Scratchpad that you can paste JS (or CSS) into and run on any webpage by clicking the button. FireMonkey remembers the last pasted data so that it can be reused.
Note: Except TM that alters the CSP of websites, other managers are bound by the webpage CSP.
Turns out there's a function for that: https://wiki.greasespot.net/GM.registerMenuCommand
Your script just needs to declare a function, call GM.registerMenuCommand("label", your_function), and it becomes available on click in the GM/TM menu.
Contrary to the other answer this means you can use #require.
Contrary to the #run-at context-menu this means you can use #match to only apply it to the intended websites
Notes:
GM_registerMenuCommand in TamperMonkey
Needs the #grant to use the function

How to programmatically open a website and click buttons

How to use VBScript to implement the following:
Open web browser
Load a URL in web browser after opening
List item
Click buttons in the loaded browser
Is this possible using VBScript. Any examples of code to help get me started would be beneficial. Also, my web browser is Chrome.
There is a Selenium webdriver created that works with VB.NET, VBA, and VBScript. Download and install the exe.
There are also lots of example scripts that show loading different browser types or in your case Chrome. Once loaded you just need to program what elements to navigate and click after loading your specific URL.
There might be other ways to launch and run commands against the web browser using VBScript. This is just one way.
SeleniumBasic v2.0.9.0 created by Florent Breheret and open source via git hub.
A Selenium based browser automation framework for VB.Net, Visual Basic Applications and VBScript
Script Example:
Set driver = CreateObject("Selenium.ChromeDriver")
driver.Start
WScript.Echo "Click OK to quit"
driver.Quit
Here is the official SELENIUM page: selenium main page
UPDATE:
Here is a second option that is based on the same concept , but implemented a little different. I am not sure it meets your needs , but thought I would include it as another example.
VBS WebDriver
Examples using the VBS WebDriver which is intended to provide a simple binding for Selenium 2. The bindings include the full functionality of Selenium 2 (WebDriver).
If you press F12 in Internet Explorer you can lie about what browser you are using. Use the compatibility tab (a downward direction play icon) and enter your UA string for a browser they support.
See https://msdn.microsoft.com/en-us/library/ms537503(v=vs.85).aspx

how to show a preference page using mozilla Add-on SDK?

I am developing an extension using the Addon-SDK. I want to show a preference page in order to get some users' configuration.
simple-prefs is too simple to use as its supported data type is so limited.
In a XUL app, I can use the following
<em:optionsType>3</em:optionsType>
<em:optionsURL>chrome://myaddon/content/options.html</em:optionsURL>
to set my preference page.
I found
the XUL migration guide
which says:
This is provided only as a migration aid, and it's still a good idea to port XUL windows to HTML.
How then can I make an HTML preference page ?
Many thanks!
I solved it in the following way:
Use simple-prefs with the preference type set to control. On its click event, open a page using the tab module, then use simple-storage to store data.
That's it!

Creating options page for BHO

I am creating an IE browser extension using BHO,
I would like to create an option page like the on chrome or firefox.
I want this page to be accessible using manage add-ons page like it works in chrome and firefox. Is it possible? how do I do that?
I am using visual studio ATL and c++
Your Best Best is adding Context Menu or Tools Menu Item.
Basically There is no Standard IE Options Dialog that you can merge your stuff into.
you are gone have to have your own dialog.
as a warning starting with IE10 and IE11. your IE-Addons (BHO,Menu,Toolbar,DeskBank) will not have any access to registry or file system.
if you need to save some stuff. you are gone have to probably create a broker process.
for instance you need to create a windows service that listen on a socket (maybe some random port) and yo you can communicate with it from your options dialog on what to save and what to read.
Inserting context Menus into IE
Inserting Menu Options

Modify contents of Firefox download dialog from add-on kit

I'd like to be able to add an option to the download dialog that pops-up in Firefox when starting a file download. Is it possible to do so using the new add-on SDK or do I have to do it the old way?
edit: Obviously, if the new option is selected, I need a way to know it and execute code based on it.
That's something you would use XUL overlays for. I guess that the dialog you are talking about is chrome://mozapps/content/downloads/downloads.xul - the download manager. AFAIK doing this isn't possible with the Add-on SDK, it only provides the most common UI integration points. You could create a traditional extension however, it can overlay any dialog.
There is no existing module that will help you that I know of, so you would have to create one, or wait for one to be made by someone else. But the main idea to extending browser UI is simple, and goes like this:
When the addon is loaded, scan for open windows of the type that you wish to extend.
extend the open windows by adding xul elements and javascript to the page.
listen for newly opened windows, and test that they are the type that you are looking for once they open
extend newly opened windows while your addon is active
Clean up after yourself when windows close or when your addon is disabled/uninstalled.
The last step is the most important and never matter with old school extensions which were not restartless.
Some for the built-in modules that you can look at that do this are the widget module, the context menu module, and the hotkeys module, all of which you can find here.
I've made a couple myself which are the toolbar button module, the xulkeys module, the menuitems module, and a few others, all of which you can find here.
Recently I wrote an extension do the same things. A bootstrap extension, not using addon-sdk.
I already submit it on AMO, but wait for review
https://addons.mozilla.org/en-US/firefox/addon/download-dialog-tweak/
And the source code
https://github.com/muzuiget/download_dialog_tweak

Resources