console.log shows nothing in FF add-on builder - javascript

I have following problem: No log pessage shows me in every console (builder's console absolutely useless - nothing happened at all when I click, built-in FF console shows every info about installing, uninstalling etc, Firebug shows nothing).
I used console.log(), console.error() without success.
On about:config page is every logLevel's set to 'all' and devtools.errorconsole.enabled is also true.
Please help me, I'm desperate :-(
Thank you.
Kamil
PS: log window is bellow. There are 3 css errors (by default 'cause I don't include any css file - it's something about expected declarations and skipped to next declaration). Program code is simple console.log('test') or console.error('test') inside or outside exports.main = function().
17:34:52.086 GET https://builder.addons.mozilla.org/get_latest_revision_number/1127553/ [HTTP/1.1 200 OK 207ms]
17:34:52.086 GET https://builder.addons.mozilla.org/package/check_latest_dependencies/1835317/ [HTTP/1.1 200 OK 215ms]
17:34:52.088 POST https://builder.addons.mozilla.org/xpi/prepare_test/1835317/ [HTTP/1.1 200 OK 805ms]
17:34:52.862 "XPI delayed ... try to load every 2 seconds" ide-min.js:1
17:34:53.919 GET https://builder.addons.mozilla.org/xpi/test/2dnzeahpy6adc/ [HTTP/1.1 200 OK 1494ms]
17:34:53.865 "installing from /xpi/test/2dnzeahpy6adc/" ide-min.js:1
17:34:54.863 "request is running" ide-min.js:1
17:34:56.308 Očakávaná deklarácia, ale bolo nájdené '['. Preskočené na ďalšiu deklaráciu. latest
17:34:56.309 "Add-on installed" ide-min.js:1
17:34:56.326 Chyba pri spracovaní hodnoty pre 'opacity'. Deklarácia vynechaná. latest
17:35:00.337 Chyba pri spracovaní hodnoty pre 'top'. Deklarácia vynechaná.

You have to change the logging level, which by default is error, either globally or for specific extensions.
See the related documentation.

Related

Capture browser console logs with capybara

I need to capture the console logs (category: info) of a browser using Ruby & Capybara. Until now I have tried using driver.manage.logs.get(:browser) or (:client) but, using this, the result is not what I want. It gives out the interaction results between selenium and browser where I can see my javascript statements sent for execution, but the resulting output fails to get captured.
Whether or not logs are available when using selenium depends on what browser you are using with Selenium. If you were using Firefox you'd be out of luck since it doesn't support the log retrieval API, however since you're using Chrome they are accessible. The issue you're having is that, by default, only WARN or ERROR level logs are captured. You can change this in the driver registration through the loggingPrefs capability
Selenium 3
Capybara.register_driver :logging_selenium_chrome do |app|
caps = Selenium::WebDriver::Remote::Capabilities.chrome(loggingPrefs:{browser: 'ALL'})
browser_options = ::Selenium::WebDriver::Chrome::Options.new()
# browser_options.args << '--some_option' # add whatever browser args and other options you need (--headless, etc)
Capybara::Selenium::Driver.new(app, browser: :chrome, options: browser_options, desired_capabilities: caps)
end
Selenium 4
Capybara.register_driver :logging_selenium_chrome do |app|
options = Selenium::WebDriver::Chrome::Options.new
options.add_option("goog:loggingPrefs", {browser: 'ALL'})
browser_options = ::Selenium::WebDriver::Chrome::Options.new()
Capybara.register_driver :chrome do |app|
Capybara::Selenium::Driver.new(app,
capabilities: options,
browser: :chrome)
end
end
and then specify to use :logging_selenium_chrome as your driver
Capybara.javascript_driver = :logging_selenium_chrome # or however else you're specifying which driver to use
which should then allow you to get the logs in your tests with
page.driver.browser.manage.logs.get(:browser)
Thomas Walpole answer is correct but it seems that nowadays if you are using chrome as your driver you should use
Selenium::WebDriver::Remote::Capabilities.chrome( "goog:loggingPrefs": { browser: 'ALL' } )
Notice goog:loggingPrefs instead of loggingPrefs only with this solution i was able to get console.log printed in the log.
Took me a while and got it from here https://intellipaat.com/community/5478/getting-console-log-output-from-chrome-with-selenium-python-api-bindings after several frustrating attempts.
November 2022 update, use:
page.driver.browser.logs.get(:browser)
Not sure that this is what you want, but take a look at https://github.com/dbalatero/capybara-chromedriver-logger.
It helps me identify the problem with dynamic modules import(''). Works both locally and in Github Actions / Circle CI by displaying failed loads of assets (which i believe outputs as console.error).

How do I recover the "text" from the page originating the alert, esp **after** the human user has *clicked* [dismiss] on the page's **alert**?

Basically, when an alert is popped up in javascript, I can dismiss() it from python perfectly OK, by calling selenium.webdriver.common.alert.Alert(browser).dismiss().
However, if the "browser user" dismisses the alert by clicking [OK] (on screen) with their mouse, then the browser alert gets "Lost in Space" the body.text can no longer be accessed from python.
So... How do I recover the "text" from the page originating the alert, esp after the human user has clicked [dismiss] on the page's alert?
Here are the hints and a script to demonstrate the problem...
FYI: The objective of the originating code is it allow the browser user intervene on screen in testing and manually response to specific alerts.
#!/usr/bin/env python
import os,sys,time
import selenium.webdriver
import selenium.webdriver.support.expected_conditions
print dict(python=sys.version,selenium=selenium.__version__)
path=os.path.join(os.getcwd(),"hello_worlds.html")
url="file:///"+path
open(path,"w").write("""<HTML>
<HEAD><TITLE>Head Title</TITLE></HEAD>
<BODY><H1>Hello, worlds!</H1></BODY>
</HTML> """)
browser=selenium.webdriver.Firefox()
browser.get(url)
body=browser.find_element_by_tag_name("body")
print "BODY:",body.text
try:
for enum,world in enumerate("Mercury Venus Earth Mars Asteroids Jupiter Saturn Uranus Neptune".split()):
if "Earth" in world: world+=": So do MANUALLY dismiss! {Click [OK] now!!!}"
else: world+=": AUTO PILOT... please DONT dismiss! {done via selenium.dismiss()!}"
browser.execute_script('alert("Hello, %s!")'%world)
if selenium.webdriver.support.expected_conditions.alert_is_present():
print selenium.webdriver.common.alert.Alert(browser).text
time.sleep(enum+5)
if "Earth" not in world: selenium.webdriver.common.alert.Alert(browser).dismiss()
print "BODY:",body.text
finally:
browser.quit()
Output: (Crash at Earth)
{'python': '2.6.6 (r266:84292, Aug 18 2016, 15:13:37) \n[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)]', 'selenium': '2.53.2'}
BODY: Hello, worlds!
Hello, Mercury: AUTO PILOT... please DONT dismiss! {done via selenium.dismiss()!}!
BODY: Hello, worlds!
Hello, Venus: AUTO PILOT... please DONT dismiss! {done via selenium.dismiss()!}!
BODY: Hello, worlds!
Hello, Earth: So do MANUALLY dismiss! {Click [OK] now!!!}!
BODY:
Traceback (most recent call last):
File "./js_alert.py", line 37, in <module>
print "BODY:",body.text
...
selenium.common.exceptions.UnexpectedAlertPresentException: Alert Text: Hello, Earth: So do MANUALLY dismiss! {Click [OK] now!!!}!
Message: Unexpected modal dialog (text: Hello, Earth: So do MANUALLY dismiss! {Click [OK] now!!!}!) The alert disappeared before it could be closed.
The strange thing is that if the browser user triggers another alert (on another page even!), then a selenium.dismiss() will pull body.text back from limbo and selenium with from then will operate as per (my) expectations.
Any suggestions on how to get the browser back to the page.body? (And escape the alert)
Addendum: Here are similar questions (found with intense searching):
downloading - Issues downloading file using Selenium + Firefox
java alert - Selenium WebDriver - Unexpected modal dialog Alert
UnexpectedAlertPresentException - Webdriver error: "No alert is present" after UnexpectedAlertPresentException is thrown
DesiredCapabilities - How to handle an Alert with "UnexpectedAlertBehaviour" capability in Selenium?
java&javascript - org.openqa.selenium.UnhandledAlertException: unexpected alert open
disables exception or DesiredCapabilities - org.openqa.selenium.UnhandledAlertException: unexpected alert open
non-click suggestion - When I show a dialog, an exception "UnhandledAlertException: Modal dialog present" is thrown
IE and in the wild - https://github.com/SeleniumHQ/selenium-google-code-issue-archive/issues/4839
java bug report? https://groups.google.com/forum/#!topic/webdriver/aNyOfEjMENg
"still doesn't work." catching exception does not reset the problem - (However almost exactly the same problem) - how to handle javascript alerts in selenium using python
suggested doing a driver.findElement(By.id("myAlert")); but that throws same exception - https://sqa.stackexchange.com/questions/22482/why-my-alert-is-not-popping-up
browser.refresh(); gives UnexpectedAlertPresentException so doesn't work. https://github.com/angular/protractor/issues/1486
browser.switch_to.window(browser.window_handles[0]) then body.text gives: UnexpectedAlertPresentException
Similar - Python webdriver to handle pop up browser windows which is not an alert
I have been struggling with this issue off and on for a long time; your comment on your question solved the problem for me:
After both UnexpectedAlertPresentException and NoAlertPresentException are thrown...
browser.execute_script('alert("Clearing out past dialogs.")')
browser.switch_to.alert.accept()
As you said in your answer, webdriver is creating a 'dialog' when the alert is present. Closing the alert by hand causes its reference to get lost in limbo, but it's still blocking access to body.text. Creating a new alert seems to allow webdriver to clear out that old 'dialog' and (after accepting) grants access to the page again.
No solution yet... I suspect it is a bug in Firefox's webdriver in file modals.js
Firefox's web driver captures the alert popup and replaces it with an element named 'dialog' { e.g. getElementsByTagName('dialog')[0]}
The problem is that if the tester is human and clicks on either "dismiss" or "accept", then the "onclick" for 'dialog' does not call fxdriver.modals.clearFlag_... hence the problem.
https://github.com/SeleniumHQ/selenium/blob/master/javascript/firefox-driver/js/modals.js#LC39
fxdriver.modals.isModalPresent = function(callback, timeout) {
fxdriver.modaltimer = new fxdriver.Timer();
fxdriver.modaltimer.runWhenTrue(
function() {
var modal = fxdriver.modals.find_();
return modal && modal.document && modal.document.getElementsByTagName('dialog')[0];
},
function() { callback(true) },
timeout,
function() { callback(false) });
};
fxdriver.modals.acceptAlert = function(driver) {
var modal = fxdriver.modals.find_();
var button = fxdriver.modals.findButton_(modal, 'accept');
button.click();
fxdriver.modals.clearFlag_(driver);
};
https://github.com/SeleniumHQ/selenium/blob/master/javascript/firefox-driver/js/modals.js#LC127
fxdriver.modals.setFlag = function(driver, flagValue) {
driver.modalOpen = flagValue;
};
fxdriver.modals.clearFlag_ = function(driver) {
fxdriver.modals.setFlag(driver, false);
};
Maybe the file_detector selecting local files has a work around...
http://selenium-python.readthedocs.io/api.html#selenium.webdriver.remote.webdriver.WebDriver.file_detector_context
Similar problem:
How to debug Firefox alert box closing automatically and being unable to detect the alert in Serenity BDD?
Bug report:
https://github.com/SeleniumHQ/selenium/issues/4190

Eliminate 404 url error in console?

I try to eleminate an 404 error occuring because the source (src) is missing..
var $chart = $("<img />")
.addClass("trend-pic")
.error(function(){
console.log("error loading..")
});
try{
$chart.attr("src", jobs[counter].url + "test/trend")
}catch(err){
$chart.attr("src", "");
}
if tried many stuff to catch the error i.e. putting an .error(function(){}) at the end.
use the $chart.load() - method to check if the images gets loaded?
Non of those helped?
GET {myURLString} 404 (Not Found)
Browser: Safari
You can't really delete those 404 errors from the console.
The best you can do is make some ajax calls and see the return code, but then you'll be limited to request only to your own domain.
EDIT--
Oh, and yes, those errors will keep showing in the "Requests" tab! They just won't appear in the "Console" tab (in Chrome).
I think there is no way to eliminate the error from your console, except using the right url.
In your code with the try {} catch() the error is thrown and $chart.attr will be called again with an empty string.
What you can do is add a check like this before you set the .attr()
if (jobs[counter].url !== void 0 &&
jobs[counter].url.length !== 0) {
$chart.attr("src", jobs[counter].url + "test/trend")
}
so you can remove the try{} catch()
Hope it helps.
Just the answer is No.Because this is the only way Server send "there is a Error".
Refer this one.
Prevent 404 Error in console
404 is not an error. It is the way server says it does not have the source referred by the client.

top.document.location.href property behaviour in IE(8/9)

I have a piece of code which works in a way that is unexpected to me. Let me first put down the details, so the code looks more or less like this:
window.onunload = doUnload;
var unLoadTimer;
var gInvokeOnBeforeUnload = true;
function setInvokeOnBeforeUnload() { gInvokeOnBeforeUnload = false; }
function doUnload() {
if(gInvokeOnBeforeUnload==true){
setInvokeOnBeforeUnload();
top.document.location.href = "LogOff";
clearTimeout(unLoadTimer);
}
//Function Midpoint
if (top.document.readyState != "complete" && gLogOffClick == false){
unLoadTimer = setTimeout("doRealUnload("+func_call_count+")", 800);
//its just a timeout for the function to be called again
}
}
How I also added logging but for sake of keeping code small excluded from examples. The issue I faced was that top.document.location.href is NOT reassigned to "LogOff" and is still equal to the very first starting page I opened on the site, call it "LogIn".
To trigger the window.onunload event I hit F5 (and it happens all the time), but the logoff is not assigned to location.href. Only if at "//Function Midpoint" comment marker I add a simple alert(1); then logoff is triggered (as seen in Apache logs below), however location href is still the same as it was - "LogIn".
Am I wrong to assume it should change as soon as its assigned a value?
And so I'm failing to understand several points:
Why location.href is not changed as soon as I assign it the value of LOGOFF.
What should happen as soon as LOCATION.HREF is changed
How does LOCATION.HREF get initialized when I open the browser and logon
Don't have any fancy session tracking mechanisms, its a straight forward HTML page with the above JS triggered # onunload via F5.
All I want to achieve is to understand what happens behind the scenes and why the redirect happens if there is an alert(1); inbetween and doesn't if no break is there. In my case Apache registered the following:
With timeout:
IP.IP.IP.IP - xxx [28/Oct/2011:10:38:50] "GET /LogOff HTTP/1.1" 200 208
IP.IP.IP.IP - xxx [28/Oct/2011:10:38:50] "GET /LogIn HTTP/1.1" 401 540
IP.IP.IP.IP - xxx [28/Oct/2011:10:38:52] "GET /LogIn HTTP/1.1" 200 2898
Without timeout:
IP.IP.IP.IP - xxx [28/Oct/2011:10:41:04] "GET /LogIn HTTP/1.1" 200 2726
Any help or guidance towards what to read/where to look is appreciated, even better if someone could elaborate what happens behind the scenes. Im afraid I'm not well educated in JS engines, to my disadvantage. The code is also not really mine :(
If you have extra question I'm listening, maybe I omitted something important there :)
Didn't try to test in other browsers as IE is the only focus group I need...
document.location.href is read-only when unloading the page. Hence you are not allowed to change this property when the user wants to leave the page. This is a security 'feature'.
See also: Changing window.location.href in Firefox in response to an onunload event
I suggest you instead make an asynchronous call to the server, logging out the user etc. You can do this with an Ajax-call, which is fairly simple using jQuery.

Cuffon is undefined. Javascript error on IE7 and IE8

I am getting this error 'Cufon' is undefined on my blog http://microreviews.org The error comes on Line 20, char1.
I also get the error 'dtsv' is undefined on Line 57 and character 3.
The errors comes only on IE7 and IE6 and no other browser. I donot really care for IE6 but the error on IE 7 is a major source of concern. What can be done to get rid of these errors?
The problem is happening in other browsers too -- check your error console.
For "Cufon is undefined", it's line 20 - that line is:
"Cufon.replace('h1, h2, h3, h4 ,h5', { fontfamily: 'Museo Sans 500' });
So .. whatever "Cufon" is supposed to be - it's not defined.
I notice that there's a link just prior to this:
http://microreviews.org/wp-content/themes/kreativ/js/cufon-yui.js
Which is resolving to a 404 error (not found) -- so that's probably your problem.
The "dtsv is undefined" problem is the same thing. Line 57:
dtsv.root = 'http://microreviews.org/wp....'
At that point, dtsv hasn't been initialized, so you can't set a property on it.
cause your Cufon file is not found, check the url to your file. And what is dstv ???

Categories