chore(nimbus): use page.open in integration tests (#6344)

Because

* The integration test PyPom library provides a handy .open method that opens the page and waits for it to load
* This can clean up a lot of code in the tests

This commit

* Uses .open in all the integration tests
This commit is contained in:
Jared Lockhart 2021-09-03 16:38:16 -04:00 коммит произвёл GitHub
Родитель 0fa612144d
Коммит 1877c650e6
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
5 изменённых файлов: 94 добавлений и 167 удалений

Просмотреть файл

@ -12,6 +12,7 @@ from nimbus.models.base_dataclass import (
BaseExperimentDataClass,
BaseExperimentMetricsDataClass,
)
from nimbus.pages.experimenter.home import HomePage
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.util.retry import Retry
@ -85,6 +86,16 @@ def kinto_review_url(kinto_url, default_data):
return urljoin(kinto_url, APPLICATION_KINTO_REVIEW_PATH[default_data.application])
@pytest.fixture
def archived_tab_url(base_url):
return f"{base_url}?tab=archived"
@pytest.fixture
def drafts_tab_url(base_url):
return f"{base_url}?tab=drafts"
@pytest.fixture
def experiment_url(base_url, default_data):
return urljoin(base_url, slugify(default_data.public_name))
@ -125,16 +136,17 @@ def default_data(request):
@pytest.fixture
def create_experiment():
def _create_experiment(selenium, home_page, data):
experiment = home_page.create_new_button()
experiment.public_name = data.public_name
experiment.hypothesis = data.hypothesis
experiment.application = data.application.value
def create_experiment(base_url, default_data):
def _create_experiment(selenium):
home = HomePage(selenium, base_url).open()
experiment = home.create_new_button()
experiment.public_name = default_data.public_name
experiment.hypothesis = default_data.hypothesis
experiment.application = default_data.application.value
# Fill Overview Page
overview = experiment.save_and_continue()
overview.public_description = data.public_description
overview.public_description = default_data.public_description
overview.select_risk_brand_false()
overview.select_risk_revenue_false()
overview.select_risk_partner_false()
@ -142,24 +154,20 @@ def create_experiment():
# Fill Branches page
branches = overview.save_and_continue()
branches.remove_branch()
branches.reference_branch_name = data.branches[0].name
branches.reference_branch_description = data.branches[0].description
branches.feature_config = data.branches[0].feature_config
branches.reference_branch_name = default_data.branches[0].name
branches.reference_branch_description = default_data.branches[0].description
branches.feature_config = default_data.branches[0].feature_config
# Fill Metrics page
metrics = branches.save_and_continue()
# Fill Audience page
audience = metrics.save_and_continue()
audience.channel = data.audience.channel.value
audience.min_version = data.audience.min_version
audience.targeting = data.audience.targeting.value
audience.percentage = data.audience.percentage
audience.expected_clients = data.audience.expected_clients
review = audience.save_and_continue()
# Review
selenium.find_element_by_css_selector("#PageSummary")
return review
audience.channel = default_data.audience.channel.value
audience.min_version = default_data.audience.min_version
audience.targeting = default_data.audience.targeting.value
audience.percentage = default_data.audience.percentage
audience.expected_clients = default_data.audience.expected_clients
return audience.save_and_continue()
return _create_experiment

Просмотреть файл

@ -35,6 +35,19 @@ class HomePage(Base):
return NewExperiment(self.driver, self.base_url).wait_for_page_to_load()
def find_in_table(self, table_name, experiment_name):
table_experiments = self.tables[0]
assert (
table_name in self.active_tab_text
), f"Home Page: Table {table_name} not found in {self.active_tab_text}"
experiment_names = [
experiment.text for experiment in table_experiments.experiments
]
assert experiment_name in experiment_names, (
f"Home Page: Experiment {experiment_name} not found in "
"{table_name} experiments: {experiment_names}"
)
class Tables(Region):
_experiment_link_locator = (By.CSS_SELECTOR, "tr a")

Просмотреть файл

@ -78,7 +78,13 @@ class SummaryPage(ExperimenterBase):
)
self.find_element(*self._approve_request_button_locator).click()
def end_experiment(self, action="End"):
def launch_and_approve(self):
self.launch_without_preview.click()
self.request_review.click_launch_checkboxes()
self.request_review.request_launch_button.click()
self.approve()
def end_and_approve(self, action="End"):
el = self.find_element(*self._end_experiment_button_locator)
el.click()
if action == "End":
@ -89,6 +95,7 @@ class SummaryPage(ExperimenterBase):
el.click()
else:
pass
self.approve()
@property
def rejected_text(self):
@ -113,9 +120,8 @@ class SummaryPage(ExperimenterBase):
def request_launch_button(self):
return self.find_element(*self._request_launch_locator)
@property
def archive_button(self):
return self.find_element(*self._archive_button_locator)
def archive(self):
self.find_element(*self._archive_button_locator).click()
@property
def archive_label(self):

