How do you get webdriverjs working? - javascript

Anyone here have experience using Selenium and webdriverjs? I'm coming from a non-Java background with a good deal of experience with Node.js and JavaScript in general. According to the Selenium docs, you have to set-up a stand-alone Selenium server to use the node web driver. Fortunately, they seem to be bundled together.
npm install webdriverjs
gets you the JAR file for the standalone selenium server inside the node_modules/webdriverjs/bin directory. Example tests are inside the node node_modules/webdriverjs/examples directory but the tests in them fail when I run them from either the webdriverjs or examples directories.
What's the missing piece here? What's the quickest way to get up and running?
I have read the docs.
Note: Stack overflow wouldn't let me use the tag webdriverjs, but this is specifically about webdriverjs, not using selenium with Java or other languages.
Update: The only problem was that the built-in example tests are broken!

Here's what I did to get webdriverjs working:
Step 1: start selenium standalone in my laptop by running command java -jar selenium-server-standalone-2.33.0.jar. then it will listen to http://localhost:4444/ and you can access it via http://localhost:4444/wd/hub/. You also need to make sure Firefox browser is installed on your laptop.
Step 2: create a new directory and run command npm install webdriverjs.
Step 3: create a new file named test_webdriverjs.js in the new directory you created, and it looks like this:
var webdriverjs = require('webdriverjs');
var client = webdriverjs.remote({
host: 'localhost',
port: 4444
});
client.init();
client.url('https://github.com/')
.getTitle(function(err, title) { console.log (title)}).call(function () {});
client.end();
Then run command node test_webdriverjs.js under the same directory and you will find it works. If it doesn't work, paste out the console output.

Related

Cypress TestRunner via "cypress.open" works locally but does not work on Windows Server 2008

I am using Cypress testing framework JS API and trying to host it on Windows Server 2008. When I execute a Javascript command "cypress.open" locally on Windows 10 laptop, the TestRunner window opens up and I can run manually run tests.
But the same does not work on Windows Server 2008. No error is being reported. Has this something to do with any kind of security aspect related to Windows Server 2008? Can anyone please shed any light on what might be happening here.
I have installed cypress using npm on the server.
npm install cypress
Installing it at C:\Users\xyz\AppData\Local
Here is the Javascript code to open the cypress test runner.
Var cypress = require(‘cypress’);
module.exports = function(callback)
{
cypress.open({
project: ‘./node_modules/.bin’
});
callback(null,”Opening cypress”);
};
I am using ASP.NET Core to run the node module. The C# code is here:
public asynchronous Task<IActionResult> OpenTests()
{
Var data = await _nodeservices.InvokeAsync<string>(“Scripts/OpenTests.js”);
return ok(data);
}
Any help is appreciated. Thank you.
I would verify you meet the System requirements

Connect to OpenVPN server through Node.js

I’m trying to create a GUI client for connecting to OpenVPN servers using electron and node but I’m struggling to figure out how to actually connect to the servers using the .ovpn files.
My question is what is the best way to connect to an OpenVPN server using node? Would it be best to Tun terminal commands like
“openvpn—config path to config”
Or is there another way applications like tunnelblick do it that might be easier or more efficient?
Hello I have been working with electron and ovpn on my last project, so here are a few tips.
VPNs require admin/root privilege in order to get setup, so running child_process.spawn on openvpn --config <path> will fail unless your electron app is being ran via sudo/admin privilege.
You can also use electron-sudo package, link here. This is basically a child process spawn with sudo/admin. Aka, app runs normally, but vpn command runs with sudo.
However, if your client is sketchy about giving you sudo/admin, the VPN must be ran separately prior to launching your app.
All in all its a admin/sudo thing.
Hope this helps.

How to use a browser on a remote server for an automated tests

I inherited a project where the person wrote tools to test our site's UI using JQuery and JS.
I don't know too much about it other than it requires a browser to be spawned and I think the tool uses JS to interact with iframes to see if it's the expected values.
My job is to get this tool to run on a remote server and post the results to Jenkins.
The remote test server and staging server is linux. From our staging server, I want to write a script to spawn a browser and run cmds from the tool to test our UI. I ran the following manually:
ssh -X user#remote_test_server /usr/bin/firefox
However, the remote server says:
Error: no display specified
Is there a way to spawn a browser for automated testing from one headless server to another? Thanks in advance for your help.
I faced a similar problem when I tried to automate a GUI installation program. While there are quite some different possibilities to choose from (e.g. Xnest, Xephyr?), I ended up using vncserver, because it's relatively easy to debug the GUI session this way.
You need to create a vncpassword file, I think:
mkdir -p $HOME/.vnc
chmod 0700 $HOME/.vnc
echo MyLittlePassword | vncpasswd -f > $HOME/.vnc/passwd
chmod 0600 $HOME/.vnc/passwd
Starting the server is then quite straightforward
vncserver
export DISPLAY=:1
/usr/bin/firefox&
...
Now it is possible to connect to the VNC server with a VNC viewer of your choice. But beware there may be no window manager, depending on the X startup scripts of your environment.
Shutting the server down
vncserver -kill :1
In the configuration of Jenkins project , specify the
Build Environment
Start Xvfb before the build, and shut it down after.
#

