简体   繁体   中英

Firefox Webdriver Selenium “No protocol specified” , Debian(Wheezy) , Service , Script

i have got a problem with my executable jar on my cubietruck running on cubian. I want to start the jar when the cubietruck starts. The Jar itselfs uses selenium-server-standalone-2.43.1.jar to control firefox.

For starting my jar i created a simple bash script ('/usr/local/bin/startplt.sh')

#!/bin/bash

PATH=/bin:/sbin:
JAVA=/usr/bin/java
JARFILE=/home/cubie/plt/plt.jar
USER=cubie

/bin/su -$USER -c "$JAVA -jar $JARFILE"

Executing this script in Console works and opens firefox successful. For getting my jar to start at startup i created a service ('/etc/init.d/startjar')

#! /bin/sh
### BEGIN INIT INFO
# Provides:          startjar
# Required-Start:    $all
# Required-Stop:     $remote_fs $syslog $local_fs $network
# Default-Start:    2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Starts plt.jar
# Description:       starts a the main jarfile
### END INIT INFO

NAME="startjar"
DESC="Starts /home/cubie/plt/plt.jar"

case "$1" in
  start)
        export DISPLAY=:0.0
        sudo /usr/local/bin/startplt.sh
    ;;
  stop)
    pkill -f /home/cubie/plt/plt.jar
    pkill -f iceweasel
    ;;
  *)
    exit 1
    ;;
esac
exit 0

And inserted it to system by:

insserv /etc/init.d/startjar

The service gets executed at startup but it doesnt start firefox. Instead its writing in the logfile :

org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port             056 after 45000 ms. Firefox console output:
No protocol specified
Error: cannot open display: :0.0
No protocol specified
Error: cannot open display: :0.0

at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:118)
at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:246)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:114)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:193)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:186)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:182)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:95)
at de.etc.plt.display.DisplayManager.<init>(DisplayManager.java:20)
at de.etc.plt.display.DisplayManager.getInstance(DisplayManager.java:26)
at de.etc.plt.service.impl.DisplayService.<init>(DisplayService.java:25)
at de.etc.plt.MainThread.run(MainThread.java:33)
at java.lang.Thread.run(Thread.java:745)
2014-10-09 12:25:27 [ERROR]:Firefox konnte nicht gestartet werden
2014-10-09 12:25:27 [org.openqa.selenium.WebDriverException]:Failed to connect to binary     FirefoxBinary(/usr/bin/firefox) on port 7056; process output follows: 
No protocol specified
Error: cannot open display: :0.0
No protocol specified
Error: cannot open display: :0.0

Build info: version: '2.43.1', revision: '5163bce', time: '2014-09-10 16:27:33'
System info: host: 'Cubian', ip: '127.0.0.1', os.name: 'Linux', os.arch: 'arm', os.version: '3.4.79-sun7i', java.version: '1.7.0_65'
Driver info: driver.version: FirefoxDriver
org.openqa.selenium.WebDriverException: Failed to connect to binary FirefoxBinary(/usr/bin/firefox) on port 7056; process output follows: 
No protocol specified
Error: cannot open display: :0.0
No protocol specified
Error: cannot open display: :0.0

Build info: version: '2.43.1', revision: '5163bce', time: '2014-09-10 16:27:33'
System info: host: 'Cubian', ip: '127.0.0.1', os.name: 'Linux', os.arch: 'arm', os.version: '3.4.79-sun7i', java.version: '1.7.0_65'
Driver info: driver.version: FirefoxDriver
at     org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:130)
at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:246)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:114)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:193)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:186)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:182)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:95)
at de.etc.plt.display.DisplayManager.<init>(DisplayManager.java:20)
at de.etc.plt.display.DisplayManager.getInstance(DisplayManager.java:26)
at de.etc.plt.service.impl.DisplayService.<init>(DisplayService.java:25)
at de.etc.plt.MainThread.run(MainThread.java:33)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7056 after 45000 ms. Firefox console output:
No protocol specified
Error: cannot open display: :0.0
No protocol specified
Error: cannot open display: :0.0

at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:118)
... 11 more

I really dont understand why the simple script startplt.sh is working even without the extra added line export DISPLAY=:0.0 to get rid of the error "no display specified"

Maybe the service is starting before even the xserver started? I dont know how to find that out. Some Help would be really appreciated.

If you have another working solution for executing scripts after boot on cubian i would be happy too.

EDIT: I got firefox working via enabling multiple users to use the xserver with xhost + and then service startjar start . But still have the problem that it isnt working on start of the system

I fixed my issue by changing the startplt.sh to

#!/bin/bash

PATH=/bin:/sbin:
JAVA=/usr/bin/java
JARFILE=/home/cubie/plt/plt.jar
USER=cubie
DISPLAY=:0
export DISPLAY
xhost +

/bin/su -$USER -c "$JAVA -jar $JARFILE"

and removed that one line from the startjar service. the xhost + was needed to allow m< jar to use my xserver for setting up the firefox

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM