Selenium server causing firefox to crash - firefox

Current Problem
I'm running automated selenium scripts every night. I just noticed that Firefox 38 is crashing and nothing is being listed in the firefox logs.
Clicking "Restart" firefox means that the tests run fine.
Is there anyway to debug and find what is going on with firefox crashing?
Firefox error report: https://crash-stats.mozilla.com/report/index/fdba810a-1980-45ea-b64b-0e8c62150604
Current Solution
Since "Restart Firefox" is already selected, using xdotool this button is clicked by sending the enter key. (note: set appropriate display, export DISPLAY=:1). I am executing a bash script from cron that contains the following section of code:
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
export PATH=$PATH:/usr/lib/jvm/java-7-openjdk-amd64/bin
export DISPLAY=":99"
java -jar /home/m/selenium-server-standalone-2.45.0.jar -htmlSuite "*firefox" "http://www.google.com" "selenium/2_Suite.html" "test_results/2_results.htm" &
sleep 5
xdotool key KP_Enter
wait
Update
Except for simulating the enter key to restart firefox and run the tests, I'v disabled all future updates on my headless automated testing VM using https://support.mozilla.org/en-US/questions/1003777 .

Selenium works on FireFox version 33.0 or below. Do not update your fire fox, selenium will not work on Firefox 36.0.

I had this issue with the .NET bindings. I never solved it, but I have a workaround.
I found that the issue didn't occur when instantiating the Selenium Firefox driver from an existing profile, so my workaround was to create a blank profile, launch Selenium's Firefox driver using a temporary copy of that profile; then at the conclusion of the test, delete the temporary copy.
In this way, you're still using a reasonably-fresh profile, and importantly the same profile, for every test.
The Selenium documentation has instructions on launching the Firefox driver with an existing profile.

Related

Close window through Capybara

I am trying to launch the browser for the capybara automation. The browser is auto populating a "Error window" (non-browser window).
I need to "close/click ok" on the window to open the browser. I tried to handle this popup with the "AutoIT" executable file. When i run the AutoIT file manually, the executable file handles it successfully.
I am not able to execute through the capybara script. The code is as below
ses = Capybara::Session.new(:selenium)
IO.popen('c:\ruby\handler.exe') #- Tried this step to execute AutoIT .exe file before visit url step.
No luck here. The popup appears only when referencing with the object.
ses.execute_script "window.close()" #- Tried this step to close the window with the ses object. no luck in this too.
ses.visit "https://google.com"
Is there a way to close the window programmatically?
It seems that you should be able to register a custom selenium driver using the Chrome browser and specify the command-line option to disable all extensions, with the following driver registry code:
Capybara.register_driver :selenium do |app|
Capybara::Selenium::Driver.new(app, :browser => :chrome,
:switches => %w[--disable-extensions])
end
ses = Capybara::Session.new(:selenium)
...
I put this together using information here and the list of available command line options here (I did not test this myself though).
There are a few approaches to a popup error like that:
1) The easiest one is to do your approach - execute an autoit script before calling capybara to visit the site that results in the error popping up. You should ensure that the autoit script you are executing waits for the window to appear before trying to close it (see: https://www.autoitscript.com/autoit3/docs/functions/WinWait.htm for reference).
2) You could execute another ruby script/thread (keep in mind threading in ruby is a bit complicated) that would execute the autoit script in the background (in a loop) and wait for a succesfull response.
3) You could try to disable whatever is causing the error to pop up in your browser.
I will be able to provide some code following approaches 1 and 2 in a few hours if you will still have problems solving the issue.
The error Failed to load Extension. Loading of unpacked extensions are disabled by administrator. indicates that your system was set-up to disable extensions with Chrome. So even if you manage to close it, you probably won't be able to automate Chrome with Selenium since it needs to start Chrome with the driver as an extension.
Your best chance to make it work is probably to disable the restriction or to add the extension to the white list.
Here is a link about this issue:
https://bugs.chromium.org/p/chromedriver/issues/detail?id=639

Firefox addon SDK error: Unable to Remove from Inner-Toolbar

