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, BaseExperimentDataClass,
BaseExperimentMetricsDataClass, BaseExperimentMetricsDataClass,
) )
from nimbus.pages.experimenter.home import HomePage
from requests.adapters import HTTPAdapter from requests.adapters import HTTPAdapter
from requests.packages.urllib3.util.retry import Retry 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]) 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 @pytest.fixture
def experiment_url(base_url, default_data): def experiment_url(base_url, default_data):
return urljoin(base_url, slugify(default_data.public_name)) return urljoin(base_url, slugify(default_data.public_name))
@ -125,16 +136,17 @@ def default_data(request):
@pytest.fixture @pytest.fixture
def create_experiment(): def create_experiment(base_url, default_data):
def _create_experiment(selenium, home_page, data): def _create_experiment(selenium):
experiment = home_page.create_new_button() home = HomePage(selenium, base_url).open()
experiment.public_name = data.public_name experiment = home.create_new_button()
experiment.hypothesis = data.hypothesis experiment.public_name = default_data.public_name
experiment.application = data.application.value experiment.hypothesis = default_data.hypothesis
experiment.application = default_data.application.value
# Fill Overview Page # Fill Overview Page
overview = experiment.save_and_continue() 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_brand_false()
overview.select_risk_revenue_false() overview.select_risk_revenue_false()
overview.select_risk_partner_false() overview.select_risk_partner_false()
@ -142,24 +154,20 @@ def create_experiment():
# Fill Branches page # Fill Branches page
branches = overview.save_and_continue() branches = overview.save_and_continue()
branches.remove_branch() branches.remove_branch()
branches.reference_branch_name = data.branches[0].name branches.reference_branch_name = default_data.branches[0].name
branches.reference_branch_description = data.branches[0].description branches.reference_branch_description = default_data.branches[0].description
branches.feature_config = data.branches[0].feature_config branches.feature_config = default_data.branches[0].feature_config
# Fill Metrics page # Fill Metrics page
metrics = branches.save_and_continue() metrics = branches.save_and_continue()
# Fill Audience page # Fill Audience page
audience = metrics.save_and_continue() audience = metrics.save_and_continue()
audience.channel = data.audience.channel.value audience.channel = default_data.audience.channel.value
audience.min_version = data.audience.min_version audience.min_version = default_data.audience.min_version
audience.targeting = data.audience.targeting.value audience.targeting = default_data.audience.targeting.value
audience.percentage = data.audience.percentage audience.percentage = default_data.audience.percentage
audience.expected_clients = data.audience.expected_clients audience.expected_clients = default_data.audience.expected_clients
review = audience.save_and_continue() return audience.save_and_continue()
# Review
selenium.find_element_by_css_selector("#PageSummary")
return review
return _create_experiment return _create_experiment

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

@ -35,6 +35,19 @@ class HomePage(Base):
return NewExperiment(self.driver, self.base_url).wait_for_page_to_load() 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): class Tables(Region):
_experiment_link_locator = (By.CSS_SELECTOR, "tr a") _experiment_link_locator = (By.CSS_SELECTOR, "tr a")

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

@ -78,7 +78,13 @@ class SummaryPage(ExperimenterBase):
) )
self.find_element(*self._approve_request_button_locator).click() 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 = self.find_element(*self._end_experiment_button_locator)
el.click() el.click()
if action == "End": if action == "End":
@ -89,6 +95,7 @@ class SummaryPage(ExperimenterBase):
el.click() el.click()
else: else:
pass pass
self.approve()
@property @property
def rejected_text(self): def rejected_text(self):
@ -113,9 +120,8 @@ class SummaryPage(ExperimenterBase):
def request_launch_button(self): def request_launch_button(self):
return self.find_element(*self._request_launch_locator) return self.find_element(*self._request_launch_locator)
@property def archive(self):
def archive_button(self): self.find_element(*self._archive_button_locator).click()
return self.find_element(*self._archive_button_locator)
@property @property
def archive_label(self): def archive_label(self):

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

@ -6,48 +6,28 @@ from nimbus.pages.experimenter.summary import SummaryPage
@pytest.mark.run_once @pytest.mark.run_once
def test_archive_experiment( def test_archive_experiment(
selenium, selenium,
base_url,
default_data, default_data,
create_experiment, create_experiment,
archived_tab_url,
drafts_tab_url,
experiment_url,
): ):
selenium.get(base_url) # Archive the experiment
home = HomePage(selenium, base_url).wait_for_page_to_load() summary = create_experiment(selenium)
summary.archive()
summary.wait_for_archive_label_visible()
# Create experiment # Check it's archived on the home page
summary_page = create_experiment(selenium, home, default_data) HomePage(selenium, archived_tab_url).open().find_in_table(
"Archived", default_data.public_name
)
# Archive it on the summary page # Unarchive the experiment
summary_page.archive_button.click() summary = SummaryPage(selenium, experiment_url).open()
summary.archive()
summary.wait_for_archive_label_not_visible()
# Check it's archived on the summary page # Check it's in drafts on the home page
summary_page.wait_for_archive_label_visible() HomePage(selenium, drafts_tab_url).open().find_in_table(
"Draft", default_data.public_name
# 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")

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

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