Selenium WebDriver Firefox - php

I'm running a LAMP configuration on Ubuntu Server 13.04. I setup XVFB and Selenium to load on startup as services (/etc/init.d). Firefox is working if I export DISPLAY before opening it in a terminal session, however I'm not attempting to test in a terminal session; I'm using PHPWebDriver to call an instance of WebDriver.
When attempting to open a session as so:
$driver_include = "/includes/user/webdriver/__init__.php";
require $driver_include;
$wd_host = 'http://localhost:4444/wd/hub';
$web_driver = new PHPWebDriver_WebDriver($wd_host);
$session = $web_driver->session('firefox');
I get the following error:
Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms.
I also have Xvfb set to DISPLAY :10. By exporting to this display I can open Firefox in a terminal.
My question is:
How do I tell WebDriver to use a certain DISPLAY by default without starting it manually from a terminal session?

I think you will be fine as long as you make sure that the Grid server is running in a shell WITHIN a windowed environment. It won't work if you start the grid outside of a windowed environment that is needed to start the Firefox profile. If you are trying to run headless, without a DISPLAY, then you should use GhostDriver/PhantomJS instead, or something similar.

Related

Set up one instance of ChromeDriver for Panther, rather than creating one for each request

I am using Symfony Panther for web scraping (not testing) in a PHP project that does not use Symfony. I installed via Composer. Each time I need to scrape a link submitted by a user, I start a new Chrome Browser.
$client = Symfony\Component\Panther\Client::createChromeClient('/usr/bin/chromedriver');
$client->request('GET', $url);
$crawler = $client->waitFor('body');
Starting a new Chrome browser for each submitted $url is slow and resource intensive, so I want to keep the Chrome Client running on port 9515 and then each user's $url request can connect to that one same instance. Based on some user comments on Github, it sounds like a reasonable method:
Spin up a Chrome instance on the Linux server, running on port 9515
Make each url request connect to that instance.
I placed the first line i.e. with createChromeClient in a php script for a CRON job, but it never starts up the chrome client, and I get no errors either. Any ideas how to achieve this?
"Not showing" the browser (Chrome here) is the default way, as it is faster. It is called "headless"
To show it, you have to specify "PANTHER_NO_HEADLESS" :
PANTHER_NO_HEADLESS=1 vendor/bin/phpunit -c phpunit.xml
also, you could check if chome is running with : (or any system log)
ps aux | grep chrome

Run R with no gui

I am trying to get a default installed CentOS7 R 3.2.3 running without GUI, just for the data processing. The following code runs fine on OSX with no gui output, but fails on CentOS. I start both as
Rscript script.r someMatrix.txt
theMatrix = as.matrix(read.table(args[1],header=TRUE,sep="\t",row.names = 1))
values = heatmap(theMatrix,keep.dendro=TRUE)
Error in dev.hold() : no active or default device
Calls: heatmap -> dev.hold
I am calling the R scirpt from a PHP script within Apache. So it maybe a bad environment setting for the Apache user, but I am using the system wide installed package, and running the script as another user without any special environment settings worked fine.

vagrant + virtualbox Timed out while waiting for the machine to boot

sorry I'm really new to vagrant I am running vagrant 1.4.3 and virtualbox 4.3.26. and my host OS is ubuntu 14.04.2.
I am a php developer and I'm trying to make my development environment ready for couple of projects.
and every box I try from vagrantbox.es I get the same error when running vagrant up command.
and the error is :
Timed out while waiting for the machine to boot. This means that
Vagrant was unable to communicate with the guest machine within
the configured ("config.vm.boot_timeout" value) time period. This can
mean a number of things.
If you're using a custom box, make sure that networking is properly
working and you're able to connect to the machine. It is a common
problem that networking isn't setup properly in these boxes.
Verify that authentication configurations are also setup properly,
as well.
If the box appears to be booting properly, you may want to increase
the timeout ("config.vm.boot_timeout") value.
I've looked through same questions and I tried
config.vm.provider :virtualbox do |vb|
vb.gui = true
end
after adding these lines I get login page in my box so its booting and I can run my commands in the GUI interface.
but surprisingly I get same error. I thought with myself maybe its because the guest OS couldn't login and I add these lines to my vagrant file
config.ssh.username = "vagrant"
config.ssh.password = "vagrant"
config.ssh.insert_key = "true"
but I get this error
There are errors in the configuration of this machine. Please fix
the following errors and try again:
SSH:
* The following settings shouldn't exist: insert_key, password
and actually I'm screwed and I don't know what else should I do .
go to in virtual box and stop the run connection. click on start and wait for login with user and pass: vagrant. inside of that write this command:
sudo vim /etc/systemd/system/network-online.targets.wants/networking.service
And changing the following line at the end of the file:
TimeoutStartSec=5min
to:
TimeoutStartSec=30sec
I have then rebooted the system and it works fine.
I upgraded my vagrant to 1.7.2 and my problem is solved now. but I don't see my box running in virtualbox interface . after all I can now ssh to my box and there is no problem.

