python - 从 python selenium 测试制作 exe 文件

标签 python selenium pyinstaller

我尝试在 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/

相关文章:

Python - 将德语变音符号音译为变音符号

python - Python中的错误处理可以检测程序状态

java - 如何在selenium 2 WebDriver中查找当前使用的窗口是最大化还是最小化?

python - pyinstaller 缺少 mxnet dll

python - pyinstaller 不工作

python - 如何在 Windows 64 位上安装 ImageMagick 和 Anaconda?

python - python新手: code doesn't see global variable of one type but it does of another

java - 我得到一个 "exception in thread "main"java.lang.NoClassDefFoundError : org/openqa/selenium/WebDriver"

java - 我们可以使用 sikuli 来自动弹出 http 吗?

python-3.x - 如何修复 pyinstaller 缺少库错误