Skip to content

Commit

Permalink
Bump selenium selectors syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerome-Roy committed Nov 25, 2024
1 parent a625704 commit 247bfe6
Show file tree
Hide file tree
Showing 4 changed files with 175 additions and 173 deletions.
8 changes: 5 additions & 3 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By

# from selenium.webdriver.common.keys import Keys


Expand Down Expand Up @@ -35,15 +37,15 @@ def login(self, *args):
if args:
url += '?returnto=%2F' + '%2F'.join(args)
self.driver.get(url)
elem = self.driver.find_element_by_id('id-username')
elem = self.driver.find_element(By.ID, 'id-username')
elem.send_keys('loujin')
elem = self.driver.find_element_by_id('id-password')
elem = self.driver.find_element(By.ID, 'id-password')
elem.send_keys('mb')
elem.submit()

# def test_login(self):
# self.login()
# assert 'loujin' in self.driver.find_element_by_class_name('account').text
# assert 'loujin' in self.driver.find_element(By.CLASS_NAME, 'account').text
# assert self.driver.current_url == 'https://test.musicbrainz.org/user/loujin'

def load_userscript(self, filepath):
Expand Down
52 changes: 27 additions & 25 deletions tests/test_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

from tests import UserscriptsTC

from selenium.webdriver.common.by import By

WORK_MBID = 'cc6eba78-85ef-3834-a400-a34e0d8856d9'
MAIN_WORK_MBID = 'db6400f0-6492-4c4a-9361-470be14d5bf2'
MAIN_WORK_MBID2 = '8f32fb44-fde9-4e44-ad54-d7ac12703b4f'
Expand All @@ -17,63 +19,63 @@ class DisplayUserscriptsTC(UserscriptsTC):
def test_script_sortable_columns(self):
self.login('work', WORK_MBID)
self.load_userscript('mb-display_sortable_table.user.js')
assert self.driver.find_element_by_id('loujine-sidebar')
btn = self.driver.find_element_by_id('makeSortable')
assert self.driver.find_element(By.ID, 'loujine-sidebar')
btn = self.driver.find_element(By.ID, 'makeSortable')
btn.click()
assert self.driver.find_element_by_css_selector('th.sortable').text == 'Date↕'
assert self.driver.find_element(By.CSS_SELECTOR, 'th.sortable').text == 'Date↕'

assert int(self.driver.find_element_by_css_selector('table.tbl tr.odd td').text[:4]) < 1950
self.driver.find_element_by_css_selector('th.sortable').click()
assert int(self.driver.find_element_by_css_selector('table.tbl tr.odd td').text[:4]) > 2018
assert int(self.driver.find_element(By.CSS_SELECTOR, 'table.tbl tr.odd td').text[:4]) < 1950
self.driver.find_element(By.CSS_SELECTOR, 'th.sortable').click()
assert int(self.driver.find_element(By.CSS_SELECTOR, 'table.tbl tr.odd td').text[:4]) > 2018

def test_script_count_alias(self):
self.login('work', WORK_MBID)
self.load_userscript('mb-display_count_alias.user.js')
header = self.driver.find_element_by_css_selector("a[href$='/aliases']")
header = self.driver.find_element(By.CSS_SELECTOR, "a[href$='/aliases']")
time.sleep(5)
assert 'background-color: rgb' in header.get_attribute('style')

def test_script_work_relations_for_artist_recordings(self):
self.login('artist', CONDUCTOR_MBID + '/relationships')
self.load_userscript('mb-display_work_relations_for_artist_recordings.user.js')
btn = self.driver.find_element_by_id('showMissingWorks')
btn = self.driver.find_element(By.ID, 'showMissingWorks')
btn.click()

def test_script_split_recordings(self):
self.login('work', MAIN_WORK_MBID)
self.load_userscript('mb-display_split_recordings.user.js')
btn = self.driver.find_element_by_id('displaySubworkRecordings')
btn = self.driver.find_element(By.ID, 'displaySubworkRecordings')
btn.click()
time.sleep(20)
assert '(33:04)' in self.driver.page_source

def test_script_split_recordings_no_rels(self):
self.login('work', MAIN_WORK_MBID2)
self.load_userscript('mb-display_split_recordings.user.js')
btn = self.driver.find_element_by_id('displaySubworkRecordings')
btn = self.driver.find_element(By.ID, 'displaySubworkRecordings')
btn.click()
time.sleep(35)
assert '(23:34)' in self.driver.page_source

