diff --git a/tests/__init__.py b/tests/__init__.py index 3e067f1..36da097 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -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 @@ -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): diff --git a/tests/test_display.py b/tests/test_display.py index 7bf9827..715b8d9 100644 --- a/tests/test_display.py +++ b/tests/test_display.py @@ -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' @@ -17,32 +19,32 @@ 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 @@ -50,30 +52,30 @@ def test_script_split_recordings(self): 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__": diff --git a/tests/test_edit.py b/tests/test_edit.py index c0bc4f8..8d75c32 100644 --- a/tests/test_edit.py +++ b/tests/test_edit.py @@ -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 @@ -20,11 +20,11 @@ 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 @@ -32,23 +32,22 @@ def test_script_seed_event(self): 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 '
Field "Name":
' in self.driver.page_source assert '
Kept "Víkingur Ólafsson"
' in self.driver.page_source @@ -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 diff --git a/tests/test_reledit.py b/tests/test_reledit.py index dccb9b1..a552f1d 100644 --- a/tests/test_reledit.py +++ b/tests/test_reledit.py @@ -4,8 +4,9 @@ import unittest import pytest -from selenium.webdriver.support.ui import Select from selenium.common.exceptions import NoAlertPresentException +from selenium.webdriver.common.by import By +from selenium.webdriver.support.ui import Select from tests import MBSERVER, UserscriptsTC @@ -31,101 +32,101 @@ def test_script_clone_ext_relations(self): self.login('release', RELEASE_WO_WORKS_MBID + '/edit-relationships') self.load_userscript('mb-reledit-clone_relations.user.js') time.sleep(1) - assert len(self.driver.find_elements_by_class_name('rel-add')) == 0 - self.driver.find_element_by_id('clone_rels_script_toggle').click() - self.driver.find_element_by_css_selector('td.recording input').click() - self.driver.find_element_by_id('cloneExtRecording').send_keys(RECORDING_URL) + assert len(self.driver.find_elements(By.CLASS_NAME, 'rel-add')) == 0 + self.driver.find_element(By.ID, 'clone_rels_script_toggle').click() + self.driver.find_element(By.CSS_SELECTOR, 'td.recording input').click() + self.driver.find_element(By.ID, 'cloneExtRecording').send_keys(RECORDING_URL) time.sleep(5) - self.driver.find_element_by_id('cloneAR').click() + self.driver.find_element(By.ID, 'cloneAR').click() time.sleep(5) - assert len(self.driver.find_elements_by_class_name('rel-add')) > 1 - assert 'recorded at' in self.driver.find_element_by_css_selector( - 'td.recording').text - assert self.driver.find_element_by_id('edit-note-text').text + assert len(self.driver.find_elements(By.CLASS_NAME, 'rel-add')) > 1 + assert 'recorded at' in self.driver.find_element( + By.CSS_SELECTOR, 'td.recording').text + assert self.driver.find_element(By.ID, 'edit-note-text').text @pytest.mark.skip(reason="") def test_script_clone_ext_recording_relations(self): self.login('release', RELEASE_WO_WORKS_MBID + '/edit-relationships') self.load_userscript('mb-reledit-clone_relations.user.js') time.sleep(1) - assert len(self.driver.find_elements_by_class_name('rel-add')) == 0 - self.driver.find_element_by_id('clone_rels_script_toggle').click() - self.driver.find_elements_by_css_selector('td.recording input')[1].click() - self.driver.find_element_by_id('cloneExtRecording').send_keys(RECORDING_URL) + assert len(self.driver.find_elements(By.CLASS_NAME, 'rel-add')) == 0 + self.driver.find_element(By.ID, 'clone_rels_script_toggle').click() + self.driver.find_elements(By.CSS_SELECTOR, 'td.recording input')[1].click() + self.driver.find_element(By.ID, 'cloneExtRecording').send_keys(RECORDING_URL) time.sleep(5) - self.driver.find_element_by_id('cloneAR').click() + self.driver.find_element(By.ID, 'cloneAR').click() time.sleep(5) - assert len(self.driver.find_elements_by_class_name('rel-add')) > 1 - assert self.driver.find_element_by_id('edit-note-text').text + assert len(self.driver.find_elements(By.CLASS_NAME, 'rel-add')) > 1 + assert self.driver.find_element(By.ID, 'edit-note-text').text @pytest.mark.skip(reason="") def test_script_clone_recording_relations(self): self.login('release', RELEASE_W_RECRELS_MBID + '/edit-relationships') self.load_userscript('mb-reledit-clone_relations.user.js') time.sleep(1) - assert len(self.driver.find_elements_by_class_name('rel-add')) == 0 - self.driver.find_element_by_id('clone_rels_script_toggle').click() - self.driver.find_element_by_css_selector('th.recordings input').click() - self.driver.find_element_by_id('cloneRef').send_keys('2') + assert len(self.driver.find_elements(By.CLASS_NAME, 'rel-add')) == 0 + self.driver.find_element(By.ID, 'clone_rels_script_toggle').click() + self.driver.find_element(By.CSS_SELECTOR, 'th.recordings input').click() + self.driver.find_element(By.ID, 'cloneRef').send_keys('2') time.sleep(1) - self.driver.find_element_by_id('cloneAR').click() + self.driver.find_element(By.ID, 'cloneAR').click() time.sleep(5) - assert len(self.driver.find_elements_by_class_name('rel-add')) > 1 - assert self.driver.find_element_by_id('edit-note-text').text + assert len(self.driver.find_elements(By.CLASS_NAME, 'rel-add')) > 1 + assert self.driver.find_element(By.ID, 'edit-note-text').text @pytest.mark.skip(reason="") def test_script_clone_multi_sources(self): self.login('release', RELEASE_W_RECRELS_MBID + '/edit-relationships') self.load_userscript('mb-reledit-clone_relations.user.js') time.sleep(1) - assert len(self.driver.find_elements_by_class_name('rel-add')) == 0 - self.driver.find_element_by_id('clone_rels_script_toggle').click() - self.driver.find_element_by_css_selector('th.recordings input').click() - self.driver.find_element_by_id('cloneRef').send_keys('1-2') + assert len(self.driver.find_elements(By.CLASS_NAME, 'rel-add')) == 0 + self.driver.find_element(By.ID, 'clone_rels_script_toggle').click() + self.driver.find_element(By.CSS_SELECTOR, 'th.recordings input').click() + self.driver.find_element(By.ID, 'cloneRef').send_keys('1-2') time.sleep(1) - self.driver.find_element_by_id('cloneAR').click() + self.driver.find_element(By.ID, 'cloneAR').click() time.sleep(2) - assert 0 < len(set([node.text for node in self.driver.find_elements_by_css_selector( - 'tr:not(.even) td.recording span.rel-add a')])) < 3 - assert 0 < len(set([node.text for node in self.driver.find_elements_by_css_selector( - 'tr.even td.recording span.rel-add a')])) < 3 - assert self.driver.find_element_by_id('edit-note-text').text + assert 0 < len(set([node.text for node in self.driver.find_elements( + By.CSS_SELECTOR, 'tr:not(.even) td.recording span.rel-add a')])) < 3 + assert 0 < len(set([node.text for node in self.driver.find_elements( + By.CSS_SELECTOR, 'tr.even td.recording span.rel-add a')])) < 3 + assert self.driver.find_element(By.ID, 'edit-note-text').text def test_script_clone_release_relations(self): self.login('release', RELEASE_MBID + '/edit-relationships') self.load_userscript('mb-reledit-clone_relations.user.js') time.sleep(1) - assert len(self.driver.find_elements_by_class_name('rel-add')) == 0 - assert len(self.driver.find_elements_by_css_selector( - 'table.rel-editor-table td.relationship-list span.rel-add')) == 0 - self.driver.find_element_by_id('clone_release_rels_script_toggle').click() - self.driver.find_element_by_id('cloneExtRelease').send_keys(RELEASE_RELS_URL) + assert len(self.driver.find_elements(By.CLASS_NAME, 'rel-add')) == 0 + assert len(self.driver.find_elements( + By.CSS_SELECTOR, 'table.rel-editor-table td.relationship-list span.rel-add')) == 0 + self.driver.find_element(By.ID, 'clone_release_rels_script_toggle').click() + self.driver.find_element(By.ID, 'cloneExtRelease').send_keys(RELEASE_RELS_URL) time.sleep(3) - self.driver.find_element_by_id('cloneReleaseAR').click() + self.driver.find_element(By.ID, 'cloneReleaseAR').click() time.sleep(5) - assert len(self.driver.find_elements_by_css_selector( - 'table.rel-editor-table td.relationship-list span.rel-add')) == 1 - assert self.driver.find_element_by_id('edit-note-text').text + assert len(self.driver.find_elements( + By.CSS_SELECTOR, 'table.rel-editor-table td.relationship-list span.rel-add')) == 1 + assert self.driver.find_element(By.ID, 'edit-note-text').text def test_script_clone_GH_28(self): # check the relation direction is kept self.login('release', RELEASE_MBID + '/edit-relationships') self.load_userscript('mb-reledit-clone_relations.user.js') time.sleep(1) - assert len(self.driver.find_elements_by_class_name('rel-add')) == 0 + assert len(self.driver.find_elements(By.CLASS_NAME, 'rel-add')) == 0 assert not self.driver.page_source.count('samples of') count_backward = self.driver.page_source.count('sampled by') - self.driver.find_element_by_id('clone_rels_script_toggle').click() + self.driver.find_element(By.ID, 'clone_rels_script_toggle').click() time.sleep(1) - self.driver.find_element_by_css_selector('td.recording input').click() - self.driver.find_element_by_id('cloneExtRecording').send_keys(RECORDING_RELS_URL) + self.driver.find_element(By.CSS_SELECTOR, 'td.recording input').click() + self.driver.find_element(By.ID, 'cloneExtRecording').send_keys(RECORDING_RELS_URL) time.sleep(3) - self.driver.find_element_by_id('cloneAR').click() + self.driver.find_element(By.ID, 'cloneAR').click() time.sleep(4) - assert len(self.driver.find_elements_by_class_name('rel-add')) > 1 + assert len(self.driver.find_elements(By.CLASS_NAME, 'rel-add')) > 1 assert not self.driver.page_source.count('samples of') assert self.driver.page_source.count('sampled by') == count_backward + 1 - assert self.driver.find_element_by_id('edit-note-text').text + assert self.driver.find_element(By.ID, 'edit-note-text').text @pytest.mark.skip(reason="") def test_script_remove_dates(self): @@ -133,11 +134,11 @@ def test_script_remove_dates(self): self.load_userscript('mb-reledit-copy_dates.user.js') time.sleep(2) assert self.driver.page_source.count('on 2016-04-07') > 1 - self.driver.find_element_by_css_selector('td.recording input.recording').click() - self.driver.find_element_by_id('removeDates').click() + self.driver.find_element(By.CSS_SELECTOR, 'td.recording input.recording').click() + self.driver.find_element(By.ID, 'removeDates').click() time.sleep(1) assert 'on 2016-04-07' not in self.driver.page_source - assert self.driver.find_element_by_id('edit-note-text').text + assert self.driver.find_element(By.ID, 'edit-note-text').text @pytest.mark.skip(reason="") def test_script_copy_dates(self): @@ -145,18 +146,18 @@ def test_script_copy_dates(self): self.load_userscript('mb-reledit-copy_dates.user.js') time.sleep(2) assert self.driver.page_source.count('on 2016-04-07') > 1 - self.driver.find_element_by_css_selector('td.recording input.recording').click() - self.driver.find_element_by_id('removeDates').click() + self.driver.find_element(By.CSS_SELECTOR, 'td.recording input.recording').click() + self.driver.find_element(By.ID, 'removeDates').click() time.sleep(1) - self.driver.find_element_by_css_selector('td.recording .remove-item').click() - self.driver.find_element_by_css_selector('td.recording .remove-item').click() + self.driver.find_element(By.CSS_SELECTOR, 'td.recording .remove-item').click() + self.driver.find_element(By.CSS_SELECTOR, 'td.recording .remove-item').click() time.sleep(1) assert self.driver.page_source.count('on 2016-04-07') == 1 - self.driver.find_element_by_id('replaceDates').click() - self.driver.find_element_by_id('copyDates').click() + self.driver.find_element(By.ID, 'replaceDates').click() + self.driver.find_element(By.ID, 'copyDates').click() time.sleep(1) assert self.driver.page_source.count('on 2016-04-07') > 1 - assert self.driver.find_element_by_id('edit-note-text').text + assert self.driver.find_element(By.ID, 'edit-note-text').text @pytest.mark.skip(reason="") def test_script_guess_works(self): @@ -164,13 +165,13 @@ def test_script_guess_works(self): self.load_userscript('mb-reledit-guess_works.user.js') time.sleep(1) assert 'Search for works' in self.driver.page_source - assert len(self.driver.find_elements_by_css_selector('td.relationship-list')) == 0 + assert len(self.driver.find_elements(By.CSS_SELECTOR, 'td.relationship-list')) == 0 - self.driver.find_element_by_css_selector('td.recording input').click() - self.driver.find_element_by_id('searchWork').click() + self.driver.find_element(By.CSS_SELECTOR, 'td.recording input').click() + self.driver.find_element(By.ID, 'searchWork').click() time.sleep(5) - assert len(self.driver.find_elements_by_css_selector('td.relationship-list span.rel-add')) == 1 - assert self.driver.find_element_by_id('edit-note-text').text + assert len(self.driver.find_elements(By.CSS_SELECTOR, 'td.relationship-list span.rel-add')) == 1 + assert self.driver.find_element(By.ID, 'edit-note-text').text @pytest.mark.skip(reason="") def test_script_guess_main_works(self): @@ -179,82 +180,81 @@ def test_script_guess_main_works(self): time.sleep(2) # no repeats - self.driver.find_element_by_css_selector('th.recordings input').click() - self.driver.find_element_by_id('mainWork').send_keys(MAIN_WORK_MBID) + self.driver.find_element(By.CSS_SELECTOR, 'th.recordings input').click() + self.driver.find_element(By.ID, 'mainWork').send_keys(MAIN_WORK_MBID) time.sleep(1) - self.driver.find_element_by_id('fetchSubworks').click() + self.driver.find_element(By.ID, 'fetchSubworks').click() time.sleep(6) - assert len(self.driver.find_elements_by_css_selector('td.relationship-list span.rel-add')) == 4 - assert self.driver.find_element_by_id('edit-note-text').text + assert len(self.driver.find_elements(By.CSS_SELECTOR, 'td.relationship-list span.rel-add')) == 4 + assert self.driver.find_element(By.ID, 'edit-note-text').text @pytest.mark.skip(reason="") def test_script_guess_repeated_subworks(self): self.login('release', RELEASE_WO_WORKS_MBID + '/edit-relationships') self.load_userscript('mb-reledit-guess_works.user.js') time.sleep(1) - self.driver.find_element_by_css_selector('th.recordings input').click() - self.driver.find_element_by_id('mainWork').send_keys(MAIN_WORK_MBID) + self.driver.find_element(By.CSS_SELECTOR, 'th.recordings input').click() + self.driver.find_element(By.ID, 'mainWork').send_keys(MAIN_WORK_MBID) time.sleep(1) # partial repeats - assert len(self.driver.find_elements_by_css_selector('td.relationship-list')) == 0 - self.driver.find_element_by_id('repeats').send_keys('1,1,2,1') + assert len(self.driver.find_elements(By.CSS_SELECTOR, 'td.relationship-list')) == 0 + self.driver.find_element(By.ID, 'repeats').send_keys('1,1,2,1') time.sleep(1) - self.driver.find_element_by_id('fetchSubworks').click() + self.driver.find_element(By.ID, 'fetchSubworks').click() time.sleep(4) - assert len(self.driver.find_elements_by_css_selector('td.relationship-list span.rel-add')) == 5 - assert ['partial' in node.text for node in self.driver.find_elements_by_css_selector( - 'td.relationship-list span.rel-add')] == [False, False, True, True, False] - for node in self.driver.find_elements_by_css_selector( - 'tr.recording-of button.remove-item'): + assert len(self.driver.find_elements(By.CSS_SELECTOR, 'td.relationship-list span.rel-add')) == 5 + assert ['partial' in node.text for node in self.driver.find_elements( + By.CSS_SELECTOR, 'td.relationship-list span.rel-add')] == [False, False, True, True, False] + for node in self.driver.find_elements(By.CSS_SELECTOR, 'tr.recording-of button.remove-item'): node.click() time.sleep(2) # missing repeats - self.driver.find_element_by_id('repeats').clear() - self.driver.find_element_by_id('repeats').send_keys('1,1,0,1') + self.driver.find_element(By.ID, 'repeats').clear() + self.driver.find_element(By.ID, 'repeats').send_keys('1,1,0,1') time.sleep(1) - self.driver.find_element_by_id('fetchSubworks').click() + self.driver.find_element(By.ID, 'fetchSubworks').click() time.sleep(3) - assert len(self.driver.find_elements_by_css_selector('td.relationship-list span.rel-add')) == 3 - assert self.driver.find_element_by_id('edit-note-text').text + assert len(self.driver.find_elements(By.CSS_SELECTOR, 'td.relationship-list span.rel-add')) == 3 + assert self.driver.find_element(By.ID, 'edit-note-text').text @pytest.mark.skip(reason="") def test_script_guess_overlapping_subworks(self): self.login('release', RELEASE_WO_WORKS_MBID + '/edit-relationships') self.load_userscript('mb-reledit-guess_works.user.js') time.sleep(2) - self.driver.find_element_by_css_selector('th.recordings input').click() - self.driver.find_element_by_id('mainWork').send_keys(MAIN_WORK_MBID) + self.driver.find_element(By.CSS_SELECTOR, 'th.recordings input').click() + self.driver.find_element(By.ID, 'mainWork').send_keys(MAIN_WORK_MBID) time.sleep(1) # overlapping repeats - self.driver.find_element_by_id('repeats').clear() - self.driver.find_element_by_id('repeats').send_keys('1,1,-1,1') + self.driver.find_element(By.ID, 'repeats').clear() + self.driver.find_element(By.ID, 'repeats').send_keys('1,1,-1,1') time.sleep(2) - self.driver.find_element_by_id('fetchSubworks').click() + self.driver.find_element(By.ID, 'fetchSubworks').click() time.sleep(4) - assert len(self.driver.find_elements_by_css_selector('td.relationship-list span.rel-add')) == 4 - assert [len(node.find_elements_by_css_selector('h3 > .remove-item')) - for node in self.driver.find_elements_by_css_selector('td.works')][:3] == [1, 2, 1] + assert len(self.driver.find_elements(By.CSS_SELECTOR, 'td.relationship-list span.rel-add')) == 4 + assert [len(node.find_elements(By.CSS_SELECTOR, 'h3 > .remove-item')) + for node in self.driver.find_elements(By.CSS_SELECTOR, 'td.works')][:3] == [1, 2, 1] assert not any( - ['partial' in node.text for node in self.driver.find_elements_by_css_selector( - 'td.relationship-list span.rel-add')]) - assert self.driver.find_element_by_id('edit-note-text').text + ['partial' in node.text for node in self.driver.find_elements( + By.CSS_SELECTOR, 'td.relationship-list span.rel-add')]) + assert self.driver.find_element(By.ID, 'edit-note-text').text @pytest.mark.skip(reason="") def test_script_release_rels(self): self.login('release', RELEASE_W_RELS_MBID + '/edit-relationships') self.load_userscript('mb-reledit-release_rel_to_recording_rel.user.js') time.sleep(1) - assert len(self.driver.find_elements_by_css_selector('td.relationship-list span.rel-add')) == 0 - self.driver.find_element_by_css_selector('input.recording').click() - self.driver.find_element_by_id('moveAR').click() + assert len(self.driver.find_elements(By.CSS_SELECTOR, 'td.relationship-list span.rel-add')) == 0 + self.driver.find_element(By.CSS_SELECTOR, 'input.recording').click() + self.driver.find_element(By.ID, 'moveAR').click() time.sleep(1) - assert len(self.driver.find_elements_by_css_selector('td.relationship-list span.rel-add')) == 4 - assert len(self.driver.find_elements_by_css_selector( - 'table.rel-editor-table td.relationship-list span.rel-remove')) == 4 - assert self.driver.find_element_by_id('edit-note-text').text + assert len(self.driver.find_elements(By.CSS_SELECTOR, 'td.relationship-list span.rel-add')) == 4 + assert len(self.driver.find_elements( + By.CSS_SELECTOR, 'table.rel-editor-table td.relationship-list span.rel-remove')) == 4 + assert self.driver.find_element(By.ID, 'edit-note-text').text @pytest.mark.skip(reason="") def test_script_set_instruments(self): @@ -263,17 +263,17 @@ def test_script_set_instruments(self): time.sleep(1) count_from = self.driver.page_source.count('orchestra') count_to = self.driver.page_source.count('remixer') - self.driver.find_element_by_css_selector('td.recording input').click() - self.driver.find_element_by_id('instrument_script_toggle').click() - select = Select(self.driver.find_element_by_id('fromRole')) + self.driver.find_element(By.CSS_SELECTOR, 'td.recording input').click() + self.driver.find_element(By.ID, 'instrument_script_toggle').click() + select = Select(self.driver.find_element(By.ID, 'fromRole')) select.select_by_visible_text(' orchestra') - select = Select(self.driver.find_element_by_id('toRole')) + select = Select(self.driver.find_element(By.ID, 'toRole')) select.select_by_visible_text(' remixer') - self.driver.find_element_by_id('setRole').click() + self.driver.find_element(By.ID, 'setRole').click() time.sleep(1) assert self.driver.page_source.count('orchestra') < count_from assert self.driver.page_source.count('remixer') > count_to - assert self.driver.find_element_by_id('edit-note-text').text + assert self.driver.find_element(By.ID, 'edit-note-text').text @pytest.mark.skip(reason="") def test_script_relation_attrs(self): @@ -281,40 +281,40 @@ def test_script_relation_attrs(self): self.load_userscript('mb-reledit-set_relation_attrs.user.js') time.sleep(1) assert '(live)' not in self.driver.page_source - self.driver.find_element_by_id('relattrs_script_toggle').click() + self.driver.find_element(By.ID, 'relattrs_script_toggle').click() # set live from recording checkbox - self.driver.find_element_by_css_selector('td.recording input').click() - self.driver.find_element_by_id('setLive').click() + self.driver.find_element(By.CSS_SELECTOR, 'td.recording input').click() + self.driver.find_element(By.ID, 'setLive').click() time.sleep(1) assert '(live)' in self.driver.page_source # set partial from second work checkbox - self.driver.find_elements_by_css_selector('td.works input')[1].click() - self.driver.find_element_by_id('setPartial').click() + self.driver.find_elements(By.CSS_SELECTOR, 'td.works input')[1].click() + self.driver.find_element(By.ID, 'setPartial').click() time.sleep(1) assert '(live)' not in self.driver.page_source assert '(live and partial)' in self.driver.page_source # unset live from second work checkbox - self.driver.find_element_by_id('toggleLive').click() + self.driver.find_element(By.ID, 'toggleLive').click() time.sleep(1) assert '(live)' not in self.driver.page_source assert '(live and partial)' not in self.driver.page_source assert '(partial)' in self.driver.page_source - assert self.driver.find_element_by_id('edit-note-text').text + assert self.driver.find_element(By.ID, 'edit-note-text').text @pytest.mark.skip(reason="") def test_script_set_writer(self): self.login('release', SMALL_RELEASE_MBID + '/edit-relationships') self.load_userscript('mb-reledit-set_rec_artist_as_writer.user.js') time.sleep(2) - assert not len(self.driver.find_elements_by_css_selector('tr.writer')) - self.driver.find_element_by_css_selector('td.recording input').click() - self.driver.find_element_by_id('setWriter').click() + assert not len(self.driver.find_elements(By.CSS_SELECTOR, 'tr.writer')) + self.driver.find_element(By.CSS_SELECTOR, 'td.recording input').click() + self.driver.find_element(By.ID, 'setWriter').click() time.sleep(2) - assert len(self.driver.find_elements_by_css_selector('tr.writer')) - assert self.driver.find_element_by_css_selector('tr.writer').text == 'writer:\nAttacca Quartet' + assert len(self.driver.find_elements(By.CSS_SELECTOR, 'tr.writer')) + assert self.driver.find_element(By.CSS_SELECTOR, 'tr.writer').text == 'writer:\nAttacca Quartet' pass