Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Headless mode #805

Merged
merged 9 commits into from
Jul 5, 2019
Merged

Headless mode #805

merged 9 commits into from
Jul 5, 2019

Conversation

byronz
Copy link
Contributor

@byronz byronz commented Jul 3, 2019

this solves #793

  • the headless mode option is added so you can do pytest --headless True, default is False
  • it might be useful for advanced testers to further configure the selenium options via a hook. the current solution opens the options object, I feel it's a good compromise here. But it might be good to know if users wanna full control on the webdriver construction.

Contributor Checklist

  • I have broken down my PR scope into the following TODO tasks
    • add headless mode
    • add hooks to configure webdriver options
  • I have run the tests locally and they passed. (refer to testing section in contributing)

optionals

  • I have added entry in the CHANGELOG.md
  • If this PR needs a follow-up in dash docs, community thread, I have mentioned the relevant URLS as follow

@byronz
Copy link
Contributor Author

byronz commented Jul 3, 2019

@mmartinsky feel free to add comments on the proposed solution for headless mode.

@alexcjohnson we can probably switch all integration with headless mode too, it's faster. I will test more

Copy link
Contributor

@Marc-Andre-Rivet Marc-Andre-Rivet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💃

@byronz byronz merged commit 21efbfe into master Jul 5, 2019
@byronz byronz deleted the headless-mode branch July 5, 2019 20:31
@mmartinsky
Copy link

Thanks @byronz ! Looking forward to release - do you happen to have any idea on release cadence post 1.0.0?

@staticmethod
def _get_chrome():
options = Options()
options.add_argument("--no-sandbox")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we lost --no-sandbox, is it important?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, I removed this part as the options are fully configurable after this PR

action="store",
default=False,
help="Run tests in headless mode",
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we use "store_true" so you can simplify to pytest --headless, rather than pytest --headless True?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, I like the shorter version

@byronz
Copy link
Contributor Author

byronz commented Jul 8, 2019

Thanks @byronz ! Looking forward to release - do you happen to have any idea on release cadence post 1.0.0?

@mmartinsky we have some internal discussion right now, nothing official yet, but 2-6 weeks, might be less frequent than last few months.

@mmartinsky
Copy link

mmartinsky commented Jul 17, 2019

hey @byronz and @alexcjohnson, do you have an example of altering the options for the webdriver? For background, I'm running into DevToolsActivePort file doesn't exist. when running in headless on Gitlab CI.

I found heroku/heroku-buildpack-google-chrome#46 (comment) that seems to be the same issue, I'm hoping that adding these options will clear this up.

The command I'm running is pytest --headless, nothing fancy there. The tests pass locally, but I can't seem to find a way to hook into the Chrome options.

I added a conftest.py at the project root, but it does not seem to get called:

def pytest_setup_options():
    print("Calling hook!!!!")

Output:

(venv) <Machine>:dash-app-kickstart <User>$ pytest --headless -v
Test session starts (platform: darwin, Python 3.7.3, pytest 4.6.3, pytest-sugar 0.9.2)
cachedir: .pytest_cache
rootdir: /some-path/dash-app-kickstart
plugins: sugar-0.9.2, dash-1.0.2, cov-2.7.1, mock-1.10.4
collecting ... 
 tests/test_integration.py::TestClass.test_style_app_title_capitalized ✓                                                                                                                                                                                   25% ██▌       
 tests/test_integration.py::TestClass.test_number_of_tabs ✓                                                                                                                                                                                                50% █████     
 tests/test_integration.py::TestClass.test_tab_change ✓                                                                                                                                                                                                    75% ███████▌  
 tests/test_integration.py::TestClass.test_grid_swap ✓                                                                                                                                                                                                    100% ██████████

Results (12.16s):
       4 passed
(venv)<Machine>:dash-app-kickstart <User>$ 

Our docker image is using Chrome v.67.0.3396.99-1, chromedriver v2.40.

@alexcjohnson
Copy link
Collaborator

I'll let @byronz comment on using the options, but I'll note a (sporadic) DevToolsActivePort file doesn't exist. is exactly why we added an auto-retry of starting the browser, most recent version #822 (comment) (included in dash 1.0.2)

If you're seeing a consistent failure, the options may be necessary; if it's sporadic the auto-retry may fix it.

@byronz
Copy link
Contributor Author

byronz commented Jul 18, 2019

@mmartinsky good point about the how-to, I added the issue for doc enhancement.

a sample hook, I put this in a conftest.py file under a submodule of tests folder

from selenium.webdriver.chrome.options import Options

def pytest_setup_options():
    """called before webdriver is initialized"""
    options = Options()
    options.add_argument('--no-sandbox')
    options.add_argument('--disable-dev-shm-usage')
    return options

and you can verify the options by increasing the logging level pytest -k dvui001 --log-cli-level DEBUG

Test session starts (platform: darwin, Python 3.7.4, pytest 4.6.4, pytest-sugar 0.9.2)
cachedir: .pytest_cache
rootdir: /Users/byron/code/dash, inifile: pytest.ini
plugins: sugar-0.9.2, mock-1.10.4, dash-1.0.1
collecting ...
------------------------------------------- live log setup --------------------------------------------
22:49:19 | DEBUG | selenium.webdriver.remote.remote_connection:388 | POST http://127.0.0.1:49395/session {"capabilities": {"firstMatch": [{}], "alwaysMatch": {"browserName": "chrome", "platformName": "any", "goog:chromeOptions": {"prefs": {"download.default_directory": "/private/var/folders/fl/dx4zhxfn11n3bbrrd7_hwhdr0000gn/T/pytest-of-byron/pytest-36/test_dvui001_disable_props_che0/download", "download.prompt_for_download": false, "download.directory_upgrade": true, "safebrowsing.enabled": false, "safebrowsing.disable_download_protection": true}, "extensions": [], "args": ["--no-sandbox", "--disable-dev-shm-usage"]}}}, "desiredCapabilities": {"browserName": "chrome", "version": "", "platform": "ANY", "loggingPrefs": {"browser": "SEVERE"}, "goog:chromeOptions": {"prefs": {"download.default_directory": "/private/var/folders/fl/dx4zhxfn11n3bbrrd7_hwhdr0000gn/T/pytest-of-byron/pytest-36/test_dvui001_disable_props_che0/download", "download.prompt_for_download": false, "download.directory_upgrade": true, "safebrowsing.enabled": false, "safebrowsing.disable_download_protection": true}, "extensions": [], "args": ["--no-sandbox", "--disable-dev-shm-usage"]}}}

we can tell that "args": ["--no-sandbox", "--disable-dev-shm-usage"]}}} is effective in selenium as configured in the hooks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants