Selenium testing setup on remote server - linux

I'm trying to install and run Selenium on a remote server to run web tests for a Drupal 7 install. I need to find a way for the browsers installed on the server to output their display onto the computer that is connected to the server, and I need to figure out why Selenium is failing to run. Error messages down below.
My server set up:
centOS 7.1 on Linux running NGinX web server
X11Forwarding available and enabled
Drupal 7 install
Selenium 7.x-3.0 Drupal Module
Selenium Standalone Server 2.46.0
Firefox 38.1.0 installed
Google Chrome stable 43.0.2357.132
Chromedriver 2.16 for 64-bit Linux, set to executable, with symlink to driver in /usr/bin and /usr/local/bin (the local is the only necessary one, the usr/bin is just a fallback)
Note: my solution must have the server hosting the selenium server as the website will be delivered to a client when it's ready for production. It won't work for me to just install the selenium server and browsers on my own machine.
My issues:
When I ssh -X user#server, it doesn't seem to matter what I set the DISPLAY to, firefox can't open the display when I run 'firefox &' [e1]. I've tried export DISPLAY=localhost:0.0, localhost:10.0 and [myIP]:0.0/10.0.
When I run the selenium server and attempt to run the sample test cases on my website, the Firefox instance of the test fails to connect through 127.0.0.1 port 7055 [e2] and the Chrome instance is either unable to find the driver or shuts down unexpectedly [e3]
Errors:
e1 - Error: cannot open display: host:#.# <== (Whatever variant I've attempted)
e2 - Message: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output: (blank)
e3 - Message: chrome not reachable
SimpleTest isn't a suitable replacement as the things I'm trying to test require too much custom setup to configure a stock Drupal sandbox properly. Consequently, I'm relying on Selenium's option to test on the original site instead of a sandbox.

Related

How to open a xterm terminal in a SSH connection with a remote Ubuntu without GUI

I am using Mininet on a remote Ubuntu without GUI. And I am trying to use "xterm h1" to open a terminal on a virtual host in Mininet. But it showed me always there is no display connected. I am trying to use other X application like firefox and it showed me
"No protocol specified
Unable to init server: Could not connect: Connection refused
Error: cannot open display: :0.0"
Then I have set X11forward yes in sshd_config on the remote Ubuntu, and install Xlaunch on my windows but showed no changes.
Can someone tell me how to solve this problem?
PS. I am using a pycharm on Windows11 to establish this SSH session
Since you are running windows you will first need an application that will run an X11 server on your windows, Xming, for example. You will then need to configure your ssh connection to use that xserver. Finally you want to setup the DISPLAY variable at your remote to be LOCAL_IP:0 where LOCAL_IP is the public IP of your machine.

Django's 'python manage.py runserver' does not create a local website I can access

I am trying to follow this online class, and I am stuck on the part where I access a local website made by django. The tutorial that I follow is this one by freecodecamp, and I get stuck by the 11min mark where I try to access the output site http://127.0.0.1:8000/ . I am following this tutorial on the browser version of Jupyter Notebook.
Tutorial: https://www.freecodecamp.org/news/create-an-e-commerce-site-with-django-and-vue/
The 'python manage.py runserver' line runs, and I get the following output:
System check identified no issues (0 silenced).
April 16, 2021 - 03:37:04
Django version 3.2, using settings 'djacket_django.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
When I copy and paste the server address into the browser, I just get the following error saying that I wasn't able to connect to the site:
Unable to connect
Firefox can’t establish a connection to the server at 127.0.0.1:8000.
The only resource I really found that addressed this issue was the following post, but when I went through my netstat list, there were no IPs listing :8000, so I don't think that I am using up that address already.
Post:
Django manage.py runserver is not working
Sounds like you are using WSL2 and have not yet discovered that the WSL2 VM's IP address is not the same as the Windows IP address. Windows has its own idea of what localhost might be!
TL;DR: Use GWSL to run WSL2 apps on X Windows. This will allow you to run a browser from WSL2 over X Windows, and no worries.

How to set up custom hostnames and ports for servers (eg node.js) running in WSL 2

