Crontab failing launch firefox browser

2,087 views
Skip to first unread message

visa

unread,
Mar 22, 2010, 6:21:43 AM3/22/10
to Selenium Users
When i am running seleniumtests normally ,they are running,...but when
i am sheduled the tests to run each an hour using crontab,the
following error is coming:
15:30:03.694 INFO - Checking Resource aliases
15:30:03.698 INFO - Command request: getNewBrowserSession[*chrome,
http://www.flipkart.com, ] on session null
15:30:03.700 INFO - creating new remote session
15:30:03.773 INFO - Allocated session 4105b2ad9d3448a4a3e1dba1cd660690
for http://www.flipkart.com, launching...
15:30:03.794 INFO - Preparing Firefox profile...
Error: no display specified
15:30:23.823 ERROR - Failed to start new browser session, shutdown
browser and clear all session data

Mark Collin

unread,
Mar 22, 2010, 6:45:38 AM3/22/10
to seleniu...@googlegroups.com
It's probably trying to run it without a GUI try something like:

gnome-terminal --tab --title="<yourTitleHere>"
--working-directory=<yourPathToSeleniumHere> --display=:0.0 -x sh -c
"<yourSeleniumCommandHere>" &

This is of course assuming you are running gnome.

> --
> You received this message because you are subscribed to the Google Groups
> "Selenium Users" group.
> To post to this group, send email to seleniu...@googlegroups.com.
> To unsubscribe from this group, send email to
> selenium-user...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/selenium-users?hl=en.
>
>


--
This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited.

If you have received this email in error please notify postm...@ardescosolutions.com

Jayakumar C

unread,
Mar 22, 2010, 7:23:38 AM3/22/10
to seleniu...@googlegroups.com
Be sure that your cron job entry(in the crontab file) is executed with appropriate user privileges.
you can ensure that by entering the username just after the cron expression .


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.




--
Thanks,
Jayakumar

de...@boomboxtesting.com

unread,
Mar 22, 2010, 1:40:25 PM3/22/10
to Selenium Users
Cron has the environment specified when cron launched, which is at
startup. When you run as a user, cron will add the home directory of
the user as HOME and dispatch the job as that user. The rest of the
environment is not present unless you put it there.

It's difficult to run complex jobs like this from cron where you
require an Xsession, like this selenium session which wants to run
Firefox, an X app. That's what the error is telling you, that
selenium can't run an X application. X requires, well X, and a lot of
environment, none of which are around with cron.

You could get an active X session going, then use 'at' instead of
cron. At preserves all the environment present when the at-job was
created. The issue with at is that it doesn't have the recurrent
scheduling of cron, but there is a workaround. If the job needs to
repeat, you could make a shell script that does what you need, then re-
creates an at job at the end of the shell script, then install this
script as the at job. It will repeat because it re-installs itself.
Then just keep this X session going.

I have also set things up so that DISPLAY 0, the console, is available
to run the firefox session from cron -- or an active x session of a
user on whatever DISPLAY. This required carefully setting up the
environment as well as xhost to allow the cron user to be able to
launch apps on the DISPLAY.

For me, a better way is to run a vnc session. Vnc creates an X
session inside it. Inside the vnc session, get everything set up
nicely to run your test from a terminal. You could capture the
environment of this session from this terminal by dumping it with
printenv. You can then put this environment in a file and make it
part of what you call from cron, like a shell script that you set up
to call from cron. Depending on the way you go, you might have to do
something with xhost to give the cron user permission to create
programs in the vnc display.

If I was setting something up, I would use the vnc with at and not use
cron at all. It isn't X-app friendly.

On Mar 22, 4:21 am, visa <vidyasagar...@gmail.com> wrote:
> When i am running seleniumtests normally ,they are running,...but when
> i am sheduled the tests to run each an hour using crontab,the
> following error is coming:
> 15:30:03.694 INFO - Checking Resource aliases

> 15:30:03.698 INFO - Command request: getNewBrowserSession[*chrome,http://www.flipkart.com, ] on session null


> 15:30:03.700 INFO - creating new remote session
> 15:30:03.773 INFO - Allocated session 4105b2ad9d3448a4a3e1dba1cd660690

> forhttp://www.flipkart.com, launching...

visa

unread,
Mar 23, 2010, 4:27:04 AM3/23/10
to Selenium Users
How to give all priviliges to crontab in order to run the script
without finding any difficulties?

de...@boomboxtesting.com

unread,
Mar 23, 2010, 9:50:56 AM3/23/10
to Selenium Users
Get logged on with your X session, with Firefox working under
Selenium.
Dump the environment to a file by opening a terminal and running the
following:
$>printenv >selenium_from_cron.sh
If you repeat this procedure, be aware that the previous step replaces
the contents of the file.
Edit the file in a text editor. You will see a pile of environmental
variables in the file.
Add the following as the first line of the file: #!/bin/bash
This tells the shell to execute this file with bash.
Skip to the end of the file, after all the environmental variables.
Add the following line: java -jar <path to your selenium>/selenium-
server-1.x.x.jar <whatever other command line options you may have>
Replace the stuff inside the <> with your particulars.
This executes your selenium remote control server.
Exit your text editor.
In a terminal, make sure that your script is executable as follows:
$>chmod +x selenium_from_cron.sh

You will now need to make sure all users on the local host can connect
to your X session. Do this with the following:
$>xhost +localhost:

Add your selenium_from_cron.sh file as your cron job as you did
before.

Now, disable all the screen savers and autologout that you have so
that this X session remains active. As long as this X session is
active, this approach will work. If the machine reboots, you will
have to restart this X session. This is the weakness of this
approach.

There are several workarounds to this weakness if you are interested.
One is to have an X session brought up on the console on startup
instead of bringing up gdm or other X-based logon manager. Then, use
this X session as the target of your selenium cron job. The other is
to bring up a X-based vnc session on startup and make this session the
target of your selenium tests. These would require more setup.

de...@boomboxtesting.com

unread,
Mar 23, 2010, 12:00:22 PM3/23/10
to Selenium Users
Also, forgot to mention about the environmental variables in your
script. You must put 'export ' before them. You don't need them all,
and without knowing how much you might already know about unix/linux,
you for sure need DISPLAY, JAVA_HOME, CLASSPATH, PATH, HOME,
LD_LIBRARY_PATH ... many of the others are generated by the shell or
not pertinent to java or FireFox.

On Mar 23, 2:27 am, visa <vidyasagar...@gmail.com> wrote:

Reply all
Reply to author
Forward
0 new messages