Frage

I try to build my python selenium tests in exe file and run it on many machines for keeping tests independent of the environment. But result *.exe file can't find selenium webdriver. How can I include all selenium dependencies in *.exe file? Or maybe is there some another way for it? Is it possible to make virtual environment and distribute it?

War es hilfreich?

Lösung

I am assuming you are using py2exe for generating exe. You will need to specify the location of selenium webdriver in the setup.py file.

Following code should help:

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,
            }
    }
)

Andere Tipps

Like most other binary, it's probably required to include the DLL or whatever library you need, with the binary file. For example:

C:\tests\
  run_tests.exe -- this will read from webdriver.dll
  selenium-webdriver.dll 

Also, from my .NET days i know that you were able to actually embed the library straight into the EXE, which makes it rather large.

You may try pyinstaller,it is simple to install and simple to use.

Install:

pip install pyinstaller

To exe:

pyinstaller yourprogram.py

This is old but I was looking for the same thing and I did have to dig in many different websites to find out my problem, so hopefully this will help others.

I was using py2exe to build my exe file but it didn't work so I decided trying pyinstaller and yeah, it worked.

Just gonna put the things in items to be more organized:

Py2exe: I first started with py2exe and I was getting error like this: python setup.py py2exe Invalid Syntax (asyncsupport.py, line 22)

I could fix it by deleting some of the things in the setup file, it looked like this in the end.

data_files = [('selenium/webdriver/chrome', ['C:\Python27\Lib\site-packages\selenium\webdriver\chrome\webdriver.py'])]

setup(
    name='General name of app',
    version='1.0',
    description='General description of app',
    author='author name',
    author_email='author email',
    url='',
    windows=[{'script': 'final_headless.py'}],   # the main py file
    data_files=data_files,
    options={
        'py2exe':
            {
                'skip_archive': True,
                'optimize': 2,
                'excludes': 'jinja2.asyncsupport',
                'dll_excludes': ["MSVCP90.dll","HID.DLL", "w9xpopen.exe"]
            }
    }
)

It could run the py2exe but the exe file didn't work, then I moved to pyinstaller.

Pyinstaller: For me pyinstaller look way easier than py2exe, so I am keeping with this from now. We only "problem" was that without the webdriver in the path the exe doesn't run. But as soon as you have it in your variables path you are good to go.

Conclusion, using pyinstaller was my solution + adding webdriver to path.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top