(I've provided a simple working solution in response)
I recently moved from macOS to WSL 2. I have two node servers running within WSL 2 (Ubuntu distro). Each must be accessible through a custom hostname for development vs production purposes. I've had difficulty accessing the node servers via custom hostnames (ie set in some ../etc/hosts file) especially given WSL 2's dynamic IP that changes per WSL/pc 'boot'. How does one go about setting custom hostnames in WSL 2?
Scenario:
Each node.js app server (again running within WSL 2) must be accessed from the browser with the following urls/custom hostnames:
www.app1.com:3010
www.app2.com:3020
After searching around I have found the following relatively simple process works. I thought I'd share and save some time and headache for those new to WSL 2. Note, although I'm using node as the server stack, this process should more or less be the same for other app/web server stacks.
Note the following SE post is the basis of the solution. It's also worthwhile to examine MSFT's reference on WSL vs WSL 2. Also note, I haven't provided deep rationale on why these steps are required, why we might need custom hostnames, ipv6 options in ../etc/hosts, the meaning of 127.0.0.1, loopback addresses, WSL 2 and distro management, etc. These are subjects beyond the scope of this post.
Simple scenario:
nodeApp1: node application server with custom hostname: 'www.app1.com' on port 3010 (or whatever)
nodeApp2: node application serverwith custom hostname: 'www.app2.com' on port 3020 (or whatever)
Each node.js app server (again running within wsl 2) can be accessed from the browser with the following urls:
www.app1.com:3010
www.app2.com:3020
Two key items:
The correct etc/hosts files to be modified is on the Windows side (not WSL distro) at: C:\Windows\System32\drivers\etc\hosts (yes in Windows folders). This is a 'hot' update so no need for WSL 2 reboot. The content for this scenario is:
127.0.0.1 localhost
127.0.0.1 www.app1.com
127.0.0.1 www.app2.com
255.255.255.255 broadcasthost
::1 localhost www.app1.com www.app2.com
Please add C:\Users\"you"\.wslconfig with the following content (yes in Windows folders):
[wsl2]
localhostForwarding=true
Note: there's a reference to this in WSL 2 Ubuntu distro's /etc/hosts.
Also note, this requires WSL shutdown and reboot. Shutting down your terminal is insufficient. Also total machine boot is not
required. Simply run:
wsl --shutdown (in Powershell) or
wsl.exe --shutdown (within Ubuntu)
Then restart the Windows Terminal app (or any WSL terminal) to access the updated WSL 2 environment. The apps with custom urls/hostnames will now work in the browser permanently and WSL 2's dynamic IP is circumvented.

PDO driver for XAMPP on Linux

I'm about to gain some experience on Yii so I set up a XAMPP (1.8.1) for Linux environment and installed the Yii framework.I progress based on the book titled 'Web Application Development with Yii and PHP' and there's an example to set up database connection and test that through the Yii console by running the following code:
echo Yii::app()->db->connectionString;
Of course previously I created the appropriate MySQL database and set up the connection string in corresponding main.php and console.php but I'm getting an error:
exception 'CDbException' with message 'CDbConnection failed to open the DB connection: could not find driver' in /work/webroot/yii/framework/db/CDbConnection.php:382
Based on Yii's requirement checker PDO for MySQL is enabled. If I check the HTML version of phpinfo it says:
PDO Driver for MySQL: Enabled
and
Client API version: mysqlnd 5.0.10 - 20111026 - $Id: b0b3b15c693b7f6aeb3aa66b646fee339f175e39 $
However if I run phpinfo from a Yii console it gives the following result:
PDO support => enabled
PDO drivers =>
So, for me it seems PDO driver is missing. I read several forum threads about how to download PDO drivers for linux and how to change the php.ini to use those drivers but I guess that solution works for CLI environment and not for XAMPP.
Can somebody help me out here how can I set up PDO driver for MySQL database on XAMPP? I'm using Ubuntu 13.10 desktop.
I was playing around for a while and found the solution with the help of several forum threads.
To resolve the following driver issue...
'CDbException' with message 'CDbConnection failed to open the DB connection: could not find driver'
... I had to install the correct connector. I ran the following:
sudo apt-get install php5-mysql
After that I tried to check the connection string once again via the Yii console by running code:
echo Yii::app()->db->connectionString;
But this time it gave me a different error mesage:
'CDbException' with message 'CDbConnection failed to open the DB connection: SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'
To resolve this issue I changed my main.php and console.php under /protected/config directory and replaced 'localhost' to '127.0.0.1'.
Based on the PHP documentation this is required because MySQL Unix socket shouldn't be used with host or port.
This resolved the second error message and I could connect to my database.

Node.js, WebSocket Location Issue?

I created a server using Node listening on port 8000, localhost. Verified it's running properly, but I cannot access the WebSocket on the client (Chrome 5). Tried several implementations from various Git repos, node + websocket, socketIO, articles, etc. Nothing.
No port conflicts (sudo lsof -i tcp);
Tried server.listen(8000, "*");
Pointed to ws = new WebSocket("ws://:8000/test");
Debian Lenny, Apache22
Node v0.1.98-31-g1c6671a
I'm thinking there may be a conflict with url rewrite. Or possible permissions. Any ideas?
I had a similar issue on Ubuntu 10.04 LTS 32-bit and Chrome 5.0.375.125 and found out it is a bug in Chrome.
Here's how you can test and work around the problem. I used WebSocket with PHP and later Node.JS:
PHP: Download a tutorial file from http://net.tutsplus.com/tutorials/javascript-ajax/start-using-html5-websockets-today/ and extract it in a folder called 'socket' in your webroot. This folder now contains a readme.txt and the folders 'server' and 'client'. Now start the script in the console according to the readme (for me the command was: sudo php -q /var/www/socket/server/startDaemon.php ). It should print 'Start listening on Socket.' . Leave the console window open. Now go to localhost/socket/client/client.php in Chrome. It should say 'Socket Status 0' and if you look in the console you see no new messages (no connection was made).
Now here comes the trick: open a second Chrome tab. Point this tab to the same url: localhost/socket/client/client.php (It also says 'Socket Status 0'). And then close it again. Your original tab should now say 'Socket Status: 1 (open)' and in the console you see a handshake was made. WebSocket now works.
I repeated the same trick as above but this time using Node.JS with the Socket.IO script. The chat example included in Socket.IO-node ( github.com/LearnBoost/Socket.IO-node ) had the same issue, hanging at the 'Connecting...' stage. Opening a second tab to the chat box and then closing it again solved the problem and the chat box proceeded to load properly. The Node.JS server confirmed the connection in the console. From then on WebSocket worked fine.

Resources