无眉毛硒测试

2024-03-29 14:38:06 发布

您现在位置:Python中文网/ 问答频道 /正文


Tags: python
3条回答

是的。只是install PhantomJS

然后,更改此行:

driver = webdriver.Firefox()

致:

driver = webdriver.PhantomJS()

其余代码不需要更改,也不会打开浏览器。


出于调试目的,在代码的不同步骤中使用driver.save_screenshot('screen.png'),或者重新切换回Firefox:

if os.getenv("environment") == "production":
    driver = webdriver.PhantomJS()
else:
    driver = webdriver.Firefox()

在Centos上设置(以根用户身份进行所有安装)

安装pip下载https://bootstrap.pypa.io/get-pip.py

python get-pip.py

安装selenium 如果您的系统上有pip,您可以简单地安装或升级Python绑定: pip安装-U selenium

或者,您可以从PyPI(例如selenium-2.53.1.tar.gz)下载源发行版,将其取消归档,然后运行:

python setup.py install

安装程序:pyvirtualdisplay

pip install pyvirtualdisplay

yum install Xvfb libXfont Xorg

然后修改脚本,在**和**中添加粗体行

**from pyvirtualdisplay import Display**
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest, time, re

class SeleniumDemo(unittest.TestCase):

    def setUp(self):
        **self.display = Display(visible=0, size=(800, 600))
        self.display.start()**
        self.driver = webdriver.Firefox()
        self.driver.implicitly_wait(30)
        self.base_url = "http://www.soastastore.com/"
        self.verificationErrors = []
        self.accept_next_alert = True


    def tearDown(self):`enter code here`
        self.driver.quit()
        ***self.display.stop()***
        self.assertEqual([], self.verificationErrors)

你可以运行Selenium headless,看看这个问题/答案:Is it possible to hide the browser in Selenium RC?

特别是对于性能负载测试,您应该看看 Apache JMeter

相关问题 更多 >