After hours and hours trying to get things working, I have this error in my console:
[CustomizableUI] Widget action-button--myAddonID-misspelutton not found, unable to remove from inner-toolbar-myAddonID-the-title-of-my-addon1 CustomizableUI.jsm:171
So, the addon's widget id is misspelled somehow and stuck somewhere. The term does not appear in any of my code.
Details: I originally built this addon using XUL overlays, and am rebuilding it with the Firefox AddOn SDK. I think (but I'm not sure) this problem happens like this: I installed my signed addon from the Firefox Addon Repo, and then I used jpm post --post-url http://localhost:8888/ to install it into Firefox Developer Edition running the Extension Auto-Installer.
In my code I had this, but I've removed it and everything that pertains to it:
const { CustomizableUI } = Cu.import('resource:///modules/CustomizableUI.jsm', {});
[update]
I have also tried this: uninstall the addon, enter customization mode and choose "Restore to Defaults" which resets all the toolbars to default. Then I exited Firefox and restarted it. When I run jpm to install the addon, the error code persists.
Funny thing also is this: when I view the button using the toolbox inspector, it shows the #id of that button just like in the error.
With that said, how do I resolve the problem without creating a new firefox profile?
The 'widget' module has been deprecated due to a number of performance and usability issues, and has been removed from the SDK as of Firefox 40. Please use the 'sdk/ui/button/action' or 'sdk/ui/button/toggle' module
https://developer.mozilla.org/Add-ons/SDK/High-Level_APIs/ui
https://developer.mozilla.org/Add-ons/SDK/Low-Level_APIs/ui_button_action
https://developer.mozilla.org/Add-ons/SDK/Low-Level_APIs/ui_button_toggle
Something was "jammed" in the profile.
I knew this after I removed all code relating to customizableUI, then uninstalling the addon and then using "Restore Defaults" in the customization panel, restarting Firefox and reinstalling the addon, but the problem persisted.
So instead of using this with my existing profile:
jpm post --post-url http://localhost:8888/
I used this to run it on a fresh clean one:
jpm run --binary "C:\Program Files (x86)\Firefox Developer Edition\firefox.exe"
(I was using post instead of run because I run multiple instances of Firefox and did not want run to cause them to exit; but adding --binary and the path to Firefox dev did the trick )
In a fresh profile everything works just fine, even with the code utilizing CustomizableUI. There are no errors relating to that in the console.

How to debug firefox extension after cfx run?

I want to debug my firefox extension. I set
javascript.options.showInConsole = true
devtools.chrome.enabled: true
devtools.debugger.remote-enabled: true
run in sdk console cfx run, after that i go to Web Developer -> Browser Toolbox get incoming connection and i see my extension main.js. But after that, the code in main.js already been executed. How to debug it after cfx run?
also, two other things might be messing with your approach:
1) when you use cfx run, that by default creates a new profile on every run, so any settings that you have changed will not persist. to avoid this, you need to specify a profile directory with --profiledir=DIR (warning: don't use your main profile).
2) if the addon main.js code has already run by the time you open the debugger, you should start firefox manually, setup the debugger, and then drag the addon xpi into a tab.
Bug 899054 - [Meta] Implement an Add-on Debugger
this is really close to landing (the UI bits in bug 911098 are in m-c), so if you grab a Nightly tomorrow, or the day after, it should be in there, and might just work (for some undefined value of "work").

How to suppress the "checking compatibility of add-ons" dialog in Firefox with Selenium?

