Installing Selenium Automation 2.53.1 - javascript

My question is based on this document.
I've installed all of the necessary jars and executables like it says in the document for the installation. I've also setup the eclipse environment and installed TestNG. I've made an Apache Http Server as well, basically I did everything as it says in the installation document.
But now I need to move the files "Inspector.js" and "TpaeInspector.js" to a central location and then change the location, where it was copied, of the Inspector.js on line 32 in TpaeInspector.js.
This is the current line 32:
https://PathToFileServer/Inspector.js"]
And I've moved the files to a map I've created on my desktop (C:\Users\anabe\Desktop\Test Selenium), so it should look like this:
C:\Users\anabe\Desktop\Test Selenium\Inspector.js"]
And lastly I need to make a bookmark in my browser and edit it to this line:
javascript:
void(require(["https://<InspectorLocation>/TpaeInspector.js"],
function(inspector){new inspector().startup(/*headless*/false,
"https://<InspectorLocation>/TpaeInspector.js")}));
Where the <InspectorLocation> is the current location of the Inspector file, so it should look like this:
javascript: void(require(["C:\Users\anabe\Desktop\Test
Selenium\TpaeInspector.js"], function(inspector){new
inspector().startup(/*headless*/false, "C:\Users\anabe\Desktop\Test
Selenium\TpaeInspector.js")}));
It still doesn't work, can anyone tell me what I did wrong?

Related

JavaScript for Automation - how to get the path of the current script?

In macOS' JavaScript for Automation (JXA), how to get the path to its own script?
That is, the equivalent of the following AppleScript snippet
path to me
I've tried the following JavaScript snippet, but the resulting path points to the Script Editor app, despite the script having been saved as a script bundle (*.scptd).
app = Application.currentApplication()
app.includeStandardAdditions = true
pathToMe = app.pathTo(this)
The underlying reason behind this is for a JXA script bundle to contain additional resources that can be referenced and used by the script itself.
Note for those downvoting or voting to close, I've been through these and none of it worked effectively:
How to get POSIX path of the current script's folder in JavaScript for Automation?
How do I get the Scripts folder in the application bundle?
Applescript indicates resource not found when trying to call within inside the app
https://macscripter.net/viewtopic.php?id=43445
As shown in the screenshots above, app.pathTo(this) points to the Script Editor. The question is about getting the script bundle, just like what the AppleScript language option is able to do.
OS version: macOS 11.4 (20F71)
Processor: Apple Silicon (M1)
Script Editor: Version 2.11 (225)
I find a way to get current parent path, its worked for me:
var app = Application.currentApplication();
app.includeStandardAdditions = true
var path = app.doShellScript('pwd')

How can I load a Firefox extension cross-platform in a functional test CI environment?

I'm trying to run functional tests in Firefox of some javascript code that relies on an extension to be loaded. In Chrome, I'm able to do this by telling the browser launcher to launch Chrome with --load-extension=<path>. I have not found an analog to this in Firefox, nor any other clear way to do this.
My first attempt was to try to launch Firefox with a custom profile using the -profile <path> command line switch, but when trying to reverse-engineer the firefox profile extension metadata it looks like there are some absolute paths in there that would make the profile not portable (i.e. i couldn't check it into git and have another developer be able to clone and run tests, because it would be looking for my machine's paths).
Does anyone know a good way to handle this? I'd really like it if I wasn't forced to generate the extensions.json each time the tests are run.
For what it's worth, I am running my functional tests using karma & karma-firefox-launcher in node.js
After doing some more research, I found a solution. You can script the creation of an empty directory (say 'tempProfile') and create the following contents:
tempProfile/prefs.js
user_pref("extensions.autoDisableScopes", 0);
user_pref("extensions.enabledScopes", 15);
tempProfile/extensions/
place your extension here. The extension's filename must exactly match the 'id' of the extension, with .xpi as its file extension. You can discover the 'id' of the extension by extracting the .xpi (i.e. unzip XXX.xpi) and opening the install.RDF file with a text editor. Look for the em:id tag under the Description tag.
For example, if your install.RDF file looks something like this:
<?xml version="1.0" encoding="utf-8"?>
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:em="http://www.mozilla.org/2004/em-rdf#">
<Description about="urn:mozilla:install-manifest">
<em:id>myCustomExt#suchandsuch</em:id>
<em:version>1.0</em:version>
<em:type>2</em:type>
<em:bootstrap>true</em:bootstrap>
<em:unpack>false</em:unpack>
[...]
</Description>
</RDF>
Then you should set the filename of the extension to myCustomExt#suchandsuch.xpi.
Once you have the profile setup, you can run Firefox with Firefox -profile /path/to/tempProfile
Anyway, karma and karma-firefox-launcher already do much of the work of automating this for you on each browser run, so I just patched that project to add support for placing the extensions in the right place and setting the necessary prefs. I submitted a PR and it is here.

JavaScript: "Uncaught SecurityError" when running JS-XSL demo locally

(This question pertains to the JS-XSL demo found here)
To briefly tell you what this demo is for; it takes a MS Excel file as input, parses the data, and outputs the data in text-only format. I downloaded the package (zip) and ran it locally, simply by opening the html file with Chrome.
The problem is, I just cannot seem to get over the following error:
Uncaught SecurityError: Failed to construct 'Worker': Script at 'file:///C:/Users/David/Desktop/Xlsx%20Demo/xlsworker.js' cannot be accessed from origin 'null'.
And above error points to line 34 of the html file, which has the following code:
/* I changed the file path from './xlsworker.js' to 'xlsworker.js' */
var worker = new Worker('xlsworker.js');
There are only three files for this demo: the html file itself, and two javascript files, one is named xls.js and the other xlsworker.js. All three files are in the same directory and at the same level.
What's rather baffling to me is, I successfully ran this same demo about a couple months ago! I cannot imagine if I am doing anything differently now. Any insight?
https://code.google.com/p/chromium/issues/detail?id=278883#c9
You are basically prevented by Chromium to use workers on the file:// protocol, you have to host your files and access them through the http:// protocol.
You need a server (even something simple like http://docs.python.org/2/library/simplehttpserver.html)
IMO, the below is a superior answer, because it does not require running a web-server. It's extremely quick and simple.
(the downvote is explained in my Note 5, below)
I have tested and verified that this solution works with the demo linked by the asker, when run locally as described by the asker. Tested on Windows 10, Chrome Stable x64 48.0.2564.103 m.
A script is not allowed to access to your local file system in Chrome. If you'd like to test web workers locally, you have to open Chrome with a special flag.
On Windows, launch chrome with the flag:
chrome.exe --allow-file-access-from-files
After that Chrome will be launched and you can test workers during this session.
Note1: if Chrome is already running when you run this command, the new instance of Chrome will not allow Workers to run-- you must first exit from Chrome (if necessary, use Windows Task Manager to ensure Chrome is not running).
Note 2: the source for this answer (link below) includes the --args flag on Windows, but i have not found the "args" to be necessary on Windows. In fact, i cannot find any documentation of the "args" flag anywhere-- not sure what it does. So i don't include it in the Windows command, above.*
Note 3: For those trying to do something similar on Chrome-Mac, or Windows-Firefox, the link below includes both, along with the Windows-Chrome solution above. But my solution described above is only the Windows-Chrome method.
http://js-workout.tompascall.com/web-workers-and-responsiveness/
Note 4: Be aware that this solution is not the same as running a web-server, but for your purpose it should be a completely adequate solution. Also, be aware that to browse the web with this chrome startup-switch enabled may compromise your local file-security, so it's advised to only use this method for your local file purpose, and disable it for web-browsing.*
Note 5: Google states that using startup flags "should only be used for temporary cases and may break in the future." Web search for chrome startup switches returns about 2,000 hits, so lots of people use them and blog about them. If your need is temporary, then this currently works great.*

How run a windows console for JavaScript

I would like to have a console window (a command line) on Windows 7 which will allow me to play with JavaScript just like a python console.
Update:
It's important to have a file access from within the console (or script run through it).
You can use Node.js's REPL. To do so follow this steps:
Download and Install Node.js.
Call Node.js from the Start Menu / Start Screen or directly node.exe installation path (e.g C:\Program Files\nodejs\node.exe).
Enjoy!
You may want to add the installation path to your PATH enviroment variable for ease of use.
Note: to leave node.js press Ctrl + C twice.
To access the local files, you will need the File System module. This is an example of usage:
var fs = require("fs");
fs.readFile(
"C:\\test.txt",
function(err, data)
{
if (!err)
console.log(data.toString());
}
);
This will output the contents of the file C:\test.txt to the console.
Note: An unhandled exception will cause node.js to "crash".
You can just use the developer tools.
For example, in Chrome, press F12. This will bring up the developer tools. The last option on the menubar is console. This will allow you to create JS variables and functions and to interact with DOM elements on the current page
It's possible thanks to Mozilla Rhino JavaScript Engine.
To create a console window for JS:
1) Download Mozilla Rhino JavaScript Engine binary.
2) Extract: js.jar.
3) Create a script to run the console window (e.g. rihno_console.bat):
java -cp js.jar org.mozilla.javascript.tools.shell.Main
For more information about usage (for instance, and global functions inside this console) visit the Rhino Shell web page.
Just like I informed another user with the same question as yours who was faced with the same need, check out DeskJS (https://deskjs.wordpress.com). It's a portable Windows console application that lets you run pure JavaScript code and even load any existing JS files. It supports even the basic JS popup boxes implemented in browsers. You can save your commands as JS files that can be run on startup or by dragging-and-dropping them on the app. Plus there's so much more to it like you can create a build system for Sublime Text that can run JS files via cmd, it supports themes for customizing the entire console and snippets which let you save short snippets of JavaScript code for later use. Improvements are still being made on the app together with other native APIs being included. Hope this helps you as it did for me.

Debug Javascript in netbeans 7.4 inside PHP project

I want to debug javascript code inside my php project in netbeans. I have read on several occasions that this should be possible in the new netbeans 7.4 version, for example here and here, but i cannot get it to work. I have installed de debugger connector for chrome and php debugging works just fine but when i try to set a breakpoint in a .js file it says:
unresolved breakpoint,
debugger is not attached to tab with id....
i understand that the link from the netbeans page is for an html 5 application but i thought this debugging would also be enabled in php projects. Am i doing something wrong?
i know i can debug with firebug or chrome itself but i would like to do it all in one place in my netbeans IDE...
thanks in advance
The unresolved breakpoint usually mean that for instance you set it in file that is not loaded in Chrome's tab right now (or for some reason, IDE cannot match URL of JS file and local JS file). The mixed debugging works only in Embdded Browser or in Chrome with NetBeans connector (you can see the usually yellow bar in your page saying "NetBeans connector is debugging this page" and you can debug PHP and JS at the same time.
Have a look here, although it is about Java EE projects, it is very similar to PHP projects
Updated answer:
One issue I remember (and plain Chrome Dev Tools has it as well) is that if you have JavaScript file attached to HTML/PHP with dynamic parameter to prevent browser from caching, e.g. , where "673612" changes each time a file is loaded. If that's your case, try to remove this dynamic attribute. I think that e.g. Sencha or ExtJS use this feature which "breaks" debuggers.
I had a similar problem : javascript breakpoints were broken, while everything else was working fine (for example php breakpoints were okay).
The reason was that in the run configuration properties I changed the Project URL to something that was not the host anymore, but a subfolder managed by a url rewriting rule.
johanvs is correct, but my reputation is not enough to +1.
Suppose a NetBeans project contains many files in different folders:
/var/www/index.html
/var/www/config.html
/usr/doc/readme.txt
/usr/doc/license.txt
Since "index.html" is not in the project root folder but under "/var/www", NetBeans does not know "http://127.0.0.1/index.html" is corresponding to "/var/www/index.html". To solve, verify below settings in NetBeans -> File -> Project Properties:
Sources -> Web Root
"var/www"
Run Configuration -> Project URL
"http://127.0.0.1/"
Run Configuration -> Index File -> Browse
"index.html"
Run Configuration -> Remote Connection -> Manage -> Initial Directory
"/"
Run Configuration -> Upload Directory
(empty)

Categories

Resources