I'm getting an exception:
Capybara::Poltergeist::JavascriptError
And a debug output:
"args"=>[[{"message"=>"ReferenceError: Can't find variable: Audio"
Here's what I found when researching the error:
This issue is due to sencha 2.0 using phantomjs in order to resolve dependencies. Phantomjs does not support the HTML5 Audio API.
Question is: How do I ignore javascript errors for javascript Audio type when using capybara/poltergeist ?
I tried
visit "/"
page.execute_script "var Audio= function(){ return { load: function(){}, play: function(){} } }"
But error is thrown at the visit method.
Phantomjs doesn't support Audio
as specified in the git documentation here
I had the same problem and also tried to follow your approach using the code like the one you described, but without using var
so it will be defined globally.
page.execute_script "Audio= function(){ return { load: function(){}, play: function(){} } }"
I tested it with the inspector page.driver.debug
and it was defining Audio
in phantomjs correctly, the problem then was that, it wasn't being executed before it was needed.
Therefore, my approach was to add a check to verify Audio
is defined before actually using it with a function in my actual code. This is an example of the function I have:
getAudioObject = function(file_path){
if (typeof Audio !== "undefined" && Audio !== null) {
audioObj = new Audio(file_path);
audioObj.loop = true;
return audioObj;
}
}
That was my solution and it worked for me. I hope that this will help you too.