def test_script_lean_ui(self):
self.login('release', RELEASE_MBID)
assert self.driver.find_element_by_css_selector(f"li > a[href$='{RELEASE_MBID}/details']")
assert self.driver.find_element_by_css_selector(f"li > a[href$='{RELEASE_MBID}/tags']")
assert self.driver.find_element_by_css_selector('th.rating').text
assert self.driver.find_element_by_css_selector('h2.rating').text
assert self.driver.find_element_by_css_selector('h2.reviews').text
assert self.driver.find_element(By.CSS_SELECTOR, f"li > a[href$='{RELEASE_MBID}/details']")
assert self.driver.find_element(By.CSS_SELECTOR, f"li > a[href$='{RELEASE_MBID}/tags']")
assert self.driver.find_element(By.CSS_SELECTOR, 'th.rating').text
assert self.driver.find_element(By.CSS_SELECTOR, 'h2.rating').text
assert self.driver.find_element(By.CSS_SELECTOR, 'h2.reviews').text

self.load_userscript('mb-display_lean_ui.user.js')
assert not self.driver.find_elements_by_css_selector(f"li > a[href$='{RELEASE_MBID}/details']")
assert not self.driver.find_elements_by_css_selector(f"li > a[href$='{RELEASE_MBID}/tags']")
assert not self.driver.find_element_by_css_selector('th.rating').text
assert not self.driver.find_element_by_css_selector('h2.rating').text
assert not self.driver.find_element_by_css_selector('#toggle-release-information dl').is_displayed()
assert not self.driver.find_element_by_css_selector('#toggle-additional-details dl').is_displayed()
assert not self.driver.find_element_by_css_selector('#toggle-labels ul').is_displayed()
assert not self.driver.find_element_by_css_selector('#toggle-release-events div').is_displayed()
assert not self.driver.find_element_by_css_selector('#toggle-external-links ul').is_displayed()
assert not self.driver.find_element_by_css_selector('h2.reviews').text
assert not self.driver.find_elements(By.CSS_SELECTOR, f"li > a[href$='{RELEASE_MBID}/details']")
assert not self.driver.find_elements(By.CSS_SELECTOR, f"li > a[href$='{RELEASE_MBID}/tags']")
assert not self.driver.find_element(By.CSS_SELECTOR, 'th.rating').text
assert not self.driver.find_element(By.CSS_SELECTOR, 'h2.rating').text
assert not self.driver.find_element(By.CSS_SELECTOR, '#toggle-release-information dl').is_displayed()
assert not self.driver.find_element(By.CSS_SELECTOR, '#toggle-additional-details dl').is_displayed()
assert not self.driver.find_element(By.CSS_SELECTOR, '#toggle-labels ul').is_displayed()
assert not self.driver.find_element(By.CSS_SELECTOR, '#toggle-release-events div').is_displayed()
assert not self.driver.find_element(By.CSS_SELECTOR, '#toggle-external-links ul').is_displayed()
assert not self.driver.find_element(By.CSS_SELECTOR, 'h2.reviews').text


if __name__ == "__main__":
Expand Down
46 changes: 22 additions & 24 deletions tests/test_edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import time
import unittest

import pytest
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select

from tests import UserscriptsTC
Expand All @@ -20,35 +20,34 @@ class EditUserscriptsTC(UserscriptsTC):
def test_script_seed_event(self):
self.login('recording', RECORDING_MBID)
self.load_userscript('mb-edit-seed_event_from_recording.user.js')
self.driver.find_element_by_id('createConcert').click()
self.driver.find_element(By.ID, 'createConcert').click()
time.sleep(8)
self.driver.switch_to.window(self.driver.window_handles[-1])
assert 'event/create' in self.driver.current_url
assert self.driver.find_element_by_id('id-edit-event.setlist').text
assert self.driver.find_element(By.ID, 'id-edit-event.setlist').text
assert 'held at:' in self.driver.page_source
assert 'main performers:' in self.driver.page_source
assert 'recording location for:' in self.driver.page_source

