How to trace <script> elements/errors with Codeception with phantomjs/Selenium? - javascript

I've set up acceptance tests with codeception and phantomjs.
My website contains script elements:
<script src="/bla/test.js" type="text/javascript"></script>
The JavaScript file looks like this:
Bla = {
request: function(var) {
}
};
It looks like the content cannot be found since one of the buttons contains
onclick="return Bla.request('100')"
Running the acceptance test which clicks on this button shows me:
[Selenium browser Logs]
17:10:24.876 WARNING - SyntaxError: Parse error
17:10:25.121 WARNING - ReferenceError: Can't find variable: Bla
onclick (http://localhost/bla)
Screenshot and page source were saved into '/var/www/bla/_output/' dir FAIL
Does the first parse error already mean that the files have been loaded but contain errors? If so, how can I see the exact parse errors?
Requesting the JS file manually in the acceptance test works and it is the correct file (as the output shows):
$I->amOnPage('/bla/test.js');
I run codeception with the option --debug and looked at the output files where everything looked correct. How can I see if the JavaScript file has been imported correctly and if the parse error means that it failed, how do I get more information about the error?
edit:
Even if the parse error is not present I cannot access variables from a different JavaScript file.
When I have multiple script elements:
<script src="/bla/test0.js" type="text/javascript"></script>
<script src="/bla/test1.js" type="text/javascript"></script>
I get an error:
ReferenceError: Can't find variable: Bla
in file test1.js if it was defined in test0.js. This works in the normal browser without errors.

Related

How to handle error 'console is undefined' in powershell?

Just a simple .js file in one of my drive which contains code
var x=3;
function numSqaure(x)
{
return(x*x);
}
var sentence="The square of" + x + "is" + numSqaure(x);
console.log(sentence);
I'm trying to run it through Powershell but it shows an error 'console' is undefined .
How to handle this error? I want it through Powershell only.
Javascript files are made for being executed by a browser, not directly in console unless you're using Node.js or something similar.
Create an HTML with a script tag like this:
<script src="c:\whatever\folder\you\choose\yourscript.js"></script>
and enter developer tools in browser. There this error won't happen anymore and console will exist.

PHP variable from another file

I have 2 files, one named client.php and one named habbo3.js. Inside the client.php there is something called "connection.info.host": that usually needs to have an IP.
However I'm trying to use it as a variable and get the IP from the JavaScript file. I tried doing it like down below but I'm getting an error on chrome developer tool
client:21 Uncaught ReferenceError: price1 is not defined(anonymous function) # client:21
My client.php file: http://pasted.co/0a5a803e
My habbo3.js file:
var price1 = 123.456.789;
var price2 = 222.222.222;
The numbers above are just false numbers but should be replaced with my VPS IP address. Any solution for this guys?
You're trying to load habbo3.js with this line:
<link src="http://.../habbo3.js">
You should replace it with:
<script type="text/javascript" src="http://.../habbo3.js"></script>

How to include JavaScript file into JSP?

I have the following script tag in my JSP file:
<script src="/js/CCTUtil.js"></script>
with the following function in it:
function disableButton(buttonID) {
document.getElementById(buttonID).setAttribute("disabled", "true");
return true;
}
and in my jsp I call it with:
onchange="disableButton('datasourceForm:cancel');
datasourceForm:cancel is just the ID, so don't worry about that.
This works if I hardcode the JS function in my JSP, but when exporting it to a file, it doesn't work. It recognizes the valid filepath (otherwise the server throws an exception) so it can see the file just fine, but when testing it in Internet Explorer the error is "Object expected", and points to the end of the JSP file, which of course isn't telling of anything.
Help please?
The SRC must not be correct then. Are you sure you have set the path correctly? It's not supposed to be "../js/CCTUtil.js" is it?
Instead of including script file, directly add javascript function in the jsp file.
Then try, if you are getting the same issue, might be some issue with javascript or ur id datasourceForm:cancel

How do I get BiwaScheme to run in JSFiddle?

I'd like to try to get BiwaScheme to run is JSFiddle, please.
The BiwaScheme page claims that all you need to do is:
<script src="biwascheme.js">
(display "hello, world!")
</script>
So I added the resource http://www.biwascheme.org/repos/release/biwascheme-min.js in JSFiddle, and the (display ...) in the JavaScript window.
http://jsfiddle.net/MsjMH/1/
However, nothing happens. The console error I am getting is:
// Uncaught SyntaxError: Unexpected string
What am I missing here?
You can evaluate a string as Scheme program with BiwaScheme.Interpreter.
Example:
http://jsfiddle.net/TaEEN/1/
(FYI) There is also BiwaScheme-fiddle: http://blackboard.biwascheme.org/

How to output the result from a js file to a specific html page other than the one that is calling it from?

I am new in Javascript and I would like to learn more on the following scenario.
I have created the following files:
1. start.html
2. destination.html
3. run.js
In run.js, I have included a simple command:
document.write("This is the destination");
In start.html, I called run.js by:
<script language="JavaScript" src="run.js"></script>
This will output the message "This is the destination" to start.html.
I would like to find out if there is a way to output the result to destination.html instead of start.html?
May be this is what you are looking for:
mywindow = window.open("http://{path}/destination.html", "Destination");
mywindow.document.write('This is the destination');
but be carefull about the pop-up blocker

Categories