我尝试在 exe 文件中构建 python selenium 测试,并在许多机器上运行它,以保持测试独立于环境。但结果 *.exe 文件找不到 selenium webdriver。如何在 *.exe 文件中包含所有硒依赖项?或者也许还有其他方法吗?
可以制作虚拟环境并分发吗?
我假设您正在使用 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,
}
}
)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)