Skip to content

Feature/integrating safari browser #276

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 16 commits into
base: develop
Choose a base branch
from
Open
38 changes: 31 additions & 7 deletions api/osf_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1197,34 +1197,39 @@ def update_file_metadata(session, file_guid):
)


def get_registration_resource_id(registration_id):
def get_registration_resource_id(registration_id, resource_type):
"""This function returns the most recent resource id
added to the given registration"""
session = client.Session(
api_base_url=settings.API_DOMAIN,
auth=(settings.REGISTRATIONS_USER, settings.REGISTRATIONS_USER_PASSWORD),
)

resource = resource_type.replace(' ', '_').lower()
url = '/v2/registrations/{}/resources/'.format(registration_id)
data = session.get(url)['data']
if data:
for i in range(0, len(data)):
date_created = data[i]['attributes']['date_created']
now = datetime.now()
current_date = now.strftime('%Y-%m-%d')
if current_date in date_created:
if (
current_date in date_created
and data[i]['attributes']['resource_type'] == resource
):
return data[i]['id']
break
return None


def delete_registration_resource(registration_id):
def delete_registration_resource(registration_id, resource_type):
"""This function deletes the resource added to the given registration"""
session = client.Session(
api_base_url=settings.API_DOMAIN,
auth=(settings.REGISTRATIONS_USER, settings.REGISTRATIONS_USER_PASSWORD),
)
registration_resource_id = get_registration_resource_id(registration_id)
registration_resource_id = get_registration_resource_id(
registration_id, resource_type
)
url = '/v2/resources/{}'.format(registration_resource_id)

session.delete(url, item_type='resources')
Expand All @@ -1238,9 +1243,9 @@ def create_registration_resource(registration_guid, resource_type):
api_base_url=settings.API_DOMAIN,
auth=(settings.REGISTRATIONS_USER, settings.REGISTRATIONS_USER_PASSWORD),
)
resource_id = get_registration_resource_id(registration_guid)
resource_id = get_registration_resource_id(registration_guid, resource_type)
if resource_id is not None:
delete_registration_resource(registration_guid)
delete_registration_resource(registration_guid, resource_type)

url = '/v2/resources/'
raw_payload = {
Expand Down Expand Up @@ -1279,3 +1284,22 @@ def create_registration_resource(registration_guid, resource_type):
item_id=resource_id,
item_type='resources',
)['data']


def delete_registration_resources(registration_id):
"""This function deletes all the resources added to the given registration"""
session = client.Session(
api_base_url=settings.API_DOMAIN,
auth=(settings.REGISTRATIONS_USER, settings.REGISTRATIONS_USER_PASSWORD),
)
url = '/v2/registrations/{}/resources/'.format(registration_id)
data = session.get(url)['data']
if data:
for i in range(0, len(data)):
date_created = data[i]['attributes']['date_created']
now = datetime.now()
current_date = now.strftime('%Y-%m-%d')
if current_date in date_created:
registration_resource_id = data[i]['id']
delete_url = '/v2/resources/{}'.format(registration_resource_id)
session.delete(delete_url, item_type='resources')
3 changes: 2 additions & 1 deletion components/project.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from selenium.webdriver.common.by import By

