Как запустить тест Django selenium в действиях github
У меня есть Django selenium test, который отлично работает на локальной машине с помощью Firefox Webdrive. Когда я пытаюсь запустить его на github actions, я получаю следующую ошибку:
Traceback (most recent call last):
File "/home/runner/work/Pangea/Pangea/core/tests/test_selenium.py", line 12, in setUpClass
cls.selenium = WebDriver()
File "/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/selenium/webdriver/firefox/webdriver.py", line 181, in __init__
RemoteWebDriver.__init__(
File "/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 269, in __init__
self.start_session(capabilities, browser_profile)
File "/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 360, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 425, in execute
self.error_handler.check_response(response)
File "/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py", line 247, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: Process unexpectedly closed with status 1
Тест, который я пытаюсь выполнить, очень простой, как показано ниже
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
from rest_framework.reverse import reverse
from selenium.webdriver.common.by import By
from selenium.webdriver.firefox.webdriver import WebDriver
class TestLoginWithSelenium(StaticLiveServerTestCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.selenium = WebDriver()
cls.selenium.maximize_window()
cls.username = "xyz"
cls.password = "mnbvcxza"
cls.server_url = 'http://127.0.0.1:8000'
@classmethod
def tearDownClass(cls):
cls.selenium.quit()
super().tearDownClass()
def test_login(self):
"""
Test Login for a user
"""
self.assertTrue(1==1)
Я выполняю следующие команды на Github Actions:
pip install selenium
sudo apt install firefox-geckodriver
which geckodriver
geckodriver -V
sudo mv /usr/bin/geckodriver /usr/local/bin/geckodriver
which geckodriver
Mozilla Firefox 99.0
geckodriver 0.30.0
Ссылка на опцию headless firefox
Ниже приведен модифицированный код для запуска headless firefox на github actions
test.py
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
from rest_framework.reverse import reverse
from selenium import webdriver
from selenium.webdriver import FirefoxOptions
from selenium.webdriver.common.by import By
class TestLoginWithSelenium(StaticLiveServerTestCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
opts = FirefoxOptions()
opts.add_argument("--headless")
cls.selenium = webdriver.Firefox(options=opts)
# this will run with head and you can actually see the
# browser open up in tests
# cls.selenium = webdriver.Firefox()
cls.username = "xyz"
cls.password = "mnbvcxza"
@classmethod
def tearDownClass(cls):
cls.selenium.quit()
super().tearDownClass()
def test_login(self):
"""
Test Login for a user
"""
self.client.logout()
self.selenium.get(f"{self.live_server_url}{reverse('login')}")
username_input = self.selenium.find_element(By.ID, "id_auth-username")
username_input.send_keys(self.username)
password_input = self.selenium.find_element(By.ID, "id_auth-password")
password_input.send_keys(self.password)
self.selenium.find_element(By.ID, 'idLogin').click()
github actions
pip install selenium
sudo apt install firefox-geckodriver