You can run headless Microsoft Edge with Selenium in Python as shown below:
from selenium import webdriver
options = webdriver.EdgeOptions()
options.add_argument("--headless=new") # Here
driver = webdriver.Edge(options=options)
Or:
from selenium import webdriver
from selenium.webdriver.edge.options import Options
options = Options()
options.add_argument("--headless=new") # Here
driver = webdriver.Edge(options=options)
In addition, the examples below can test Django Admin with headless Microsoft Edge, Selenium, pytest-django and Django. *My answer explains how to test Django Admin with multiple headless browsers(Chrome, Microsoft Edge and Firefox), Selenium, pytest-django and Djang:
# "tests/test_1.py"
import pytest
from selenium import webdriver
from django.test import LiveServerTestCase
@pytest.fixture(scope="class")
def edge_driver_init(request):
options = webdriver.EdgeOptions()
options.add_argument("--headless=new")
edge_driver = webdriver.Edge(options=options)
request.cls.driver = edge_driver
yield
edge_driver.close()
@pytest.mark.usefixtures("edge_driver_init")
class Test_URL_Edge(LiveServerTestCase):
def test_open_url(self):
self.driver.get(("%s%s" % (self.live_server_url, "/admin/")))
assert "Log in | Django site admin" in self.driver.title
Or:
# "tests/conftest.py"
import pytest
from selenium import webdriver
@pytest.fixture(scope="class")
def edge_driver_init(request):
options = webdriver.EdgeOptions()
options.add_argument("--headless=new")
edge_driver = webdriver.Edge(options=options)
request.cls.driver = edge_driver
yield
edge_driver.close()
# "tests/test_1.py"
import pytest
from django.test import LiveServerTestCase
@pytest.mark.usefixtures("edge_driver_init")
class Test_URL_Edge(LiveServerTestCase):
def test_open_url(self):
self.driver.get(("%s%s" % (self.live_server_url, "/admin/")))
assert "Log in | Django site admin" in self.driver.title