我在 windows 7 机器上有 python 3.5,这台机器没有任何其他 python 版本。
pip 附带 python 3.5 安装。
我用pip来安装selenium
库
pip install selenium
Run Code Online (Sandbox Code Playgroud)
它在以下位置安装了库:
AppData\Local\VirtualStore\
Program Files (x86)\Python 3.5\Lib\site-packages\
但是像pycharm这样的IDE看起来:
C:\Program Files (x86)\Python 3.5\Lib\site-packages\
这就是它应该安装的地方。
由于此 IDE 无法识别库,因此我无法在 IDE 中获得任何帮助。
作为一种解决方法,我将库复制到所需的文件夹并且它正在运行,但我想知道如何配置 pip 以立即安装 C:\Program Files (x86)\Python 3.5\Lib\site-packages\
我有一个返回如下值的fixture:
import pytest
@pytest.yield_fixture(scope="module")
def oneTimeSetUp(browser):
print("Running one time setUp")
if browser == 'firefox':
driver = webdriver.Firefox()
print("Running tests on FF")
else:
driver = webdriver.Chrome()
print("Running tests on chrome")
yield driver
print("Running one time tearDown")
Run Code Online (Sandbox Code Playgroud)
此夹具从另一个夹具中获取浏览器值,该夹具正在读取命令行选项.
然后我有一个测试类,我有多个测试方法,他们都想使用相同的返回值驱动程序来进行测试.
import pytest
@pytest.mark.usefixtures("oneTimeSetUp")
class TestClassDemo():
def test_methodA(self):
# I would like to use the driver value here
# How could I do this?
# Something like this
self.driver.get("https://www.google.com")
self.driver.find_element(By.ID, "some id")
print("Running method A")
def test_methodB(self):
print("Running method B")
Run Code Online (Sandbox Code Playgroud)
使用self.driver失败并显示错误消息
self = <test_class_demo.TestClassDemo …
Run Code Online (Sandbox Code Playgroud) 我正在尝试学习python在测试项目上的工作。有没有一种方法可以在Python测试框架中实现类似功能的TestNG侦听器。
侦听器具有OnTestFailure(),OnTestSuccess,OnStart()等方法,这些方法在您要做某些事情时确实很有用。
假设一个测试用例失败,并且您想执行一些操作,例如截屏。然后,您可以将其写在一个地方,而不必在每个afterTest方法中都写。