I'm setting up crontab job to run my automation test script which invokes browser and does some testing.

Below is how I started setup cron job at 10:30 every day. The .py file invokes firefox browser and does some testing

30 10 * * * python3 -u /home/Desktop/automation_script.py 2>&1 | tee /etc/cron.daily/automationlog.txt

But this ended up in an error:

Traceback (most recent call last):
  File "/home/automatedqa/workspace/UNIFIED_QA_TESTING/branches/AutoTestRailQA/src/nightly_run_tests.py", line 15, in <module>
    rack1 = rack.RACK(sys.argv[1], sys.argv[2])             # the rack module contains a lot of equipment combinations which must be configured before running the tests.
  File "/home/automatedqa/workspace/UNIFIED_QA_TESTING/branches/AutoTestRailQA/src/rack.py", line 260, in __init__
    self.driver = webdriver.Firefox(firefox_profile=fp)
  File "/usr/local/lib/python3.4/dist-packages/selenium/webdriver/firefox/webdriver.py", line 103, in __init__
    self.binary, timeout)
  File "/usr/local/lib/python3.4/dist-packages/selenium/webdriver/firefox/extension_connection.py", line 51, in __init__
    self.binary.launch_browser(self.profile, timeout=timeout)
  File "/usr/local/lib/python3.4/dist-packages/selenium/webdriver/firefox/firefox_binary.py", line 68, in launch_browser
  File "/usr/local/lib/python3.4/dist-packages/selenium/webdriver/firefox/firefox_binary.py", line 98, in _wait_until_connectable
    raise WebDriverException("The browser appears to have exited "
selenium.common.exceptions.WebDriverException: Message: The browser appears to have exited before we could connect. If you specified a log_file in the FirefoxBinary constructor, check it for details.

If I try to run


from the terminal, the script runs and browser invokes successfully.

It didn't work when tried to run it from crontab job.

Can anyone help me on this?

  • 1
    Since the script runs properly from shell, but not from cron, look at your evnironment variables. For example, cron has no idea which $DISPLAY you are using...until you tell it. – user535733 Jan 22 '18 at 17:30
  • Also make sure to set the correct PATH environment within the crontab config. Cron also might not be able to start a GUI .. maybe that's it? – derHugo Jan 22 '18 at 17:36
  • thanks user535733 and derHugo. I tried "30 10 * * * env DISPLAY=:0 python3 -u /home/Desktop/automation_script.py 2>&1 | tee /etc/cron.daily/automationlog.txt" and it worked in one of my VM but didn't worked it my second VM, I tried with 30 10 * * * export DISPLAY=:0 python3 -u /home/Desktop/automation_script.py 2>&1 | tee /etc/cron.daily/automationlog.txt this workrs in my second VM. May I know whats the differenceAm I using it right way ??? – Shiva Nelli Jan 22 '18 at 19:28
  • 2
    Possible duplicate of How to start a GUI application from cron? – muru Jan 27 '18 at 4:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.