草庐IT

pytest-selenium

全部标签

python - 如何使用 pytest 为覆盖率报告设置不同的 html 输出目录?

将覆盖与pytests结合使用是一个非常有用的工具。Html报告允许很好的输出,但是通过命令行找不到修改默认输出目录(htmlcov)的选项示例命令行:python-mpytestlib_being_tested\tests--covlib_being_tested.module--cov-report=html 最佳答案 现在(3年后)您可以直接在命令行中更改默认输出目录:python-mpytest--cov--cov-report=html:reports/html_dir--cov-report=xml:reports/co

python - 使用 Python 使用 Selenium 设置 chromedriver 代理身份验证

我正在使用Python和Selenium库编写测试套件。使用chromedriver,我设置代理使用:chrome_options=webdriver.ChromeOptions()chrome_options.add_argument('--proxy-server=%s'%hostname+":"+port)globaldriverdriver=webdriver.Chrome(chrome_options=chrome_options)当代理没有身份验证时,这可以正常工作。但是,如果代理要求您使用用户名和密码登录,它将不起作用。使用add_argument或其他方法将代理身份验证

python - 在 PyDev 中使用 virtualenv 运行 Selenium Chrome 时如何解决 "chromedriver executable needs to be in PATH"错误?

短的:在https://automatetheboringstuff.com/chapter11阅读ControllingtheBrowserwiththeseleniumModuleathttps://www.dabapps.com/blog/introduction-to-pip-and-virtualenv-python/后,我试图在PyDev的虚拟环境中运行SeleniumChrome驱动程序。我已经设法从PyDev外部做到了,但从内部,我得到:selenium.common.exceptions.WebDriverException:Message:'chromedriver

python - 使用 Selenium 模块创建 Exe : Py2exe/Pyinstaller

我到处都看过了。Stackoverflow、各种留言板、py2exe网站、pyinstaller网站……没有任何帮助。包括selenium模块,特别是制作支持firefox的exe,似乎是不可能的。我开始拔头发,因为使用py2exe和pyinstaller变得非常头疼。py2exe和pyinstaller都有各自的问题。我的目标是制作一个单独的exe文件,没有任何额外的目录,这样其他人如果没有python/modules也可以使用我的程序。使用py2exe,如果我这样创建一个setup.py文件fromdistutils.coreimportsetupimportpy2exesetup

python - Selenium webdriver 的工厂模式

目前我正在尝试使用Selenium和Proboscis编写一个自动化测试套件。我正在尝试抽象webdriver并通过工厂模式实现。Page_object类也是在这里创建的,它在创建对象时将webdriver作为参数。下面是代码。importselenium.webdriveraswebdriverfromproboscisimportTestProgramfromproboscisimporttestfromproboscisimportbefore_classfromproboscisimportafter_classclassWebdriverFactory:@staticmeth

python - 如何在 Python 上使用 selenium webdriver 和 browsermob 代理捕获网络流量?

我想通过在Python上使用SeleniumWebdriver来捕获网络流量。因此,我必须使用代理(如BrowserMobProxy)当我使用webdriver.Chrome时:frombrowsermobproxyimportServerserver=Server("~/browsermob-proxy")server.start()proxy=server.create_proxy()fromseleniumimportwebdriverco=webdriver.ChromeOptions()co.add_argument('--proxy-server={host}:{port}

python - 在子文件夹中使用 pytest where test

我正在使用pythonpytest来运行我的单元测试。我的项目文件夹是:Main-包含数据文件:A.txtMain\Tests-我运行pytest的文件夹Main\Tests\A_test-包含测试文件的文件夹A_test文件夹中的测试使用文件A.txt(位于Main文件夹中)。我的问题是,当我运行py.test时,测试失败,因为它找不到A.txt。我发现是因为pytest在运行测试时使用了路径Main\Test,而不是将路径改为Main\Tests\A_test(我是在测试文件中打开A.txt时使用相对路径)我的问题:有没有办法让pytest将目录更改为它为每个测试执行的测试文件夹?

python - Selenium 无法连接到 GhostDriver(但只是有时)

我已经使用Selenium和PhantomJS在Python中设置了一个简单的网络抓取脚本。我总共有大约200个URL需要抓取。该脚本起初运行良好,然后在大约20-30个URL之后(它可能更多/更少,因为它在失败时看起来是随机的并且与任何特定URL无关)我在python中收到以下错误:selenium.common.exceptions.WebDriverException:Message:'CannotconnecttoGhostDriver'还有我的ghostdriver.log:PhantomJSislaunchingGhostDriver...[ERROR-2014-07-04

python - 如何使用 pytest 测试 Django 模型?

我正在开始使用pytest。我已经配置了pytest,无论如何我找不到关于使用pytest进行Django特定测试的资源。如何使用pytest_django测试模型?我已经问了一个关于单元测试的问题,howdoIefficientlytestthisDjangomodel?我想知道如何使用py.test编写相同的测试?在模型下方添加用unittest编写的测试。被测模型是,classUser(AbstractBaseUser,PermissionsMixin):username=models.CharField(max_length=25,unique=True,error_messa

python - 使用 selenium 和 firefox 保存图像

我正在尝试使用selenium服务器和python客户端从网站保存图像。我知道图像的URL,但我找不到保存它的代码,无论是文档本身还是嵌入在当前浏览器session中。到目前为止我找到的解决方法是保存页面的屏幕截图(有2种selenium方法可以做到这一点),但我想要原始图像。我不介意摆弄点击菜单选项等,但我找不到方法。谢谢 最佳答案 我找到了将图像放入Canvas,然后将其转换为数据的代码——例如,然后可以对其进行base64编码。我的想法是在selenium中使用eval命令来调用它,但是在我的测试中,toDataURL抛出了安