annotate tests/e2e/libervia-web/conftest.py @ 4118:07370d2a9bde

plugin XEP-0167: keep media order when starting a call: media content order is relevant when building Jingle contents/SDP notably for bundling. This patch fixes the previous behaviour of always using the same order by keeping the order of the data (i.e. order of original SDP offer). Previous behaviour could lead to call failure. rel 424
author Goffi <goffi@goffi.org>
date Tue, 03 Oct 2023 15:15:24 +0200
parents d78b5eae912a
children dfccc90cacc6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3429
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/env python3
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
2
3480
7550ae9cfbac Renamed the project from "Salut à Toi" to "Libervia":
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
3 # Libervia: an XMPP client
3479
be6d91572633 date update
Goffi <goffi@goffi.org>
parents: 3438
diff changeset
4 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org)
3429
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
5
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
6 # This program is free software: you can redistribute it and/or modify
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # it under the terms of the GNU Affero General Public License as published by
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # the Free Software Foundation, either version 3 of the License, or
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # (at your option) any later version.
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
10
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
11 # This program is distributed in the hope that it will be useful,
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # GNU Affero General Public License for more details.
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
15
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
16 # You should have received a copy of the GNU Affero General Public License
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
18
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
19 import sys
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
20 import os
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
21 import socket
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
22 import pytest
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
23 import time
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
24 from datetime import datetime
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from pathlib import Path
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
26 import helium
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
27
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
28
3498
d78b5eae912a tests: update following names change
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
29 WEB_HOST = "libervia-web.test"
d78b5eae912a tests: update following names change
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
30 WEB_PORT_HTTPS = 8443
d78b5eae912a tests: update following names change
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
31 BASE_URL = f"https://{WEB_HOST}:{WEB_PORT_HTTPS}"
3429
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
32 SIZE_DESKTOP = (1024, 728)
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
33 SIZE_MOBILE = (380, 640)
3438
84fb41b515a1 tests (e2e/libervia/conftest): new `log_in_account1_s2` fixture
Goffi <goffi@goffi.org>
parents: 3429
diff changeset
34 accounts_cookies = {}
3429
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
35
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
36
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
37 @pytest.hookimpl(tryfirst=True, hookwrapper=True)
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
38 def pytest_runtest_makereport(item, call):
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
39 # needed to get test results in request fixture
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
40 # cf. https://docs.pytest.org/en/latest/example/simple.html#making-test-result-information-available-in-fixtures
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
41 outcome = yield
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
42 rep = outcome.get_result()
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
43 setattr(item, "rep_" + rep.when, rep)
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
44
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
45
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
46 @pytest.fixture
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
47 def screenshot_on_failure(request):
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
48 yield
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
49 if request.node.rep_setup.passed:
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
50 if request.node.rep_call.failed:
3498
d78b5eae912a tests: update following names change
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
51 report_dir = Path(os.getenv("LIBERVIA_TEST_REPORT_DIR", "/tmp/tests_report"))
3429
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
52 dest_dir = report_dir/"screenshots"
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
53 dest_dir.mkdir(parents=True, exist_ok=True)
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
54 filename = f"{datetime.now().isoformat()}_{request.node.name}.png"
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
55 dest_path = dest_dir/filename
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
56 helium.get_driver().save_screenshot(str(dest_path))
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
57 print(f"screenshot saved to {dest_path}")
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
58
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
59
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
60 def wait_for_socket(host, port, retries=30):
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
61 sock = socket.socket()
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
62 while True:
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
63 try:
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
64 sock.connect((host, port))
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
65 except ConnectionRefusedError as e:
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
66 retries -= 1
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
67 if retries < 0:
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
68 print(f"Can't access server at {host}:{port}", file=sys.stderr)
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
69 raise e
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
70 else:
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
71 print(f"Can't connect to {host}:{port}, retrying ({retries})")
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
72 time.sleep(1)
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
73 else:
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
74 break
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
75
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
76
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
77 @pytest.fixture(scope="session")
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
78 def browser():
3498
d78b5eae912a tests: update following names change
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
79 if os.getenv("LIBERVIA_TEST_E2E_WEB_NO_HEADLESS") is not None:
3429
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
80 kwargs = {}
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
81 else:
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
82 kwargs = {"headless": True}
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
83 driver = helium.start_firefox(**kwargs)
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
84 driver.set_window_size(*SIZE_DESKTOP)
3498
d78b5eae912a tests: update following names change
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
85 wait_for_socket(WEB_HOST, WEB_PORT_HTTPS)
3429
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
86 yield helium
3498
d78b5eae912a tests: update following names change
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
87 if os.getenv("LIBERVIA_TEST_E2E_WEB_KEEP_BROWSER") is None:
3429
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
88 helium.kill_browser()
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
89
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
90
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
91 @pytest.fixture
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
92 def nobody_logged_in(browser):
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
93 browser.get_driver().delete_all_cookies()
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
94
3438
84fb41b515a1 tests (e2e/libervia/conftest): new `log_in_account1_s2` fixture
Goffi <goffi@goffi.org>
parents: 3429
diff changeset
95 def log_in(browser, account):
84fb41b515a1 tests (e2e/libervia/conftest): new `log_in_account1_s2` fixture
Goffi <goffi@goffi.org>
parents: 3429
diff changeset
96 try:
84fb41b515a1 tests (e2e/libervia/conftest): new `log_in_account1_s2` fixture
Goffi <goffi@goffi.org>
parents: 3429
diff changeset
97 account_cookies = accounts_cookies[account]
84fb41b515a1 tests (e2e/libervia/conftest): new `log_in_account1_s2` fixture
Goffi <goffi@goffi.org>
parents: 3429
diff changeset
98 except KeyError:
84fb41b515a1 tests (e2e/libervia/conftest): new `log_in_account1_s2` fixture
Goffi <goffi@goffi.org>
parents: 3429
diff changeset
99 browser.get_driver().delete_all_cookies()
3498
d78b5eae912a tests: update following names change
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
100 browser.go_to("https://libervia-web.test:8443/login")
3438
84fb41b515a1 tests (e2e/libervia/conftest): new `log_in_account1_s2` fixture
Goffi <goffi@goffi.org>
parents: 3429
diff changeset
101 browser.write(account, into="login")
84fb41b515a1 tests (e2e/libervia/conftest): new `log_in_account1_s2` fixture
Goffi <goffi@goffi.org>
parents: 3429
diff changeset
102 browser.write("test", into="password")
84fb41b515a1 tests (e2e/libervia/conftest): new `log_in_account1_s2` fixture
Goffi <goffi@goffi.org>
parents: 3429
diff changeset
103 browser.click("log in")
84fb41b515a1 tests (e2e/libervia/conftest): new `log_in_account1_s2` fixture
Goffi <goffi@goffi.org>
parents: 3429
diff changeset
104 accounts_cookies[account] = browser.get_driver().get_cookies()[0]
84fb41b515a1 tests (e2e/libervia/conftest): new `log_in_account1_s2` fixture
Goffi <goffi@goffi.org>
parents: 3429
diff changeset
105 else:
84fb41b515a1 tests (e2e/libervia/conftest): new `log_in_account1_s2` fixture
Goffi <goffi@goffi.org>
parents: 3429
diff changeset
106 browser.get_driver().add_cookie(account_cookies)
3429
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
107
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
108 @pytest.fixture
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
109 def log_in_account1(browser):
3438
84fb41b515a1 tests (e2e/libervia/conftest): new `log_in_account1_s2` fixture
Goffi <goffi@goffi.org>
parents: 3429
diff changeset
110 log_in(browser, "account1")
3429
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
111
3438
84fb41b515a1 tests (e2e/libervia/conftest): new `log_in_account1_s2` fixture
Goffi <goffi@goffi.org>
parents: 3429
diff changeset
112 @pytest.fixture
84fb41b515a1 tests (e2e/libervia/conftest): new `log_in_account1_s2` fixture
Goffi <goffi@goffi.org>
parents: 3429
diff changeset
113 def log_in_account1_s2(browser):
84fb41b515a1 tests (e2e/libervia/conftest): new `log_in_account1_s2` fixture
Goffi <goffi@goffi.org>
parents: 3429
diff changeset
114 log_in(browser, "account1_s2")
3429
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
115
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
116 @pytest.fixture
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
117 def mobile_screen(browser):
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
118 browser.get_driver().set_window_size(*SIZE_MOBILE)
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
119
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
120
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
121 @pytest.fixture
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
122 def desktop_screen(browser):
d4558f3cbf13 tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
diff changeset
123 browser.get_driver().set_window_size(*SIZE_DESKTOP)