Running selenium on a headless EC2 machine? - ruby

I have a headless EC2 M1.Small instance running Ubuntu. I have been trying to use it to run a selenium test coded in Ruby. I am running selenium server 2.0b3 (the latest).
i have enabled XVFB:
$ sudo startx -- which Xvfb :1 -screen 0 1024x768x24 2>&1 >/dev/null &
[1] 1119
$ DISPLAY=:1 java -jar Automation/ruby-selenium-framework/selenium-server-1.0.3/selenium-server.jar > /tmp/selenium_log.log &
[2] 1245
And then run my code:
$ ./BTRuby.rb coverage_
I get the following output to the selenium log:
14:11:27.448 INFO - Command request: getNewBrowserSession[*firefox, URL, , ] on session null
14:11:27.448 INFO - creating new remote session
14:11:27.448 INFO - Allocated session 4b1395b136174ab798eddd6a59d8e308 for URL, launching...
14:11:27.488 INFO - Preparing Firefox profile...
14:11:30.709 INFO - Launching Firefox...
14:11:35.873 INFO - Got result: OK,4b1395b136174ab798eddd6a59d8e308 on session 4b1395b136174ab798eddd6a59d8e308
14:11:35.878 INFO - Command request: setTimeout[30000000, ] on session 4b1395b136174ab798eddd6a59d8e308
14:11:35.937 INFO - Got result: OK on session 4b1395b136174ab798eddd6a59d8e308
14:11:36.007 INFO - Command request: open[URL, ] on session 4b1395b136174ab798eddd6a59d8e308
Can anyone provide any help? It just seems to hang at this last INFO line.
BTW, the URL variable is a valid URL that I have stripped out for purposes of this question

sudo startx -- which Xvfb :1 -screen 0 1024x768x24 2>&1 >/dev/null &
DISPLAY=:1 java -jar selenium-server-1.0.3/selenium-server.jar > /tmp/selenium_log.log &
was able to do the trick

Related

Command succeeds within docker manually but not through bash script