Since updated to Firefox 12, every time I launch Firefox with a particular profile with Selenium (in python and Mac OS 10.7) it pops up the "checking compatibility of add-ons" dialog, and sometimes this dialog would stay up forever and I have to force-quit it. After forcing quit it, a new instance of the Firefox would continue to launch and finishes the rest of the Selenium script successfully though.
I have tried setting extensions.checkCompatibility to false. This fixed it if I launched Firefox normally, but not if I launch it with Selenium. Any idea on how to suppress this dialog? Thanks!
This dialog is shown only once whenever Firefox is updated. The reason it is shown each time for you is probably that Selenium creates a new profile each time. If you set extensions.lastAppVersion preference to "12.0" (or whatever the current Firefox version is) then Firefox will no longer think that it has been updated and won't show this dialog. However, it should be easier to add a extensions.showMismatchUI preference and set it to false, this will suppress this dialog (but not the other upgrade actions).
Side-note: extensions.checkCompatibility preference no longer does anything starting with Firefox 3.6, it is a version-specific preference in the current Firefox versions. So you would have to set extensions.checkCompatibility.12.0 preference instead. That disables compatibility checking for extensions completely however, not just the dialog you are concerned about.
I have tried setting extensions.checkCompatibility to false. This fixed it if I launched Firefox normally, but not if I launch it with Selenium.
The reason it won't when you launch it with Selenium is the Firefox Driver will create a temporary profile in the temporary files directory, slowing down tests and taking up unnecessary space.
Create a profile for your test purposes and set what you need. Full instructions to create the SeleniumProfile can be found at https://support.mozilla.org/en-US/kb/profile-manager-create-and-remove-firefox-profiles
In Java I have the following:
protected WebDriver createFirefoxDriver() {
File proFile = new File("C:\\Users\\<username>\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\xxxxxx42.SeleniumProfile");
FirefoxProfile ffProfile = new FirefoxProfile(proFile);
WebDriver ffDriver = new FirefoxDriver(ffProfile);
return ffDriver;
}
Do this to remove the "checking for addon's compatibility" Dialog. This is based on the Windows operating system..
Create a temporary FF Profile and start the server with that profileas shown below.
java -jar selenium-server-x.x.x.jar -firefoxProfileTemplate "/path/to/the/temp/profile"
Now use the following code.
import com.thoughtworks.selenium.*;
public class Test {
public static void main(String ar[]) {
Selenium sel = new DefaultSelenium("localhost", 4444, "*firefox", "http://www.google.com/");
sel.start();
}
}
Now in the Run command type "%TEMP%" and you can see there a folder with same name as the selenium session. Copy the folder contents and replace them with your temp profile Contents.
Follow the steps below to remove the Addons compatibility.
1 . Create a new FF Profile
2 . Set the FF Profile as per required settings
3 . Just run a sample program of selenium such that it invokes firefox.
4 . Now you can find a folder with the same name as Selenium Session created somewhere in your sytsem. ( Most probably in the directory where the Temporary Content is saved)
5 . Copy the folder contents and replace them with the newly created profile.
Now you can use the newly created profile whenever required. Whenever FF is updated , always check whether the existing addons are compatible with the Existing version by once invoking firefox with the Profile.

How to stop Chrome from prompting for search engine during Selenium Tests

When I run selenium tests that use Chrome as the browser, the tests hang. The reason is that, since the browser is running as the SYSTEM user, it continually pops up Chrome's prompt for search engine choice. If I run the selenium server interactively, and as a logged-in user select a search engine, it will enable the tests to run. However, the next time I run the tests I get the prompt.
Is it possible to avoid this behavior?
This happened with me on Firefox as well. What i did was run Firefox as administrator and answered all the prompts that one time.
Next time when I ran the selenium scripts, those modals did not show.
Not sure if this would directly relate to Chrome, but definitely worth a try.
Let me know if it worked?
I can suggest you 2 options:
a. Open Chrome with a specific profile.
b. Write and run setup routine before any tests, which will open browser settings page and do whatever you need too:
from selenium.webdriver import Chrome
SETTINGS_PAGE_URL = 'chrome://settings/browser'
SEARCH_ENGINE_DROPDOWN_ID = 'defaultSearchEngine'
SEARCH_ENGINE_CHOICE_XPATH = '//option[text()="Google"]'
browser = Chrome()
browser.get(SETTINGS_PAGE_URL)
dropdown = browser.find_element_by_id(SEARCH_ENGINE_DROPDOWN_ID)
option = dropdown.find_element_by_xpath(SEARCH_ENGINE_CHOICE_XPATH)
option.click()
browser.get('http://wherever.you/need/to/go/next/')
I'd use option a.

Resources