[英]Run Python Selenium Tests Headless
I'm having a little trouble getting Webdriver to run on a specific hub headless with Pyvirtualdisplay. 使用Pyvirtualdisplay使Webdriver在特定的集线器上运行时,我遇到了一些麻烦。 The following generic code works fine: 以下通用代码可以正常工作:
class TestHub4444TestClass01(unittest.TestCase):
def setUp(self):
self.display = Display(visible=0, size=(1920, 1080))
self.display.start()
self.driver = firefox.webdriver.WebDriver()
def test_hub_4444_test_case_01(self):
self.driver.get('http://google.com')
time.sleep(5)
def tearDown(self):
self.driver.close()
self.display.stop()
if __name__ == "__main__":
unittest.main()
However the following opens a borwser window when I try to assign Webdriver to the hub on port 4445. 但是,当我尝试将Webdriver分配给端口4445上的集线器时,以下内容将打开一个浏览器窗口。
class TestHub4445TestClass01(unittest.TestCase):
def setUp(self):
self.display = Display(visible=0, size=(1920, 1080))
self.display.start()
self.driver = WebDriver(command_executor='http://localhost:4445/wd/hub',
desired_capabilities={"browserName": "firefox",
"platform": "LINUX"})
def test_hub_4445_test_case_01(self):
self.driver.get('http://google.com')
time.sleep(5)
def tearDown(self):
self.driver.close()
self.display.stop()
if __name__ == "__main__":
unittest.main()
Even if you are unsure of the answer, any suggestions would be greatly appreciated and I will give them a shot. 即使您不确定答案,任何建议也将不胜感激,我会给他们一个机会。
In case anyone else receives something like 万一其他人收到类似的东西
WebDriverException: Message: u'Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:\nError: cannot open display: :99\nError:
Here are my commands in Ubuntu. 这是我在Ubuntu中的命令。 I went to my xvfb control script. 我去了我的xvfb控制脚本。
sudo ./xvfb
export DISPLAY=:99
java -jar selenium-server-standalone-2.37.0.jar -role node -hub http://localhost:4445/grid/register -port 5560
I have my xvfb script located in the same place as my selenium server jar. 我的xvfb脚本与硒服务器jar位于同一位置。 Here is my xvfb script. 这是我的xvfb脚本。
PIDFILE=/var/run/xvfb.pid
case "$1" in
start)
echo -n "Starting virtual X frame buffer: Xvfb"
exec start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile --background --exec $XVFB -- $XVFBARGS
echo "."
;;
stop)
echo -n "Stopping virtual X frame buffer: Xvfb"
exec start-stop-daemon --stop --quiet --pidfile $PIDFILE
echo "."
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage: /etc/init.d/xvfb {start|stop|restart}"
exit 1
esac
exit 0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.