Просмотреть файл

@ -6,48 +6,28 @@ from nimbus.pages.experimenter.summary import SummaryPage
@pytest.mark.run_once
def test_archive_experiment(
selenium,
base_url,
default_data,
create_experiment,
archived_tab_url,
drafts_tab_url,
experiment_url,
):
selenium.get(base_url)
home = HomePage(selenium, base_url).wait_for_page_to_load()
# Archive the experiment
summary = create_experiment(selenium)
summary.archive()
summary.wait_for_archive_label_visible()
# Create experiment
summary_page = create_experiment(selenium, home, default_data)
# Check it's archived on the home page
HomePage(selenium, archived_tab_url).open().find_in_table(
"Archived", default_data.public_name
)
# Archive it on the summary page
summary_page.archive_button.click()
# Unarchive the experiment
summary = SummaryPage(selenium, experiment_url).open()
summary.archive()
summary.wait_for_archive_label_not_visible()
# Check it's archived on the summary page
summary_page.wait_for_archive_label_visible()
# Check it's archived on the directory page
archived_tab_url = f"{base_url}?tab=archived"
selenium.get(archived_tab_url)
home = HomePage(selenium, archived_tab_url).wait_for_page_to_load()
archived_experiments = home.tables[0]
assert "Archived" in home.active_tab_text
for archived_experiment in archived_experiments.experiments:
if default_data.public_name in archived_experiment.text:
archived_experiment.click()
summary_page = SummaryPage(selenium, base_url).wait_for_page_to_load()
break
# Unarchive it on the summary page
summary_page.archive_button.click()
# Check it's unarchived on the summary page
summary_page.wait_for_archive_label_not_visible()
# Check it's in draft on the directory page
draft_tab_url = f"{base_url}?tab=drafts"
selenium.get(draft_tab_url)
home = HomePage(selenium, draft_tab_url).wait_for_page_to_load()
draft_experiments = home.tables[0]
assert "Draft" in home.active_tab_text
for draft_experiment in draft_experiments.experiments:
if default_data.public_name in draft_experiment.text:
break
else:
raise Exception("Experiment was not found in draft list")
# Check it's in drafts on the home page
HomePage(selenium, drafts_tab_url).open().find_in_table(
"Draft", default_data.public_name
)

Просмотреть файл

