Firefox Webdriver Selenium"没有指定协议" ,Debian(Wheezy),服务,脚本

时间:2014-10-09 10:54:05

标签: java linux firefox selenium-webdriver startupscript

我的cubietruck上的可执行jar有问题,在cubian上运行。 当cubietruck开始时,我想启动jar。 Jar本身使用selenium-server-standalone-2.43.1.jar来控制firefox。

为了启动我的jar,我创建了一个简单的bash脚本(' /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"

在Console中执行此脚本并成功打开firefox。 为了让我的jar在启动时启动,我创建了一个服务(' /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

将其插入系统:

insserv /etc/init.d/startjar

该服务在启动时执行但它不启动Firefox。 而是在日志文件中写入:

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

我真的不明白为什么简单的脚本startplt.sh工作即使没有额外添加的行export DISPLAY=:0.0来摆脱错误&#34;没有指定显示&#34;

也许服务在xserver启动之前就开始了?我不知道如何找到它。一些帮助将非常感激。

如果你有另一个工作解决方案,用于在cubian上启动后执行脚本,我也会很高兴。

编辑:我通过允许多个用户将xserver与xhost +一起使用然后service startjar start来使Firefox运行起来。但仍有问题,它不能在系统启动时工作

1 个答案:

答案 0 :(得分:0)

我通过将startplt.sh更改为

来解决了我的问题
#!/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"

并从startjar服务中删除了这一行。 需要xhost +以允许m&lt; jar使用我的xserver来设置firefox