0

I wrote an automated test suite in Python, Selenium, and Behave. I am trying to execute my script with a bash file. The challenge here is that I want to create two separate scripts. One will run headless mode (build my docker file and run it headless in docker) while the other script will execute a non-headless one locally on my system> I was able to create the first one easily.

This is what I have done to my webconfig.py file.

from selenium import webdriver
from selenium.webdriver.chrome.options import Options


headless = True


class Driver:
    def __init__(self, driver):
        self.driver = driver
        if driver == "chrome":
            if headless:
                chrome_options = Options()
                chrome_options.add_argument("--headless")
                chrome_options.add_argument("--no-sandbox")
                chrome_options.add_argument("--disable-gpu")
                chrome_options.add_argument("--start-maximized")
                chrome_options.add_argument("--window-size=1920,1200")
                chrome_options.add_argument("--disable-dev-shm-usage")

                self.driver = webdriver.Chrome(chrome_options=chrome_options)
            else:
                self.driver = webdriver.Chrome()
        elif driver == "firefox":
            self.driver = webdriver.Firefox()
        else:
            print(f"{driver} is not defined.")

I am yet to write the Firefox implementation but I felt with this, I should be able to create a bash script where I can specify that headless=False and it should execute a visual regression locally. How can I achieve this?

  • This doesn't answer the question, the execution command for a behave framework is `behave` and not Python. I tried the `sys.argv` and all I got the file itself. – i_m_sanguine Apr 09 '21 at 07:47
  • I found a work around by using `export headless=0; behave` in the non-headless bash script and it worked. The caveat to this method is that I have to use `os.getenv('headless')` which refers to the value set in my .env file. – i_m_sanguine Apr 13 '21 at 21:38

0 Answers0