@ -1,5 +1,4 @@
import pytest
from nimbus.pages.experimenter.home import HomePage
from nimbus.pages.experimenter.summary import SummaryPage
from nimbus.pages.remote_settings.dashboard import Dashboard
from nimbus.pages.remote_settings.login import Login
@ -15,158 +14,79 @@ def test_create_new_experiment_approve_remote_settings(
default_data,
create_experiment,
):
selenium.get(base_url)
home = HomePage(selenium, base_url).wait_for_page_to_load()
create_experiment(selenium).launch_and_approve()
summary = create_experiment(selenium, home, default_data)
summary.launch_without_preview.click()
summary.request_review.click_launch_checkboxes()
summary.request_review.request_launch_button.click()
summary.approve()
Login(selenium, kinto_url).open().login()
Dashboard(selenium, kinto_review_url).open().approve()
selenium.get(kinto_url)
kinto_login = Login(selenium, kinto_url).wait_for_page_to_load()
kinto_login.login()
selenium.get(kinto_review_url)
kinto_dashboard = Dashboard(selenium, kinto_review_url).wait_for_page_to_load()
kinto_dashboard.approve()
selenium.get(experiment_url)
summary = SummaryPage(selenium, experiment_url).wait_for_page_to_load()
summary.wait_for_live_status()
SummaryPage(selenium, experiment_url).open().wait_for_live_status()
@pytest.mark.run_once
def test_create_new_experiment_reject_remote_settings(
selenium,
base_url,
kinto_url,
kinto_review_url,
experiment_url,
default_data,
create_experiment,
):
selenium.get(base_url)
home = HomePage(selenium, base_url).wait_for_page_to_load()
create_experiment(selenium).launch_and_approve()
summary = create_experiment(selenium, home, default_data)
summary.launch_without_preview.click()
summary.request_review.click_launch_checkboxes()
summary.request_review.request_launch_button.click()
summary.approve()
Login(selenium, kinto_url).open().login()
Dashboard(selenium, kinto_review_url).open().reject()
selenium.get(kinto_url)
kinto_login = Login(selenium, kinto_url).wait_for_page_to_load()
kinto_login.login()
selenium.get(kinto_review_url)
kinto_dashboard = Dashboard(selenium, kinto_review_url).wait_for_page_to_load()
kinto_dashboard.reject()
selenium.get(experiment_url)
summary = SummaryPage(selenium, experiment_url).wait_for_page_to_load()
summary.wait_for_rejected_alert()
SummaryPage(selenium, experiment_url).open().wait_for_rejected_alert()
@pytest.mark.run_once
def test_create_new_experiment_timeout_remote_settings(
selenium,
base_url,
default_data,
create_experiment,
):
selenium.get(base_url)
home = HomePage(selenium, base_url).wait_for_page_to_load()
summary = create_experiment(selenium, home, default_data)
summary.launch_without_preview.click()
summary.request_review.click_launch_checkboxes()
summary.request_review.request_launch_button.click()
summary.approve()
summary = create_experiment(selenium)
summary.launch_and_approve()
summary.wait_for_timeout_alert()
@pytest.mark.run_once
def test_end_experiment_and_approve_end(
selenium,
base_url,
kinto_url,
kinto_review_url,
experiment_url,
default_data,
create_experiment,
):
selenium.get(base_url)
home = HomePage(selenium, base_url).wait_for_page_to_load()
create_experiment(selenium).launch_and_approve()
summary = create_experiment(selenium, home, default_data)
summary.launch_without_preview.click()
summary.request_review.click_launch_checkboxes()
summary.request_review.request_launch_button.click()
summary.approve()
Login(selenium, kinto_url).open().login()
Dashboard(selenium, kinto_review_url).open().approve()
selenium.get(kinto_url)
kinto_login = Login(selenium, kinto_url).wait_for_page_to_load()
kinto_login.login()
selenium.get(kinto_review_url)
kinto_dashboard = Dashboard(selenium, kinto_review_url).wait_for_page_to_load()
kinto_dashboard.approve()
selenium.get(experiment_url)
summary = SummaryPage(selenium, experiment_url).wait_for_page_to_load()
summary = SummaryPage(selenium, experiment_url).open()
summary.wait_for_live_status()
summary.end_experiment()
summary.approve()
summary.end_and_approve()
selenium.get(kinto_review_url)
kinto_dashboard = Dashboard(selenium, kinto_review_url).wait_for_page_to_load()
kinto_dashboard.approve()
Dashboard(selenium, kinto_review_url).open().approve()
selenium.get(experiment_url)
summary = SummaryPage(selenium, experiment_url).wait_for_page_to_load()
summary.wait_for_complete_status()
SummaryPage(selenium, experiment_url).open().wait_for_complete_status()
@pytest.mark.run_once
def test_end_experiment_and_reject_end(
selenium,
base_url,
kinto_url,
kinto_review_url,
experiment_url,
default_data,
create_experiment,
):
selenium.get(base_url)
home = HomePage(selenium, base_url).wait_for_page_to_load()
create_experiment(selenium).launch_and_approve()
summary = create_experiment(selenium, home, default_data)
summary.launch_without_preview.click()
summary.request_review.click_launch_checkboxes()
summary.request_review.request_launch_button.click()
summary.approve()
Login(selenium, kinto_url).open().login()
Dashboard(selenium, kinto_review_url).open().approve()
selenium.get(kinto_url)
kinto_login = Login(selenium, kinto_url).wait_for_page_to_load()
kinto_login.login()
selenium.get(kinto_review_url)
kinto_dashboard = Dashboard(selenium, kinto_review_url).wait_for_page_to_load()
kinto_dashboard.approve()
selenium.get(experiment_url)
summary = SummaryPage(selenium, experiment_url).wait_for_page_to_load()
summary = SummaryPage(selenium, experiment_url).open()
summary.wait_for_live_status()
summary.end_experiment()
summary.approve()
summary.end_and_approve()
selenium.get(kinto_review_url)
kinto_dashboard = Dashboard(selenium, kinto_review_url).wait_for_page_to_load()
kinto_dashboard.reject()
Dashboard(selenium, kinto_review_url).open().reject()
selenium.get(experiment_url)
summary = SummaryPage(selenium, experiment_url).wait_for_page_to_load()
summary.wait_for_rejected_alert()
SummaryPage(selenium, experiment_url).open().wait_for_rejected_alert()