Starting a node.js server

I recently got into node and I installed it on my localhost. I am using WAMP. I am on Windows Vista.
Anwyay, I installed it. I made a new file in my localhost directory with this being called server.js
var http = require('http');
http.createServer(function (request, response) {
response.writeHead(200, {
'Content-Type': 'text/plain',
'Access-Control-Allow-Origin' : '*'
});
response.end('Hello World\n');
}).listen(1337);
then I went to node and tried typing % node server.js and all I got was an ellipses. What gives?
UPDATE: I checked my Systems variable and saw that my PATH lists the node.js as C:\Program Files (x86)\nodejs\
Run cmd and then run node server.js. In your example, you are trying to use the REPL to run your command, which is not going to work. The ellipsis is node.js expecting more tokens before closing the current scope (you can type code in and run it on the fly here)
The NodeJS code that you wrote is corrected, and it should work but as #dwerner said you have to write node server.js in the command prompt not inside the Node REPL.
But today most of who work with NodeJS are developing using a development environment (IDE). By using IDE you get a hotkey for running your code, and many things that can help you in the daily development (Syntax highlight for e.g.)
One of the most popular IDE's today for NodeJS development is VSCode, you can check it out.
As dwerner and aminadav mentioned, you need to run the node command for the main .js file you're using for your script/app. This file will typically be index.js by default, when you run npm init to create the package.json for your NodeJS project.
Maybe you will find this blog post that covers the basics helpful as well. :)
https://dev.to/bishopwm/my-first-server-and-rest-api-essentials-for-frontenders-2gnk

Writing a pseudo terminal in python for a web based ubuntu terminal

I am interested in writing a web based terminal which can execute and autocomplete the commands in ubuntu terminal.
I have fiddled with Anyterm http://www.anyterm.org which uses ROTE: "a simple C library for VT102 terminal emulation" at the backend server and javascript/html for the terminal ui. The problem was that I couldn't have it open two terminals in the same window.
After doing some research I've decided to write a terminal server/pseudo terminal (whichever is the right terminology) in python which can:
execute commands in ubuntu terminal (such as ls, grep etc...)
autocomplete the commands (like $gedi (pressed tab) $gedit)
and have multiple instances of terminal open at the same time (when typed ls in one, the other terminal won't recognize ls as the last command since its another terminal session)
I have found that with pty python module I can write a pseudo terminal
however I'm new to python and I couldn't even get the example on that page to work.
I'm planning to have the python script serve a http server with the javascript/html terminal ui I would write (this was the main reason I wanted to choose python for this project). Then I want to let the web ui talk to the backend terminal "server" and get the results back to the web ui.
If you could point me in the right direction, maybe tell me which module I should use -if not pty- and give me some ideas on how to write the python pseudo terminal server I would appreciate it.
I know javascript/php and familiar with bash scripting- At this point I could go for a C based or python based backend server, is python right for this project?
Note: I'm planning to write a ui that uses ajax post or get methods to retrieve the terminal output from backend server.
You need to learn the basic terminology first. The shell is the program that interprets your input command lines, such as grep "foo" abc.txt. A terminal emulator is a program that mimics a terminal. Terminal is a device with display and keyboard that one
used in 1970s to access a UNIX mainframe. A pseudoterminal, pty is the device node supporting terminal emulators, as opposed to "real terminal devices" (tty1) for example.
Now, you could either build a shell, that would work in terminal instead of bash or dash; or you could build a terminal emulator that is usable over the internet; you could run any existing shell in it. Both are challenging tasks by themselves.
Python documentation is not of much use, I recommend you should start by googling more of these concepts first - and not only python references, but C, C++ too.
And lastly, if you want to run Emacs or nano or some other advanced program in your shell, you want to use the pty module.
I had a friends who did something similar but he did it over Google chat, I don't know how much help it will be but take a look at xmpp (python modual) maybe it could help you, or even here is a link to his source code:
chatIO
I didn't work with him on it but it was really easy for him to use
Good Luck

Categories