tests (e2e/libervia): more stable test_user_can_log_in + photos tests

This commit is contained in:
Goffi 2020-12-04 12:39:44 +01:00
commit 50fd4f48d0

View file

@ -17,9 +17,11 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
import re
import pytest
from helium import (
go_to, write, click, drag_file, find_all, wait_until, S, Text, Link, get_driver
go_to, write, press, click, drag_file, find_all, wait_until, S, Text, Link, Button,
get_driver, ENTER
)
@ -60,10 +62,11 @@ class TestLogin:
def test_user_can_log_in(self, nobody_logged_in):
go_to("https://libervia.test:8443/login")
write("account1_s2", into="login")
write("account1_s3", into="login")
write("test", into="password")
click("log in")
assert Text("you are logged").exists()
wait_until(Text("you are logged").exists)
assert Button("Disconnect").exists()
def test_wrong_password_fails(self, nobody_logged_in):
go_to("https://libervia.test:8443/login")
@ -74,7 +77,12 @@ class TestLogin:
class TestPhotos:
ACCOUNT1_ALBUMS_URL = (
"https://libervia.test:8443/photos/album/account1@files.server1.test/albums"
)
TEST_ALBUM_URL = f"{ACCOUNT1_ALBUMS_URL}/test%20album"
@pytest.mark.dependency(name="create_album")
def test_user_can_create_album(self, log_in_account1):
go_to("https://libervia.test:8443/photos")
wait_until(Link("create").exists)
@ -91,3 +99,81 @@ class TestPhotos:
wait_until(lambda: len(find_all(S("div.progress_finished")))==2)
assert S('img[alt="test_1.jpg"]').exists()
assert S('img[alt="test_2.jpg"]').exists()
@pytest.mark.dependency(depends=["create_album"])
def test_user_can_slideshow(self, log_in_account1):
go_to(self.TEST_ALBUM_URL)
wait_until(lambda: not S("#loading_screen").exists())
thumb_1 = S("img[alt='test_1.jpg'].is-photo-thumbnail")
assert thumb_1.exists()
click(thumb_1)
assert S("div.slideshow").exists()
active_slide_1 = S("div.swiper-slide-active")
assert active_slide_1.exists()
# if we don't save the web_element here, the test in wait_until fails
# it seems that Helium is re-using the selector, i.e. we get the other
# slide in active_slide_1.
active_slide_1_elt = active_slide_1.web_element
click(S(".swiper-button-next"))
wait_until(
lambda:
"swiper-slide-active" not in active_slide_1_elt.get_attribute("class")
)
active_slide_2 = S("div.swiper-slide-active")
assert active_slide_2.exists()
active_slide_2_elt = active_slide_2.web_element
assert active_slide_1_elt != active_slide_2_elt
click(S(".click_to_close"))
assert not S("div.slideshow").exists()
@pytest.mark.dependency(name="ext_user_no_access", depends=["create_album"])
def test_external_user_cant_access_album(self, log_in_account1_s2):
go_to(self.TEST_ALBUM_URL)
assert Text("Unauthorized").exists()
assert "Error" in get_driver().title
@pytest.mark.dependency(name="invite_ext_user", depends=["create_album", "ext_user_no_access"])
def test_invitation_of_external_user(self, log_in_account1):
"""User can invite somebody not in its roster by its full JID"""
go_to(self.TEST_ALBUM_URL)
wait_until(lambda: not S("#loading_screen").exists())
click("manage invitations")
assert Text("people who can access this album").exists()
contact_input = S("input[name='contact']")
write("account1@server2.test", into=contact_input)
press(ENTER)
assert contact_input.web_element.get_attribute("value") == ""
assert Text("account1@server2.test").exists()
@pytest.mark.dependency(depends=["create_album", "invite_ext_user"])
def test_invited_user_can_access_album(self, log_in_account1_s2):
go_to(self.TEST_ALBUM_URL)
assert not Text("Unauthorized").exists()
assert not "Error" in get_driver().title
assert len(find_all(S("img.is-photo-thumbnail"))) == 2
@pytest.mark.dependency(name="invite_by_email", depends=["create_album"])
def test_invitation_by_email(self, log_in_account1, sent_emails, shared_data):
"""User can invite somebody without XMPP account by email"""
go_to(self.TEST_ALBUM_URL)
wait_until(lambda: not S("#loading_screen").exists())
click("manage invitations")
assert Text("people who can access this album").exists()
click("invite by email")
wait_until(Text("Invite somebody by email").exists)
write("somebody@example.net", "email")
write("Some Guest", "name")
click("send invitation")
wait_until(lambda: len(sent_emails) == 1)
invitation_email = sent_emails[0]
assert "Welcome" in invitation_email.body
url_match = re.search(r"https:\/\/.+\/g\/\w+", sent_emails[0].body)
assert url_match is not None
shared_data["invitation_url"] = url_match.group()
@pytest.mark.dependency(depends=["invite_by_email"])
def test_email_guest_can_access_album(self, nobody_logged_in, shared_data):
go_to(shared_data["invitation_url"])
click("test album")
wait_until(lambda: not S("#loading_screen").exists())
assert len(find_all(S("img.is-photo-thumbnail"))) == 2