import settings
import utils
from base.locators import (
BaseElement,
GroupLocator,
Expand Down Expand Up @@ -96,7 +97,7 @@ class CreateRegistrationModal(BaseElement):

def get_schema_names_list(self):
"""Returns the schema names from the schema list"""
return [schema.text for schema in self.schema_list]
return [utils.clean_text(schema.text) for schema in self.schema_list]

def select_schema_radio_button(self, schema_name='Open-Ended Registration'):
"""Selects the radio button corresponding to the given schema name"""
Expand Down
2 changes: 1 addition & 1 deletion pages/cos.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
class COSDonatePage(BasePage):
url = 'https://www.cos.io/support-cos'

identity = Locator(By.ID, 'Yourdonationtitle', settings.LONG_TIMEOUT)
identity = Locator(By.CSS_SELECTOR, 'h2#Yourdonationtitle', settings.LONG_TIMEOUT)
7 changes: 4 additions & 3 deletions pages/preprints.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from selenium.webdriver.common.by import By

import settings
import utils
from base.locators import (
ComponentLocator,
GroupLocator,
Expand Down Expand Up @@ -101,7 +102,7 @@ class PreprintSubmitPage(BasePreprintPage):

def select_from_dropdown_listbox(self, selection):
for option in self.dropdown_options:
if option.text == selection:
if utils.clean_text(option.text) == selection:
option.click()
break

Expand All @@ -114,7 +115,7 @@ def select_from_dropdown_listbox(self, selection):

def select_top_level_subject(self, selection):
for subject in self.top_level_subjects:
if subject.text == selection:
if utils.clean_text(subject.text) == selection:
# Find the checkbox element and click it to select the subject
checkbox = subject.find_element_by_css_selector(
'input.ember-checkbox.ember-view'
Expand Down Expand Up @@ -325,7 +326,7 @@ def click_provider_group_link(self, provider_name, link_name):
group_name = provider_group.find_element_by_css_selector(
'span._provider-name_gp8jcl'
)
if provider_name == group_name.text:
if provider_name == utils.clean_text(group_name.text):
links = provider_group.find_elements_by_css_selector(
'ul._provider-links_gp8jcl > li > a'
)
Expand Down
7 changes: 4 additions & 3 deletions pages/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from selenium.webdriver.common.by import By

import settings
import utils
from api import osf_api
from base.locators import (
ComponentLocator,
Expand Down Expand Up @@ -43,7 +44,7 @@

class ProjectPage(GuidBasePage):

identity = Locator(By.ID, 'projectScope')
identity = Locator(By.ID, 'projectScope', settings.LONG_TIMEOUT)
title = Locator(By.ID, 'nodeTitleEditable', settings.LONG_TIMEOUT)
title_input = Locator(By.CSS_SELECTOR, '.form-inline input')
title_edit_submit_button = Locator(By.CSS_SELECTOR, '.editable-submit')
Expand Down Expand Up @@ -535,7 +536,7 @@ class FilesMetadataPage(GuidBasePage):

def select_from_dropdown_listbox(self, selection):
for option in self.dropdown_options:
if option.text == selection:
if utils.clean_text(option.text) == selection:
option.click()
break

Expand Down Expand Up @@ -588,7 +589,7 @@ class ProjectMetadataPage(GuidBasePage):

def select_from_dropdown_listbox(self, selection):
for option in self.dropdown_options:
if option.text == selection:
if utils.clean_text(option.text) == selection:
option.click()
break

Expand Down
25 changes: 12 additions & 13 deletions pages/registries.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from selenium.webdriver.common.by import By

import settings
import utils
from base.locators import (
ComponentLocator,
GroupLocator,
Expand Down Expand Up @@ -114,7 +115,7 @@ class RegistrationDetailPage(BaseSubmittedRegistrationPage):

def select_from_dropdown_listbox(self, selection):
for option in self.dropdown_options:
if option.text == selection:
if utils.clean_text(option.text) == selection:
option.click()
break

Expand Down Expand Up @@ -179,7 +180,7 @@ class RegistrationMetadataPage(BaseSubmittedRegistrationPage):

def select_from_dropdown_listbox(self, selection):
for option in self.dropdown_options:
if option.text == selection:
if utils.clean_text(option.text) == selection:
option.click()
break

Expand Down Expand Up @@ -254,7 +255,7 @@ class RegistrationFileDetailPage(GuidBasePage):

def get_tag(self, tag_value):
for tag in self.tags:
if tag.text == tag_value:
if utils.clean_text(tag.text) == tag_value:
return tag
return None

Expand Down Expand Up @@ -366,7 +367,7 @@ def url(self):

def select_from_dropdown_listbox(self, selection):
for option in self.dropdown_options:
if option.text == selection:
if utils.clean_text(option.text) == selection:
option.click()
break

Expand Down Expand Up @@ -438,13 +439,13 @@ class DraftRegistrationMetadataPage(BaseRegistrationDraftPage):

def select_from_dropdown_listbox(self, selection):
for option in self.dropdown_options:
if option.text == selection:
if utils.clean_text(option.text) == selection:
option.click()
break

def select_top_level_subject(self, selection):
for subject in self.top_level_subjects:
if subject.text == selection:
if utils.clean_text(subject.text) == selection:
# Find the checkbox element and click it to select the subject
checkbox = subject.find_element_by_css_selector(
'input.ember-checkbox.ember-view'
Expand Down Expand Up @@ -474,10 +475,8 @@ class DraftRegistrationDesignPlanPage(BaseRegistrationDraftPage):
"""Draft Design Plan Page for an OSF Preregistration Template"""

url_addition = '2-design-plan'
identity = Locator(
By.CSS_SELECTOR, 'input[id^="radio-Experiment"]', settings.LONG_TIMEOUT
)
other_radio_button = Locator(By.CSS_SELECTOR, 'input[id^="radio-Other"]')
identity = Locator(By.CSS_SELECTOR, '[data-test-page-heading]')
other_radio_button = Locator(By.XPATH, '//div/input[@value="Other"]')
no_blinding_checkbox = Locator(
By.CSS_SELECTOR, 'div._Checkboxes_qxt8ij > div:nth-child(1) > input'
)
Expand All @@ -492,12 +491,12 @@ class DraftRegistrationSamplingPlanPage(BaseRegistrationDraftPage):

url_addition = '3-sampling-plan'
identity = Locator(
By.CSS_SELECTOR,
'input[id^="radio-Registration prior to creation"]',
By.XPATH,
'//input[@value="Registration following analysis of the data"]',
settings.LONG_TIMEOUT,
)
reg_following_radio_button = Locator(
By.CSS_SELECTOR, 'input[id^="radio-Registration following"]'
By.XPATH, '//input[@value="Registration following analysis of the data"]'
)
data_procedures_textbox = Locator(By.NAME, '__responseKey_q10|question')
sample_size_textbox = Locator(By.NAME, '__responseKey_q11')
Expand Down
8 changes: 6 additions & 2 deletions pages/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,13 @@ class AccountSettingsPage(BaseUserSettingsPage):
storage_location_listbox = Locator(
By.CSS_SELECTOR, 'div[data-test-region-selector] > div'
)
affiliation_help_text = Locator(
By.CSS_SELECTOR, '[data-test-affiliated-institutions-help-text]'
)
first_affiliated_institution = Locator(
By.CSS_SELECTOR, 'span[data-test-affiliated-institutions-item]'
)

first_aff_inst_delete_button = Locator(
By.CSS_SELECTOR, 'span[data-test-affiliated-institutions-delete] > button'
)
Expand All @@ -110,6 +114,7 @@ class AccountSettingsPage(BaseUserSettingsPage):
configure_2fa_button = Locator(
By.CSS_SELECTOR, 'button[data-test-two-factor-enable-button]'
)
two_factor_help = Locator(By.CSS_SELECTOR, '[data-test-why-two-factor]')
two_factor_qr_code_img = Locator(By.CSS_SELECTOR, 'div[data-test-2f-qr-code] > img')
cancel_2fa_button = Locator(
By.CSS_SELECTOR, 'button[data-test-two-factor-verify-cancel-button]'
Expand All @@ -127,7 +132,6 @@ class AccountSettingsPage(BaseUserSettingsPage):
unconfirmed_emails = GroupLocator(
By.CSS_SELECTOR, 'div[data-test-unconfirmed-email-item]'
)

configure_2fa_modal = ComponentLocator(Configure2FAModal)
confirm_deactivation_modal = ComponentLocator(ConfirmDeactivationRequestModal)
undo_deactivation_modal = ComponentLocator(UndoDeactivationRequestModal)
Expand All @@ -147,7 +151,7 @@ def get_unconfirmed_email_item(self, email_address):
class ConfigureAddonsPage(BaseUserSettingsPage):
url = settings.OSF_HOME + '/settings/addons/'

identity = Locator(By.CSS_SELECTOR, '#configureAddons')
identity = Locator(By.CSS_SELECTOR, 'div[data-analytics-scope="User addons"]')


class NotificationsPage(BaseUserSettingsPage):
Expand Down
10 changes: 10 additions & 0 deletions settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,16 @@
'resolution': '2048x1536',
'timezone': 'UTC',
},
'safari': {
'browser': 'Safari',
'browser_version': '17',
'os': 'OS X',
'os_version': 'Sonoma',
'timezone': 'UTC',
'networkLogs': True,
'enablePopups': False,
'acceptInsecureCerts': True,
},
}

BUILD = DRIVER
Expand Down
29 changes: 18 additions & 11 deletions tests/test_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import markers
import settings
import utils
from api import osf_api
from pages.collections import (
CollectionDiscoverPage,
Expand Down Expand Up @@ -326,9 +327,11 @@ def test_pre_moderation_collection_reject(
# first).
rejected_card = rejected_page.get_submission_card(collection_project.id)
assert (
rejected_card.find_element_by_css_selector(
'[data-test-review-action-comment]'
).text
utils.clean_text(
rejected_card.find_element_by_css_selector(
'[data-test-review-action-comment]'
).text
)
== '— Rejecting collection submission via selenium automated test.'
)
rejected_card.find_element_by_css_selector(
Expand All @@ -354,12 +357,12 @@ def test_pre_moderation_collection_reject(
assert project_page.collections_container.present()
project_page.collections_container.click()
assert (
project_page.first_collection_label.text
utils.clean_text(project_page.first_collection_label.text)
== "Rejected from Selenium Testing Collection's Collection"
)
project_page.collection_justification_link.click()
assert (
project_page.collection_justification_reason.text
utils.clean_text(project_page.collection_justification_reason.text)
== 'Rejecting collection submission via selenium automated test.'
)
finally:
Expand Down Expand Up @@ -436,9 +439,11 @@ def test_post_moderation_collection_remove(
# first).
removed_card = removed_page.get_submission_card(collection_project.id)
assert (
removed_card.find_element_by_css_selector(
'[data-test-review-action-comment]'
).text
utils.clean_text(
removed_card.find_element_by_css_selector(
'[data-test-review-action-comment]'
).text
)
== '— Removing collection submission via selenium automated test.'
)
removed_card.find_element_by_css_selector(
Expand Down Expand Up @@ -567,9 +572,11 @@ def test_post_moderation_collection_remove_by_project_admin(
# in the table since the default sort order is by Date (newest first).
removed_card = removed_page.get_submission_card(collection_project.id)
assert (
removed_card.find_element_by_css_selector(
'[data-test-review-action-comment]'
).text
utils.clean_text(
removed_card.find_element_by_css_selector(
'[data-test-review-action-comment]'
).text
)
== '— Project admin removing project from collection via selenium automated test.'
)
removed_card.find_element_by_css_selector(
Expand Down
2 changes: 1 addition & 1 deletion tests/test_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def test_collections_link(self, driver, dashboard_page):
# and switch focus to it.
WebDriverWait(driver, 3).until(EC.number_of_windows_to_be(2))
driver.switch_to.window(driver.window_handles[1])
WebDriverWait(driver, 3).until(
WebDriverWait(driver, 10).until(
EC.visibility_of_element_located((By.CLASS_NAME, 'hs-menu-wrapper'))
)
assert 'https://www.cos.io/products/osf-collections' in driver.current_url
Expand Down
Loading