Skip to content

Instantly share code, notes, and snippets.

@tyndyll
Forked from mcbhenwood/run_customer_tests.py
Created July 26, 2016 13:22
Show Gist options
  • Select an option

  • Save tyndyll/dac557c1dc81dbacfb6402eb7267d113 to your computer and use it in GitHub Desktop.

Select an option

Save tyndyll/dac557c1dc81dbacfb6402eb7267d113 to your computer and use it in GitHub Desktop.

Revisions

  1. @mcbhenwood mcbhenwood revised this gist Nov 8, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion run_customer_tests.py
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,7 @@
    Requires Xvfb and IceWeasel to be installed. For Debian flavours:
    sudo apt-get install xvfm iceweasel
    sudo apt-get install xvfb iceweasel
    For details, see:
    http://pyuseful.wordpress.com/2012/11/08/running-cucumber-style-tests-in-django-using-behave/
  2. @mcbhenwood mcbhenwood revised this gist Nov 8, 2012. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion run_customer_tests.py
    Original file line number Diff line number Diff line change
    @@ -8,6 +8,9 @@
    sudo apt-get install xvfm iceweasel
    For details, see:
    http://pyuseful.wordpress.com/2012/11/08/running-cucumber-style-tests-in-django-using-behave/
    """
    import os
    from os.path import abspath, join, split
    @@ -47,4 +50,4 @@ def run():


    if __name__ == '__main__':
    run()
    run()
  3. @mcbhenwood mcbhenwood created this gist Nov 8, 2012.
    50 changes: 50 additions & 0 deletions run_customer_tests.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,50 @@
    """
    Run Selenium headless tests against Django test server
    ------------------------------------------------------
    Creates and destroys a test environment each time.
    Requires Xvfb and IceWeasel to be installed. For Debian flavours:
    sudo apt-get install xvfm iceweasel
    """
    import os
    from os.path import abspath, join, split
    import subprocess
    import sys
    import time

    from behave.__main__ import main as behave_main

    DJANGO_PROJECT_DIR = 'djangoproject' # Substitute your top level Django project folder name

    if __name__ == '__main__':
    project_dir = split(abspath(__file__))[0]
    sys.path.insert(0, join(project_dir, DJANGO_PROJECT_DIR))


    def run():
    print('Starting django testserver')
    django_process = subprocess.Popen(
    ['python', join(DJANGO_PROJECT_DIR, 'manage.py'), 'testserver', '--noinput'],
    stdout=open('/dev/null', 'w'),
    stderr=open('/dev/null', 'w'))
    time.sleep(2)

    print('Starting Xvfb')
    xvfb_process = subprocess.Popen(
    ['Xvfb', ':99', '-ac', '-screen', '0', '1024x768x8'])
    os.environ["DISPLAY"] = ":99"

    try:
    behave_main() # This calls sys.exit() under all circumstances
    finally:
    print('Stopping django testserver')
    django_process.terminate()
    print('Stopping Xvfb')
    xvfb_process.terminate()


    if __name__ == '__main__':
    run()