From e8678a7155ff64d797693f7a8ec84c196d1d4748 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Tue, 7 Mar 2023 19:54:07 +0100 Subject: switch order of expect & assert While it shouldn't change the outcome of the test, it might make the test less flaky, as the expect call will wait until the page is loaded - which also indicates that the data is updated. Without this, the test depends on the backend being "fast enough" with applying the transformation. --- tests/playwright/test_transformers.py | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) (limited to 'tests/playwright/test_transformers.py') diff --git a/tests/playwright/test_transformers.py b/tests/playwright/test_transformers.py index d12be5e..0b2e4de 100644 --- a/tests/playwright/test_transformers.py +++ b/tests/playwright/test_transformers.py @@ -15,13 +15,14 @@ def test_transformer_zero_elevation_disabled(page: Page, playwright_helper, tmp_ page.locator(".btn", has_text="Upload").click() - # Once we have finished the upload, extract the ID of the track and check - # the properties + # Expect early (here and in the other tests) to ensure that the backend has + # caught up with executing the transformer. Otherwise it might happen that + # we read the database while the request is not finished yet. + expect(page.locator("#detailsUphill")).to_contain_text("167.7 m") new_track_id = int(page.url.rsplit("/", 1)[1]) track = dbaccess.execute(select(models.Track).filter_by(id=new_track_id)).scalar_one() assert track.cache.uphill > 160 - expect(page.locator("#detailsUphill")).to_contain_text("167.7 m") def test_transformer_zero_elevation_enabled(page: Page, playwright_helper, tmp_path, dbaccess): @@ -37,13 +38,11 @@ def test_transformer_zero_elevation_enabled(page: Page, playwright_helper, tmp_p page.locator(".btn", has_text="Upload").click() - # Once we have finished the upload, extract the ID of the track and check - # the properties + expect(page.locator("#detailsUphill")).to_contain_text("0 m") new_track_id = int(page.url.rsplit("/", 1)[1]) track = dbaccess.execute(select(models.Track).filter_by(id=new_track_id)).scalar_one() assert track.cache.uphill < 0.1 - expect(page.locator("#detailsUphill")).to_contain_text("0 m") def test_transformer_zero_elevation_edited(page: Page, playwright_helper, tmp_path, dbaccess): @@ -63,11 +62,11 @@ def test_transformer_zero_elevation_edited(page: Page, playwright_helper, tmp_pa page.locator(".btn", has_text="Save").click() + expect(page.locator("#detailsUphill")).to_contain_text("0 m") track_id = int(page.url.rsplit("/", 1)[1]) track = dbaccess.execute(select(models.Track).filter_by(id=track_id)).scalar_one() assert track.cache.uphill < 0.1 - expect(page.locator("#detailsUphill")).to_contain_text("0 m") def test_transformer_steep_slope_disabled(page: Page, playwright_helper, tmp_path, dbaccess): @@ -80,13 +79,11 @@ def test_transformer_steep_slope_disabled(page: Page, playwright_helper, tmp_pat page.locator(".btn", has_text="Upload").click() - # Once we have finished the upload, extract the ID of the track and check - # the properties + expect(page.locator("#detailsUphill")).to_contain_text("61.54 m") new_track_id = int(page.url.rsplit("/", 1)[1]) track = dbaccess.execute(select(models.Track).filter_by(id=new_track_id)).scalar_one() assert track.cache.uphill > 60 - expect(page.locator("#detailsUphill")).to_contain_text("61.54 m") def test_transformer_steep_slope_enabled(page: Page, playwright_helper, tmp_path, dbaccess): @@ -102,13 +99,11 @@ def test_transformer_steep_slope_enabled(page: Page, playwright_helper, tmp_path page.locator(".btn", has_text="Upload").click() - # Once we have finished the upload, extract the ID of the track and check - # the properties + expect(page.locator("#detailsUphill")).to_contain_text("1.2 m") new_track_id = int(page.url.rsplit("/", 1)[1]) track = dbaccess.execute(select(models.Track).filter_by(id=new_track_id)).scalar_one() assert track.cache.uphill < 2 - expect(page.locator("#detailsUphill")).to_contain_text("1.2 m") def test_transformer_steep_slope_edited(page: Page, playwright_helper, tmp_path, dbaccess): @@ -128,8 +123,8 @@ def test_transformer_steep_slope_edited(page: Page, playwright_helper, tmp_path, page.locator(".btn", has_text="Save").click() + expect(page.locator("#detailsUphill")).to_contain_text("1.2 m") track_id = int(page.url.rsplit("/", 1)[1]) track = dbaccess.execute(select(models.Track).filter_by(id=track_id)).scalar_one() assert track.cache.uphill < 2 - expect(page.locator("#detailsUphill")).to_contain_text("1.2 m") -- cgit v1.2.3