def test_script_set_video(self):
self.login('release', RELEASE_MBID)
self.load_userscript('mb-edit-set_video_recordings.user.js')
self.driver.find_element_by_id('video_script_toggle').click()
self.driver.find_element(By.ID, 'video_script_toggle').click()
time.sleep(2)
assert len(self.driver.find_elements_by_class_name('replacevideo')) > 1
self.driver.find_element_by_id('video-68eec263-13e4-4a5f-8042-23117714cdce').click()
assert len(self.driver.find_elements(By.CLASS_NAME, 'replacevideo')) > 1
self.driver.find_element(By.ID, 'video-68eec263-13e4-4a5f-8042-23117714cdce').click()
# self.driver.set_network_conditions(offline=True, latency=1000, throughput=500 * 1024)
# self.driver.find_element_by_id('batch_video').click()
# self.driver.find_element(By.ID, 'batch_video').click()
# time.sleep(1)
# assert 'Fetching required data' in self.driver.page_source

@pytest.mark.skip(reason="external link already exists")
def test_script_wikidata(self):
self.login('artist', ARTIST_MBID + '/edit')
self.load_userscript('mb-edit-create_from_wikidata.user.js')
time.sleep(1)
assert 'Add external link' in self.driver.page_source
assert len(self.driver.find_elements_by_class_name('url')) > 18
self.driver.find_element_by_id('linkParser').send_keys(WIKIDATA_LINK)
assert len(self.driver.find_elements(By.CLASS_NAME, 'url')) > 18
self.driver.find_element(By.ID, 'linkParser').send_keys(WIKIDATA_LINK)
time.sleep(1)
assert '<dt>Field "Name":</dt>' in self.driver.page_source
assert '<dd>Kept "Víkingur Ólafsson"</dd>' in self.driver.page_source
Expand All @@ -59,40 +58,39 @@ def test_script_set_aliases(self):
self.login('artist', ARTIST_MBID + '/aliases')
self.load_userscript('mb-edit-add_aliases.user.js')
assert 'Add a new row' in self.driver.page_source
self.driver.find_element_by_id('addRow').click()
self.driver.find_element(By.ID, 'addRow').click()
time.sleep(1)
lang = [o.text for o in self.driver.find_elements_by_class_name('language')]
lang = [o.text for o in self.driver.find_elements(By.CLASS_NAME, 'language')]
assert sorted(lang) == lang
select = Select(self.driver.find_element_by_css_selector('tr.newAlias select'))
select = Select(self.driver.find_element(By.CSS_SELECTOR, 'tr.newAlias select'))
select.select_by_visible_text('Legal name')
assert self.driver.find_element_by_css_selector(
'tr.newAlias select').get_attribute('selectedIndex') == '2'
self.driver.find_element_by_id('addRow').click()
assert self.driver.find_element(
By.CSS_SELECTOR, 'tr.newAlias select').get_attribute('selectedIndex') == '2'
self.driver.find_element(By.ID, 'addRow').click()
time.sleep(1)
assert len(self.driver.find_elements_by_class_name('newAlias')) == 2
assert len(self.driver.find_elements(By.CLASS_NAME, 'newAlias')) == 2
# remove first (modified) row
self.driver.find_element_by_class_name('deleteRow').click()
self.driver.find_element(By.CLASS_NAME, 'deleteRow').click()
time.sleep(1)
# row 1 is now the former row 2 (i.e. empty)
assert self.driver.find_element_by_css_selector(
'tr.newAlias select').get_attribute('selectedIndex') == '0'
assert self.driver.find_element(
By.CSS_SELECTOR, 'tr.newAlias select').get_attribute('selectedIndex') == '0'

@pytest.mark.skip(reason="async releditor")
def test_script_edit_subworks(self):
self.login('work', WORK_WITH_SW_MBID + '/edit')
self.load_userscript('mb-edit-edit_subworks.user.js')
time.sleep(1)
assert '(movement)' in self.driver.page_source

select = Select(self.driver.find_element_by_id('subwork_attribute'))
select = Select(self.driver.find_element(By.ID, 'subwork_attribute'))
select.select_by_visible_text('act')
self.driver.find_element_by_id('setSubworksAttributes').click()
self.driver.find_element(By.ID, 'setSubworksAttributes').click()
time.sleep(1)
assert '(movement)' not in self.driver.page_source
assert '(act and movement)' in self.driver.page_source

select.select_by_visible_text('movement')
self.driver.find_element_by_id('setSubworksAttributes').click()
self.driver.find_element(By.ID, 'setSubworksAttributes').click()
time.sleep(1)
assert '(act and movement)' not in self.driver.page_source
assert '(act)' in self.driver.page_source
Expand Down
Loading

0 comments on commit 247bfe6

Please sign in to comment.