The introduction
I am currently trying to build a docker image with all of my node project dependencies, so I can use it to run the tests on Bitbucket Pipelines.
The reason I decided to create an image was due to the fact I want to be in control of what version of the dependencies I have, and to control when to upgrade them accordingly.
The implementation
After having built the image using the following dockerfile:
FROM selenium/standalone-chrome-debug
LABEL name="nodejs-chrome-java"
USER root
# Install Java 8
RUN set -x \
&& apt-get update \
&& apt-get install -y \
ca-certificates-java \
openjdk-8-jre-headless \
openjdk-8-jre \
openjdk-8-jdk-headless \
openjdk-8-jdk \
&& apt-get clean
ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64/
RUN export JAVA_HOME
# Install node 10 and npm
RUN set -x \
&& curl -sL https://deb.nodesource.com/setup_14.x | bash - \
&& apt-get update \
&& apt-get install -y nodejs \
&& npm install -g npm#latest \
&& apt-get clean
# Make node available
RUN set -x \
&& touch ~/.bashrc \
&& echo 'alias nodejs=node' > ~/.bashrc
# Install PhantomJS
RUN set -x \
&& apt-get update \
&& apt-get install -y \
phantomjs \
&& apt-get clean
# Set PhantomJS to run headless
ENV QT_QPA_PLATFORM offscreen
RUN mkdir /logs
RUN touch /logs/selenium.log
I executed the docker image using the following command:
docker run -it --entrypoint /bin/bash -v /my/project:/project -w /project <DOCKER_IMAGE_ID>
And I realised that in order to have selenium running, I would have to run the following command:
/opt/bin/start-selenium-standalone.sh
Which yields the following output:
22:14:13.034 INFO [GridLauncherV3.parse] - Selenium server version: 3.141.59, revision: e82be7d358
22:14:13.304 INFO [GridLauncherV3.lambda$buildLaunchers$3] - Launching a standalone Selenium Server on port 4444
2020-06-29 22:14:13.466:INFO::main: Logging initialized #1128ms to org.seleniumhq.jetty9.util.log.StdErrLog
22:14:14.228 INFO [WebDriverServlet.<init>] - Initialising WebDriverServlet
22:14:14.547 INFO [SeleniumServer.boot] - Selenium Server is up and running on port 4444
However, because I do not want the command line within the container to get stuck, I tried the following instead:
/opt/bin/start-selenium-standalone.sh > /logs/selenium.log 2>&1 &
Which indeed outputs the same content as stated before, into the log file I defined (/logs/selenium.log) when creating the docker image. So, so far so good 👍
And if I then run my tests using the npm test command, all tests pass successfully. 🎉
Given this outcome, and because when I use this image within the Bitbucket Pipelines I wouldn't be able to run this command manually, I decided to include the line that starts the standalone selenium server in the background, on my bash script that gets executed when I call npm test, like so:
#!/bin/bash
printf "Starting Selenium Server"
/opt/bin/start-selenium-standalone.sh > /logs/selenium.log 2>&1 &
PROCESS_ID=$!
retry=0
maxRetries=10
until [ ${retry} -ge ${maxRetries} ]
do
grep "Selenium Server is up and running on port 4444" /logs/selenium.log > /dev/null \
&& echo \
&& break;
retry=$[${retry}+1]
printf . ;
sleep 1
done
if [ ${retry} -ge ${maxRetries} ]; then
echo "Failed after ${maxRetries} attempts!"
exit 1
fi
printf "Running UI tests...\n"
CONFIG_FILE_PATH='../../config_test.json' ./node_modules/.bin/nightwatch
The problem
When the command gets included into the bash script to be executed from there, it seems like the command cannot be executed on the same way as when it's done so manually. And I get the following on the log file:
22:29:12.814 INFO [GridLauncherV3.parse] - Selenium server version: 3.141.59, revision: e82be7d358
22:29:13.093 INFO [GridLauncherV3.lambda$buildLaunchers$3] - Launching a standalone Selenium Server on port 4444
2020-06-30 22:29:13.253:INFO::main: Logging initialized #1602ms to org.seleniumhq.jetty9.util.log.StdErrLog
22:29:14.058 INFO [WebDriverServlet.<init>] - Initialising WebDriverServlet
22:29:14.381 INFO [SeleniumServer.boot] - Selenium Server is up and running on port 4444
22:29:21.121 INFO [ActiveSessionFactory.apply] - Capabilities are: {
"acceptSslCerts": true,
"browserName": "chrome",
"chromeOptions": {
"w3c": false,
"args": [
"headless",
"no-sandbox"
]
},
"javascriptEnabled": true,
"name": "Route Subdomain Dashboard Test"
}
22:29:21.128 INFO [ActiveSessionFactory.lambda$apply$11] - Matched factory org.openqa.selenium.grid.session.remote.ServicedSession$Factory (provider: org.openqa.selenium.chrome.ChromeDriverService)
/my/project/node_modules/chromedriver/lib/chromedriver/chromedriver: 1: /my/project/node_modules/chromedriver/lib/chromedriver/chromedriver: Syntax error: ")" unexpected
22:29:41.214 ERROR [OsProcess.checkForError] - org.apache.commons.exec.ExecuteException: Process exited with an error: 2 (Exit value: 2)
And the following output from my running tests:
⠴ Connecting to 127.0.0.1 on port 4444...
Response 500 POST /wd/hub/session (20425ms)
{
value: {
error: [
"Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'",
"System info: host: '75136e9ec116', ip: '172.17.0.2', os.name: 'Linux', os.arch: 'amd64', os.version: '4.19.76-linuxkit', java.version: '1.8.0_252'",
'Driver info: driver.version: unknown'
],
message: 'Timed out waiting for driver server to start.'
},
status: 13
⚠ Error connecting to 127.0.0.1 on port 4444.
_________________________________________________
TEST FAILURE: 1 error during execution; 0 tests failed, 0 passed (24.402s)
✖ route-subdomain-dashboard-test
An error occurred while retrieving a new session: "Timed out waiting for driver server to start."
Error: An error occurred while retrieving a new session: "Timed out waiting for driver server to start."
at endReadableNT (_stream_readable.js:1224:12)
at processTicksAndRejections (internal/process/task_queues.js:84:21)
Error: An error occurred while retrieving a new session: "Timed out waiting for driver server to start."
at endReadableNT (_stream_readable.js:1224:12)
at processTicksAndRejections (internal/process/task_queues.js:84:21)
The question
Is there anything I am missing that would allow the command to be successfully executed through the bash script? Why am I seeing such disparate results?
The appreciation
Sorry for the long post, but I think I needed to provide as much context as possible, since it seems a very tricky problem that I've been struggling for quite some time now.
Many thanks in advance 🙏
Updates
02/10/2020 - I realised today that once inside the docker image, if I execute the npm test command in order to run the tests, I have the issue described under the section named The problem. However, if I run the bash script that I created and that npm test command is calling under the hood, I have the tests successfully executed. Could it be the way that npm executes the scripts?

New relic infra agent not restarted

We are using New Relic infrastructure agent from last 2 yrs but after 13th Nov 2019 suddenly its not working. Then I update the version of newrelic to 5.2.3.131. But the problem is not resolve. The problem is i’m unable to restart new relic infra agent.
I used below commands…
echo “license_key: ${NEW_RELIC_LICENSE_KEY}” | sudo tee /etc/newrelic-infra.yml
sudo curl -o /etc/yum.repos.d/newrelic-infra.repo https://download.newrelic.com/infrastructure_agent/linux/yum/el/6/x86_64/newrelic-infra.repo
sudo yum -q makecache -y --disablerepo=’*’ --enablerepo=‘newrelic-infra’
sudo yum install newrelic-infra -y
sudo initctl restart newrelic-infra
Application hosted aws elastic beanstalk.
I’m getting initctl: Unknown instance.
Deatails error are below…
INFO [7168] - [Application update pem.pem-staging.f6e105eb760.20191117-164558#668/AppDeployStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild/postbuild_1_PEM/Command 04-configure_new_relic] : Activity execution failed, because: license_key: XXXXXXXXXXXXXXXX
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:–:-- --:–:-- --:–:-- 0
100 239 100 239 0 0 2091 0 --:–:-- --:–:-- --:–:-- 2096
Loaded plugins: priorities, update-motd, upgrade-helper
Package newrelic-infra-1.7.1-1.x86_64 already installed and latest version
Nothing to do
initctl: Unknown instance:
(ElasticBeanstalk::ExternalInvocationError)
in my case it looks:
.ebextensions/new_relic.yml
packages:
yum:
newrelic-sysmond: []
rpm:
newrelic: http://yum.newrelic.com/pub/newrelic/el5/x86_64/newrelic-repo-5-3.noarch.rpm
commands:
"01":
command: nrsysmond-config --set license_key=XXXXXXXXXXXXXXXXXXXX
"02":
command: echo hostname=$SERVER_URL >> /etc/newrelic/nrsysmond.cfg
"03":
command: /etc/init.d/newrelic-sysmond start
You might not need '02' command
Problem is new relic end. I have solved this temporarily by using below commands...
cat /etc/newrelic-infra.yml
ps aux | grep newrelic-infra
Just kill all processes returned by the ps command above with kill -9 pid1 pid2...
Then start the service with sudo initctl start newrelic-infra
It's now working fine.

Supervisor not starting .AppImage app

I have an Electron App packaged using an AppImage format, on a Debian 8 box. I would like to monitor and restart this app using supervisord (v3.0) but I just can't understand why it doesn't work.
This is how I successfully launch my app, manually:
/home/player/player.AppImage
Worth nothing that this app is not daemonized. If you close the current shell, you also close the app, as it should for an app to be tracked by supervisor.
Now, this is how my .conf file for supervisor looks like:
[program:player]
command=/home/player/player.AppImage
user=player
autostart=true
autorestart=true
startretries=3
This is what supervisor returns on "supervisor start player":
player: ERROR (abnormal termination)
What's in the logs:
2018-01-09 22:44:13,510 INFO exited: player (exit status 0; not expected)
2018-01-09 22:44:22,526 INFO spawned: 'player' with pid 18362
2018-01-09 22:44:22,925 INFO exited: player (exit status 0; not expected)
2018-01-09 22:44:32,967 INFO spawned: 'player' with pid 18450
2018-01-09 22:44:33,713 INFO exited: player (exit status 0; not expected)
2018-01-09 22:44:34,715 INFO gave up: player entered FATAL state, too many start retries too quickly
I also tried to use an intermediate shell script to start the main app but it also fails, even using "exec" to start the app.
FYI, this what I have on "ps ax" when I start the app manually:
19121 pts/1 Sl+ 0:00 /tmp/.mount_player5aT7Ib/app/player
19125 ? Ssl 0:01 ./player-1.0.0-i386.AppImage
19141 pts/1 S+ 0:00 /tmp/.mount_player5aT7Ib/app/player --type=zygote --no-sandbox
19162 pts/1 Sl+ 0:00 /tmp/.mount_player5aT7Ib/app/player --type=gpu-process --no-sandbox --supports-dual-gpus=false --gpu-driver-bug-workarounds=7,23,
19168 pts/1 Sl+ 0:01 /tmp/.mount_player5aT7Ib/app/player --type=renderer --no-sandbox --primordial-pipe-token=EE7AFB262A1393E7D97C54C3C42F901B --lang=1
I can't find anything related to the AppImage format in the Supervisor docs, is there anything special about it and do you see any workaround to make this to work?
Thanks for your help
I gave up with Supervisor and ended up using God (Ruby based). Works perfectly with this kind of App.

selenium rc killing firefox at random points for no reason

I'm running test using behat, but this basically runs phpunits selenium driver, to do integration tests
everything was working fine but for no apparent reason firefox quits at some point in the middle of my test suite the selenium rc log looks like this
09:23:53.157 INFO - Command request: setTimeout[30000, ] on session 62b513ea550a419898a79f912beecc69
09:23:53.180 INFO - Got result: OK on session 62b513ea550a419898a79f912beecc69
09:23:53.263 INFO - Command request: open[/request/step1, ] on session 62b513ea550a419898a79f912beecc69
09:23:53.318 INFO - Got result: XHR ERROR: URL = http://local-test.account/request/step1 Response_Code = -1 Error_Message = Request Error on session 62b513ea550a419898a79f912beecc69
09:23:53.321 INFO - Command request: testComplete[, ] on session 62b513ea550a419898a79f912beecc69
09:23:53.321 INFO - Killing Firefox...
09:23:53.356 INFO - Got result: OK on session 62b513ea550a419898a79f912beecc69
09:23:53.371 INFO - Command request: open[/request/step1, ] on session null
09:23:53.374 ERROR - Exception running 'open 'command on session null
at what point in the test it quits doesn't seem to follow any pattern.
i've tried rolling my projects code back to before I was having problems but to no avail
If you are using Selenium 1.3, try upgrading to Selenium 2.0. Here is how I resolved my problem with selenium.open();
This is possible when you are not passing correct website address. What are you passing, what is the URL of your website.

Can't open Firefox with profile (not temporary) with Selenium

I want start firefox with my custom profile, and when I add some plugins (for example) in this session starting from selenium I want he do not forgot them.
I started selenium server
start "JAVA Selenium Server" java -jar selenium-server.jar -interactive -firefoxProfileTemplate "D:\Ogame\SeleniumStaticProfile"
Then in selenium server
cmd=getNewBrowserSession&1=*custom firefox.exe -p SeleniumStatic -no-remote&2=http://www.google.com
cmd=open&1=httttp://www.hotmail.com
cmd=open&1=httttp://www.google.pl
and i'm gettings error something like:
www.goole.com havent rights to read properties Window.seleniumMarker1299...
All log:
cmd=getNewBrowserSession&1=*custom firefox.exe -p SeleniumStatic
-no-remote&2=ht tttp://www.google.com 13:54:50.817 INFO - ---> Requesting
htttttp://localhost:4444/selenium-server/driver
?cmd=getNewBrowserSession&1=*custom
firefox.exe -p SeleniumStatic
-no-remote&2=h tttttp://www.google.com 13:54:50.823 INFO - Command request:
getNewBrowserSession[*custom
firefox.exe -p SeleniumStatic
-no-remote, htttttp://www.google.com] on session null 13:54:50.824 INFO -
creating new remote session
13:54:50.832 INFO - Allocated session
ad3e48137d024959863ab8bb4c297d55 for
httttp: //www.google.com, launching...
13:54:54.615 INFO - Got result:
OK,ad3e48137d024959863ab8bb4c297d55 on
session a
d3e48137d024959863ab8bb4c297d55
cmd=open&1=http://www.wp.pl
13:55:23.588 INFO - ---> Requesting
httttp://localhost:4444/selenium-server/driver
?cmd=open&1=htttttp://www.wp.pl&sessionId=ad3e48137d024959863ab8bb4c297d55
13:55:23.595 INFO - Command request:
open[htttttp://www.wp.pl, ] on session
ad3e481 37d024959863ab8bb4c297d55
13:55:23.596 WARN - you appear to be
changing domains from
httttp://www.google.com to
htttttp://www.wp.pl this may lead to a
'Permission denied' from the browser
(unless it is running as *iehta or
*chrome, or alternatively the selenium server is runnttting in proxy
injection mode) 13:55:23.691 INFO -
Got result: Witrynie
http://www.google.com nie udzielono
u prawnien do odczytania wlasciwosci
Window.document z
on sessi on
ad3e48137d024959863ab8bb4c297d55
Of course I have entered proxy in Firefox SeleniumStatic profile (localhost:4444)
What am I doing wrong?
Sorry for my bad english :/
Change your commands to look like the following
cmd=getNewBrowserSession&1=*firefox -no-remote&2=http://www.google.com
cmd=open&1=httttp://www.hotmail.com
cmd=open&1=httttp://www.google.pl
YOu don't need to specify the profile since you have already done that when starting the Selenium Server.

Resources