我尝试在 exe 文件中构建我的 python selenium 测试并在许多机器上运行它以保持测试独立于环境。但是结果 *.exe 文件找不到 selenium webdriver。如何在 *.exe 文件中包含所有 selenium 依赖项?或者也许还有其他方法吗? 是否可以制作虚拟环境并分发?
最佳答案
我假设您正在使用 py2exe 生成 exe。您需要在 setup.py 文件中指定 selenium webdriver 的位置。
以下代码应该有所帮助:
from distutils.core import setup
import py2exe
# Change the path in the following line for webdriver.xpi
data_files = [('selenium/webdriver/firefox', ['D:/Python27/Lib/site-packages/selenium/webdriver/firefox/webdriver.xpi'])]
setup(
name='General name of app',
version='1.0',
description='General description of app',
author='author name',
author_email='author email',
url='',
windows=[{'script': 'abc.py'}], # the main py file
data_files=data_files,
options={
'py2exe':
{
'skip_archive': True,
'optimize': 2,
}
}
)
关于python - 从 python selenium 测试制作 exe 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21098527/