How can I launch a local Application on OSX from php running MAMP?

I'm running a bunch of local Kiosks on mac mini's and have been using dropbox to keep all the files in sync. However - the dropbox updates have been sketchy as of late because of the firewall settings where these things are. A workaround I have found is by having dropbox quit and restart periodically to force it to update.
My question is - since all of these are running php applications on MAMP - is there a way to launch a local app from php? I'm able to kill dropbox by doing something like this:
$killit = killall -KILL Dropbox;
But it doesn't work the same to restart it. I've tried doing this:
$start_dbox = open /Applications/Dropbox.app;
To no avail. Is there a better way to automate this process of shutting down and reopening a local application?
I've had similar problems trying to control software remotely. The 'open' command must be executed either as the currently logged in console user, or from a terminal owned by the console (e.g. Terminal.app).
If you change your PHP to redirect STDERR, you should see the error that 'open' is returning:
$start_dbox = "open /Applications/Dropbox.app 2>&1";
The following text should then be returned from the system call:
LSOpenURLsWithRole() failed with error -10810 for the file /Applications/Dropbox.app.
One workaround I've used in the past is to create a lock file somewhere in the filesystem, which your PHP script can write to and your console user can read. Then, you can create a cron that runs as the console user and periodically checks the lock file to see if it needs to restart Dropbox.
I was actually able to solve this by creating a shell script with the following:
#!/bin/sh
export DYLD_LIBRARY_PATH=""
osascript -e 'tell application "Dropbox" to activate'
Saved it as start_db.sh and dropped it in my root apache directory (so there was no permissions problem for that user).
Then in my php file I was able to do:
$start_dbox = exec('/full/path/to/start_db.sh');
Worked like a charm. Dropbox now quits and restarts with no issues.

Server side script for launching application

I have been trying unsuccessfully so far to write a php script that will run when a page is opened and that will launch metasploit!
I ve tried shell_exec and exec and all the other alternatives but although I can get it to do simple things (i.e. ls, cds etc) if I try msfconsole it doesnt do anything!
I have also tried a different script that launches firefox and again nothing happens!
Now i know that php runs on the server and I m not expecting to see a console or firefox opening in the clients machine! Instead in order to check if it works I am trying to echo out the output of the shell_exec!But anyway since im hosting the files on my machine (i.e. this is the server and a VM is the client) if it could actually launch firefox i should be able to see the app opening here in the same way as by just doing this from the command line!
What am I missing?
Is there any other way to do this?(i.e. Launch metasploit everytime a user opens up my page)
NOTE: I've tried specifying the full path for msfconsole but that didnt work either!
Heres what I have so far:
$output = shell_exec('/opt/local/libexec/metasploit3/msfconsole;show');
echo "<pre>$output</pre>";
The ";show" bit was used in order to actually make it run something and print some stuff but didnt make any difference!
When you run a gui application from the command prompt in a X window system, it will use the default display. When you run it using php which is embedded in apache webserver, the program may not know where to display the gui application.
there are 2 things to make this work.
The program that executes the gui application must have permission to use display
you need to tell the program which display to use.
I used the following in my php script
<?php
$cmd = `export DISPLAY=:0; gedit`;
shell_exec($cmd);
?>
and ran the script from terminal using php -f test.php
I got the gedit up and running.
You can test the same with the script in apache too.
Please add apache user with privileges to access display server
update: I just added the following in /etc/apache2/apache2.conf (I am using ubuntu)
User poomalai
Group poomalai
and restarted the web server
sudo service apache2 restart
now I accessed localhost/test.php
and Presto!! I got the gedit :)
Hope this helps

Categories