diff --git a/test/test_description.py b/test/test_description.py index ef937d0..292e78d 100644 --- a/test/test_description.py +++ b/test/test_description.py @@ -1,12 +1,13 @@ from test.test_selenium import TestSelenium from unittest import TestCase +from selenium.webdriver.common.by import By class TestDescription(TestSelenium, TestCase): def setUp(self): super(TestDescription, self).setUp() - self.plus_button = self.driver.find_element_by_id('plus-button') - self.desc = self.driver.find_element_by_id('description') + self.plus_button = self.driver.find_element(By.ID, 'plus-button') + self.desc = self.driver.find_element(By.ID, 'description') self.tp_ShowingColumns = "ShowingColumns: " self.tp_SortedBy = "; SortedBy: " self.tp_Minver = "; FilteredBy: MinHugoVersion=" diff --git a/test/test_description_per_features.py b/test/test_description_per_features.py index 44eecbc..96faded 100644 --- a/test/test_description_per_features.py +++ b/test/test_description_per_features.py @@ -1,67 +1,69 @@ +import re +from secrets import choice from test.test_description import TestDescription from unittest import TestCase -from secrets import choice -import re + +from selenium.webdriver.common.by import By class TestDescriptionPerFeatures(TestDescription, TestCase): def setUp(self): super(TestDescriptionPerFeatures, self).setUp() - self.driver.find_element_by_id('button-for-filter-by-features').click() + self.driver.find_element(By.ID, 'button-for-filter-by-features').click() self.match = re.compile(r'^(.*)(\s\(\d*\))$') def test_description_per_features(self): - featureSelectionRow = self.driver.find_element_by_id( - 'featureSelectionRow') + featureSelectionRow = self.driver.find_element( + By.ID, 'featureSelectionRow') inputs = [ x.get_attribute( 'id' - ) for x in featureSelectionRow.find_elements_by_tag_name( - 'input' + ) for x in featureSelectionRow.find_elements( + By.TAG_NAME, 'input' ) ] for x in inputs: - button = self.driver.find_element_by_id( - x).find_element_by_xpath('..') + button = self.driver.find_element( + By.ID, x).find_element(By.XPATH, '..') self.features = self.match.search( - button.find_element_by_tag_name('label').text).group(1) + button.find_element(By.TAG_NAME, 'label').text).group(1) button.click() self.coalesced_text_test() - self.driver.find_element_by_id( - x).find_element_by_xpath('..').click() + self.driver.find_element( + By.ID, x).find_element(By.XPATH, '..').click() def test_description_per_features_random(self): self.randomly_select_feature() def randomly_select_feature(self): - featureSelectionRow = self.driver.find_element_by_id( - 'featureSelectionRow') + featureSelectionRow = self.driver.find_element( + By.ID, 'featureSelectionRow') inputs = [ x.get_attribute( 'id' - ) for x in featureSelectionRow.find_elements_by_tag_name( - 'input' + ) for x in featureSelectionRow.find_elements( + By.TAG_NAME, 'input' ) ] unchecked_inputs = [ - x for x in inputs if self.driver.find_element_by_id( - x).is_selected() is False + x for x in inputs if self.driver.find_element( + By.ID, x).is_selected() is False ] if len(unchecked_inputs) > 0: random_input = choice(unchecked_inputs) - button = self.driver.find_element_by_id( - random_input).find_element_by_xpath('..') + button = self.driver.find_element( + By.ID, random_input).find_element(By.XPATH, '..') feature = self.match.search( - button.find_element_by_tag_name('label').text).group(1) + button.find_element(By.TAG_NAME, 'label').text).group(1) button.click() diff --git a/test/test_description_per_license.py b/test/test_description_per_license.py index 446d2a9..d9d1ce1 100644 --- a/test/test_description_per_license.py +++ b/test/test_description_per_license.py @@ -1,32 +1,34 @@ +import re from test.test_description import TestDescription from unittest import TestCase -import re + +from selenium.webdriver.common.by import By class TestDescriptionPerLicense(TestDescription, TestCase): def test_description_per_license(self): match = re.compile(r'^(.*)(\s\(\d*\))$') - self.driver.find_element_by_id('button-for-filter-by-license').click() + self.driver.find_element(By.ID, 'button-for-filter-by-license').click() - licenseSelectionRow = self.driver.find_element_by_id( - 'licenseSelectionRow' + licenseSelectionRow = self.driver.find_element( + By.ID, 'licenseSelectionRow' ) inputs = [ x.get_attribute( 'id' - ) for x in licenseSelectionRow.find_elements_by_tag_name( - 'input' + ) for x in licenseSelectionRow.find_elements( + By.TAG_NAME, 'input' ) ] for i, x in enumerate(inputs): - button = self.driver.find_element_by_id( - x).find_element_by_xpath('..') + button = self.driver.find_element( + By.ID, x).find_element(By.XPATH, '..') license = match.search( - button.find_element_by_tag_name('label').text).group(1) + button.find_element(By.TAG_NAME, 'label').text).group(1) if i == 0: self.licenses = license else: diff --git a/test/test_description_per_min_hugo_version.py b/test/test_description_per_min_hugo_version.py index 9df0bc4..1d5f109 100644 --- a/test/test_description_per_min_hugo_version.py +++ b/test/test_description_per_min_hugo_version.py @@ -1,29 +1,31 @@ from test.test_description import TestDescription from unittest import TestCase +from selenium.webdriver.common.by import By + class TestDescriptionPerMinHugoVersion(TestDescription, TestCase): def test_description_per_min_hugo_version(self): - self.driver.find_element_by_id('button-for-filter-by-minver').click() + self.driver.find_element(By.ID, 'button-for-filter-by-minver').click() - minVerSelectionRow = self.driver.find_element_by_id( - 'minVerSelectionRow' + minVerSelectionRow = self.driver.find_element( + By.ID, 'minVerSelectionRow' ) inputs = [ x.get_attribute( 'id' - ) for x in minVerSelectionRow.find_elements_by_tag_name( - 'input' + ) for x in minVerSelectionRow.find_elements( + By.TAG_NAME, 'input' ) ] for x in inputs: - button = self.driver.find_element_by_id( - x).find_element_by_xpath('..') + button = self.driver.find_element( + By.ID, x).find_element(By.XPATH, '..') - self.min_ver = button.find_element_by_tag_name('label').text + self.min_ver = button.find_element(By.TAG_NAME, 'label').text button.click() self.coalesced_text_test() diff --git a/test/test_description_per_more_columns.py b/test/test_description_per_more_columns.py index 3b03b83..bd20b71 100644 --- a/test/test_description_per_more_columns.py +++ b/test/test_description_per_more_columns.py @@ -1,64 +1,65 @@ from test.test_description import TestDescription from unittest import TestCase +from selenium.webdriver.common.by import By + class TestDescriptionPerMoreColumns(TestDescription, TestCase): def test_description_per_more_columns(self): - self.driver.find_element_by_id( - 'button-for-showing-columns').click() + self.driver.find_element(By.ID, 'button-for-showing-columns').click() - self.driver.find_element_by_id( - 'commit-column-selection-input' - ).find_element_by_xpath('..').click() + self.driver.find_element( + By.ID, 'commit-column-selection-input' + ).find_element(By.XPATH, '..').click() self.columns = "theme, date, stars" self.coalesced_text_test() - self.driver.find_element_by_id( - 'num_stars-column-selection-input' - ).find_element_by_xpath('..').click() + self.driver.find_element( + By.ID, 'num_stars-column-selection-input' + ).find_element(By.XPATH, '..').click() self.columns = "theme, date" self.coalesced_text_test() - self.driver.find_element_by_id( - 'date-column-selection-input' - ).find_element_by_xpath('..').click() + self.driver.find_element( + By.ID, 'date-column-selection-input' + ).find_element(By.XPATH, '..').click() self.columns = "theme" self.coalesced_text_test() - self.driver.find_element_by_id( - 'cname-column-selection-input' - ).find_element_by_xpath('..').click() + self.driver.find_element( + By.ID, 'cname-column-selection-input' + ).find_element(By.XPATH, '..').click() self.columns = "theme, date, stars, commit" self.coalesced_text_test() - self.driver.find_element_by_id( - 'min_ver-column-selection-input' - ).find_element_by_xpath('..').click() + self.driver.find_element( + By.ID, 'min_ver-column-selection-input' + ).find_element(By.XPATH, '..').click() self.columns = "theme, date, stars, commit, minVer" self.coalesced_text_test() - self.driver.find_element_by_id( - 'license-column-selection-input' - ).find_element_by_xpath('..').click() + self.driver.find_element( + By.ID, 'license-column-selection-input' + ).find_element(By.XPATH, '..').click() self.columns = "theme, date, stars, commit, minVer, license" self.coalesced_text_test() - self.driver.find_element_by_id( - 'desc-column-selection-input' - ).find_element_by_xpath('..').click() + self.driver.find_element( + By.ID, 'desc-column-selection-input' + ).find_element(By.XPATH, '..').click() self.columns = "theme, date, stars, commit, minVer, license, desc" self.coalesced_text_test() - self.driver.find_element_by_id( - 'tags-column-selection-input' - ).find_element_by_xpath('..').click() + self.driver.find_element( + By.ID, 'tags-column-selection-input' + ).find_element(By.XPATH, '..').click() self.columns = "theme, date, stars, commit, minVer, license, desc, "\ "tags" self.coalesced_text_test() - self.driver.find_element_by_id( - 'features-column-selection-input' - ).find_element_by_xpath('..').click() + self.driver.find_element( + By.ID, 'features-column-selection-input' + ).find_element(By.XPATH, '..').click() self.columns = "theme, date, stars, commit, minVer, license, desc, "\ "tags, features" self.coalesced_text_test() diff --git a/test/test_description_per_sort_by.py b/test/test_description_per_sort_by.py index 82ae037..2f73fe3 100644 --- a/test/test_description_per_sort_by.py +++ b/test/test_description_per_sort_by.py @@ -1,37 +1,39 @@ from test.test_description import TestDescription from unittest import TestCase +from selenium.webdriver.common.by import By + class TestDescriptionPerSortBy(TestDescription, TestCase): def setUp(self): super(TestDescriptionPerSortBy, self).setUp() - self.driver.find_element_by_id( - 'button-for-showing-sort-option').click() + self.driver.find_element( + By.ID, 'button-for-showing-sort-option').click() def test_description_per_sort_by_stars(self): - self.driver.find_element_by_id( - 'sortByStars' - ).find_element_by_xpath('..').click() + self.driver.find_element( + By.ID, 'sortByStars' + ).find_element(By.XPATH, '..').click() self.sorted_by = "stars, date, name, minVer, license" self.coalesced_text_test() def test_description_per_sort_by_License(self): - self.driver.find_element_by_id( - 'sortByLicense' - ).find_element_by_xpath('..').click() + self.driver.find_element( + By.ID, 'sortByLicense' + ).find_element(By.XPATH, '..').click() self.sorted_by = "license, date, stars, name, minVer" self.coalesced_text_test() def test_description_per_sort_by_minVer(self): - self.driver.find_element_by_id( - 'sortByMinVer' - ).find_element_by_xpath('..').click() + self.driver.find_element( + By.ID, 'sortByMinVer' + ).find_element(By.XPATH, '..').click() self.sorted_by = "minVer, date, stars, name, license" self.coalesced_text_test() def test_description_per_sort_by_name(self): - self.driver.find_element_by_id( - 'sortByName' - ).find_element_by_xpath('..').click() + self.driver.find_element( + By.ID, 'sortByName' + ).find_element(By.XPATH, '..').click() self.sorted_by = "name, date, stars, minVer, license" self.coalesced_text_test() diff --git a/test/test_description_per_tags.py b/test/test_description_per_tags.py index 68054c5..3e36938 100644 --- a/test/test_description_per_tags.py +++ b/test/test_description_per_tags.py @@ -1,67 +1,69 @@ +import re +from secrets import choice from test.test_description import TestDescription from unittest import TestCase -from secrets import choice -import re + +from selenium.webdriver.common.by import By class TestDescriptionPerTags(TestDescription, TestCase): def setUp(self): super(TestDescriptionPerTags, self).setUp() - self.driver.find_element_by_id('button-for-filter-by-tags').click() + self.driver.find_element(By.ID, 'button-for-filter-by-tags').click() self.match = re.compile(r'^(.*)(\s\(\d*\))$') def test_description_per_tags(self): - tagSelectionRow = self.driver.find_element_by_id( - 'tagSelectionRow') + tagSelectionRow = self.driver.find_element( + By.ID, 'tagSelectionRow') inputs = [ x.get_attribute( 'id' - ) for x in tagSelectionRow.find_elements_by_tag_name( - 'input' + ) for x in tagSelectionRow.find_elements( + By.TAG_NAME, 'input' ) ] for x in inputs: - button = self.driver.find_element_by_id( - x).find_element_by_xpath('..') + button = self.driver.find_element( + By.ID, x).find_element(By.XPATH, '..') self.tags = self.match.search( - button.find_element_by_tag_name('label').text).group(1) + button.find_element(By.TAG_NAME, 'label').text).group(1) button.click() self.coalesced_text_test() - self.driver.find_element_by_id( - x).find_element_by_xpath('..').click() + self.driver.find_element( + By.ID, x).find_element(By.XPATH, '..').click() def test_description_per_tags_random(self): self.randomly_select_tag() def randomly_select_tag(self): - tagSelectionRow = self.driver.find_element_by_id( - 'tagSelectionRow') + tagSelectionRow = self.driver.find_element( + By.ID, 'tagSelectionRow') inputs = [ x.get_attribute( 'id' - ) for x in tagSelectionRow.find_elements_by_tag_name( - 'input' + ) for x in tagSelectionRow.find_elements( + By.TAG_NAME, 'input' ) ] unchecked_inputs = [ - x for x in inputs if self.driver.find_element_by_id( - x).is_selected() is False + x for x in inputs if self.driver.find_element( + By.ID, x).is_selected() is False ] if len(unchecked_inputs) > 0: random_input = choice(unchecked_inputs) - button = self.driver.find_element_by_id( - random_input).find_element_by_xpath('..') + button = self.driver.find_element( + By.ID, random_input).find_element(By.XPATH, '..') tag = self.match.search( - button.find_element_by_tag_name('label').text).group(1) + button.find_element(By.TAG_NAME, 'label').text).group(1) button.click() diff --git a/test/test_filterby_features.py b/test/test_filterby_features.py index 8d179d8..ded64fa 100644 --- a/test/test_filterby_features.py +++ b/test/test_filterby_features.py @@ -1,9 +1,11 @@ +from ast import literal_eval +from test.database import get_themes_orderedby_cname +from test.test_filterby_tags import MATCH from test.test_selenium import TestSelenium from unittest import TestCase -from test.database import get_themes_orderedby_cname -from ast import literal_eval + from bs4 import BeautifulSoup -from test.test_filterby_tags import MATCH +from selenium.webdriver.common.by import By class TestFilterByFeatures(TestSelenium, TestCase): @@ -17,22 +19,22 @@ class TestFilterByFeatures(TestSelenium, TestCase): 'sortByName', 'button-for-filter-by-features', ]: - self.driver.find_element_by_id(x).click() + self.driver.find_element(By.ID, x).click() def test_filterby_features(self): filterby_features_inputs = self.get_filter_by_features_inputs() for feature in filterby_features_inputs: - self.driver.find_element_by_id( - f"{feature}-feature-selection-input").click() + self.driver.find_element( + By.ID, f"{feature}-feature-selection-input").click() self.themes = [x for x in get_themes_orderedby_cname() if x.features_list is not None and feature in literal_eval(x.features_list)] self.update_features_available() - featureSelectionRow = self.driver.find_element_by_id( - 'featureSelectionRow') + featureSelectionRow = self.driver.find_element( + By.ID, 'featureSelectionRow') buttons = BeautifulSoup( featureSelectionRow.get_attribute( 'innerHTML'), features='lxml').findAll('button') @@ -47,7 +49,7 @@ class TestFilterByFeatures(TestSelenium, TestCase): self.features_available[button_feature]['num_themes'] ) - results_table_div = self.driver.find_element_by_id('results') + results_table_div = self.driver.find_element(By.ID, 'results') rows = BeautifulSoup(results_table_div.get_attribute( 'innerHTML'), features='lxml').find('table').findAll('tr') @@ -73,13 +75,13 @@ class TestFilterByFeatures(TestSelenium, TestCase): ], ) - self.driver.find_element_by_id( - f"{feature}-feature-selection-input").click() + self.driver.find_element( + By.ID, f"{feature}-feature-selection-input").click() def get_filter_by_features_inputs(self): - div = self.driver.find_element_by_id('featureSelectionRow') + div = self.driver.find_element(By.ID, 'featureSelectionRow') return [x.get_attribute('id')[:-24] - for x in div.find_elements_by_tag_name('input')] + for x in div.find_elements(By.TAG_NAME, 'input')] def update_features_available(self): self.features_available = {} diff --git a/test/test_filterby_license.py b/test/test_filterby_license.py index d5cdb64..b35b970 100644 --- a/test/test_filterby_license.py +++ b/test/test_filterby_license.py @@ -1,7 +1,9 @@ +from test.database import get_themes_orderedby_cname from test.test_selenium import TestSelenium from unittest import TestCase -from test.database import get_themes_orderedby_cname + from bs4 import BeautifulSoup +from selenium.webdriver.common.by import By class TestFilterByLicense(TestSelenium, TestCase): @@ -15,21 +17,21 @@ class TestFilterByLicense(TestSelenium, TestCase): 'sortByName', 'button-for-filter-by-license', ]: - self.driver.find_element_by_id(x).click() + self.driver.find_element(By.ID, x).click() self.themes = get_themes_orderedby_cname() def test_filter_by_license(self): filterby_lic_inputs = [x.get_attribute('id')[:-24] - for x in self.driver.find_element_by_id( - 'licenseSelectionRow').find_elements_by_tag_name('input')] + for x in self.driver.find_element( + By.ID, 'licenseSelectionRow').find_elements(By.TAG_NAME, 'input')] for license in filterby_lic_inputs: - self.driver.find_element_by_id( - f"{license}-license-selection-input").click() + self.driver.find_element( + By.ID, f"{license}-license-selection-input").click() themes = list( filter(lambda x: x.theme_license == license, self.themes) ) - results_table_div = self.driver.find_element_by_id('results') + results_table_div = self.driver.find_element(By.ID, 'results') rows = BeautifulSoup(results_table_div.get_attribute( 'innerHTML'), features='lxml').find('table').findAll('tr') @@ -47,5 +49,5 @@ class TestFilterByLicense(TestSelenium, TestCase): themes[i].theme_license, ], ) - self.driver.find_element_by_id( - f"{license}-license-selection-input").click() + self.driver.find_element( + By.ID, f"{license}-license-selection-input").click() diff --git a/test/test_filterby_minver.py b/test/test_filterby_minver.py index 86eb7a5..faf6429 100644 --- a/test/test_filterby_minver.py +++ b/test/test_filterby_minver.py @@ -1,7 +1,9 @@ -from test.test_selenium import TestSelenium -from unittest import TestCase from test.database import get_themes_orderedby_cname -from test.theme_compare import semver_split, compare_jk +from test.test_selenium import TestSelenium +from test.theme_compare import compare_jk, semver_split +from unittest import TestCase +from selenium.webdriver.common.by import By + from bs4 import BeautifulSoup @@ -16,17 +18,17 @@ class TestFilterByMinVer(TestSelenium, TestCase): 'sortByName', 'button-for-filter-by-minver', ]: - self.driver.find_element_by_id(x).click() + self.driver.find_element(By.ID, x).click() self.themes = get_themes_orderedby_cname() def test_filter_by_min_ver(self): filterby_mv_inputs = [x.get_attribute('id')[0:-33] - for x in self.driver.find_element_by_id( - 'minVerSelectionRow').find_elements_by_tag_name('input')] + for x in self.driver.find_element( + By.ID, 'minVerSelectionRow').find_elements(By.TAG_NAME, 'input')] for m_ver in filterby_mv_inputs: - self.driver.find_element_by_id( - f'{m_ver}-select-minver-radio-button-input').click() + self.driver.find_element( + By.ID, f'{m_ver}-select-minver-radio-button-input').click() if m_ver == 'none': themes = self.themes else: @@ -38,7 +40,7 @@ class TestFilterByMinVer(TestSelenium, TestCase): ) != 1, self.themes ) ) - results_table_div = self.driver.find_element_by_id('results') + results_table_div = self.driver.find_element(By.ID, 'results') rows = BeautifulSoup(results_table_div.get_attribute( 'innerHTML'), features='lxml').find('table').findAll('tr') diff --git a/test/test_filterby_tags.py b/test/test_filterby_tags.py index 193861e..10e3e48 100644 --- a/test/test_filterby_tags.py +++ b/test/test_filterby_tags.py @@ -4,6 +4,7 @@ from test.database import get_themes_orderedby_cname from ast import literal_eval from bs4 import BeautifulSoup import re +from selenium.webdriver.common.by import By MATCH = re.compile(r'^(.*)(\s\(\d*\))$') @@ -18,22 +19,22 @@ class TestFilterByTags(TestSelenium, TestCase): 'sortByName', 'button-for-filter-by-tags', ]: - self.driver.find_element_by_id(x).click() + self.driver.find_element(By.ID, x).click() self.themes = get_themes_orderedby_cname() def test_filter_by_tags(self): filterby_tags_inputs = self.get_filter_by_tags_inputs() for tag in filterby_tags_inputs: - self.driver.find_element_by_id( - f"{tag}-tag-selection-input").click() + self.driver.find_element( + By.ID, f"{tag}-tag-selection-input").click() themes = [x for x in self.themes if x.tags_list is not None and tag in literal_eval(x.tags_list)] self.update_tags_available(themes) - tagSelectionRow = self.driver.find_element_by_id('tagSelectionRow') + tagSelectionRow = self.driver.find_element(By.ID, 'tagSelectionRow') buttons = BeautifulSoup( tagSelectionRow.get_attribute( 'innerHTML'), features='lxml').findAll('button') @@ -50,7 +51,7 @@ class TestFilterByTags(TestSelenium, TestCase): self.tags_available[button_tag]['num_themes'] ) - results_table_div = self.driver.find_element_by_id('results') + results_table_div = self.driver.find_element(By.ID, 'results') rows = BeautifulSoup(results_table_div.get_attribute( 'innerHTML'), features='lxml').find('table').findAll('tr') @@ -75,13 +76,13 @@ class TestFilterByTags(TestSelenium, TestCase): ], ) - self.driver.find_element_by_id( - f"{tag}-tag-selection-input").click() + self.driver.find_element( + By.ID, f"{tag}-tag-selection-input").click() def get_filter_by_tags_inputs(self): - div = self.driver.find_element_by_id('tagSelectionRow') + div = self.driver.find_element(By.ID, 'tagSelectionRow') return [x.get_attribute('id')[:-20] - for x in div.find_elements_by_tag_name('input')] + for x in div.find_elements(By.TAG_NAME, 'input')] def update_tags_available(self, themes): self.tags_available = {} diff --git a/test/test_minus_button.py b/test/test_minus_button.py index 7180449..e8cabee 100644 --- a/test/test_minus_button.py +++ b/test/test_minus_button.py @@ -1,14 +1,16 @@ from test.test_selenium import TestSelenium from unittest import TestCase +from selenium.webdriver.common.by import By + class TestMinusButton(TestSelenium, TestCase): def setUp(self): super(TestMinusButton, self).setUp() - self.plus_button = self.driver.find_element_by_id('plus-button') - self.minus_button = self.driver.find_element_by_id('minus-button') - self.selection_options_menu = self.driver.find_element_by_id( - 'selection-options-menu') + self.plus_button = self.driver.find_element(By.ID, 'plus-button') + self.minus_button = self.driver.find_element(By.ID, 'minus-button') + self.selection_options_menu = self.driver.find_element( + By.ID, 'selection-options-menu') def test_minus_button_props(self): self.assertEqual( diff --git a/test/test_multiple_filters.py b/test/test_multiple_filters.py index a622c43..7a9532f 100644 --- a/test/test_multiple_filters.py +++ b/test/test_multiple_filters.py @@ -1,10 +1,12 @@ -from test.test_selenium import TestSelenium -from unittest import TestCase +from ast import literal_eval from secrets import choice from test.database import get_themes_orderedby_cname -from ast import literal_eval -from bs4 import BeautifulSoup from test.test_filterby_tags import MATCH +from test.test_selenium import TestSelenium +from unittest import TestCase + +from bs4 import BeautifulSoup +from selenium.webdriver.common.by import By class TestMultipleFilters(TestSelenium, TestCase): @@ -20,7 +22,7 @@ class TestMultipleFilters(TestSelenium, TestCase): 'sortByName', 'button-for-filter-by-features', ]: - self.driver.find_element_by_id(x).click() + self.driver.find_element(By.ID, x).click() self.current_filter = 'features' self.selected_tags = [] self.selected_features = [] @@ -32,7 +34,7 @@ class TestMultipleFilters(TestSelenium, TestCase): self.check_table_contents() def check_table_contents(self): - results_table_div = self.driver.find_element_by_id('results') + results_table_div = self.driver.find_element(By.ID, 'results') rows = BeautifulSoup(results_table_div.get_attribute( 'innerHTML'), features='lxml').find('table').findAll('tr') @@ -95,16 +97,16 @@ class TestMultipleFilters(TestSelenium, TestCase): tc_from_button, tc_from_selfdotthemes, msg=feature_from_button) def update_available_licenses(self): - licenseSelectionRow = self.driver.find_element_by_id( - 'licenseSelectionRow') + licenseSelectionRow = self.driver.find_element( + By.ID, 'licenseSelectionRow') self.license_buttons = BeautifulSoup( licenseSelectionRow.get_attribute('innerHTML'), features='lxml' ).findAll('button') def set_unchecked_features(self): - featureSelectionRow = self.driver.find_element_by_id( - 'featureSelectionRow') - inputs = featureSelectionRow.find_elements_by_tag_name('input') + featureSelectionRow = self.driver.find_element( + By.ID, 'featureSelectionRow') + inputs = featureSelectionRow.find_elements(By.TAG_NAME, 'input') self.unchecked_features = [ x.get_attribute('id')[:-24] for x in inputs if not x.is_selected() ] @@ -113,9 +115,9 @@ class TestMultipleFilters(TestSelenium, TestCase): ).findAll('button') def set_unchecked_tags(self): - tagSelectionRow = self.driver.find_element_by_id( - 'tagSelectionRow') - inputs = tagSelectionRow.find_elements_by_tag_name('input') + tagSelectionRow = self.driver.find_element( + By.ID, 'tagSelectionRow') + inputs = tagSelectionRow.find_elements(By.TAG_NAME, 'input') self.unchecked_tags = [ x.get_attribute('id')[:-20] for x in inputs if not x.is_selected() ] @@ -148,29 +150,29 @@ class TestMultipleFilters(TestSelenium, TestCase): def check_random_feature(self): if len(self.unchecked_features) > 0: random_feature = choice(self.unchecked_features[:2]) - self.driver.find_element_by_id( - f"{random_feature}-feature-selection-input").click() + self.driver.find_element( + By.ID, f"{random_feature}-feature-selection-input").click() self.selected_features.append(random_feature) self.update_lists() def check_random_tag(self): if len(self.unchecked_tags) > 0: random_tag = choice(self.unchecked_tags[:2]) - self.driver.find_element_by_id( - f"{random_tag}-tag-selection-input").click() + self.driver.find_element( + By.ID, f"{random_tag}-tag-selection-input").click() self.selected_tags.append(random_tag) self.update_lists() def multiple_filter_test(self): if self.current_filter == 'tags': self.current_filter = 'features' - self.driver.find_element_by_id( - 'button-for-filter-by-features').click() + self.driver.find_element( + By.ID, 'button-for-filter-by-features').click() self.add_feature_filter() if self.current_filter == 'features': self.current_filter = 'tags' - self.driver.find_element_by_id( - 'button-for-filter-by-tags').click() + self.driver.find_element( + By.ID, 'button-for-filter-by-tags').click() self.add_tag_filter() def has_tags_and_features(self, tl, fl): diff --git a/test/test_plus_button.py b/test/test_plus_button.py index 3534aa1..dbc4f3f 100644 --- a/test/test_plus_button.py +++ b/test/test_plus_button.py @@ -1,14 +1,16 @@ from test.test_selenium import TestSelenium from unittest import TestCase +from selenium.webdriver.common.by import By + class TestPlusButton(TestSelenium, TestCase): def setUp(self): super(TestPlusButton, self).setUp() - self.plus_button = self.driver.find_element_by_id('plus-button') - self.minus_button = self.driver.find_element_by_id('minus-button') - self.selection_options_menu = self.driver.find_element_by_id( - 'selection-options-menu') + self.plus_button = self.driver.find_element(By.ID, 'plus-button') + self.minus_button = self.driver.find_element(By.ID, 'minus-button') + self.selection_options_menu = self.driver.find_element( + By.ID, 'selection-options-menu') def test_plus_button_props(self): self.assertEqual( diff --git a/test/test_scroll.py b/test/test_scroll.py index c408dd0..7c13613 100644 --- a/test/test_scroll.py +++ b/test/test_scroll.py @@ -1,12 +1,14 @@ from test.test_selenium import TestSelenium from unittest import TestCase +from selenium.webdriver.common.by import By + class TestScroll(TestSelenium, TestCase): def setUp(self): super(TestScroll, self).setUp() - self.plus_button = self.driver.find_element_by_id('plus-button') - self.minus_button = self.driver.find_element_by_id('minus-button') + self.plus_button = self.driver.find_element(By.ID, 'plus-button') + self.minus_button = self.driver.find_element(By.ID, 'minus-button') def test_get_scroll_position(self): self.assertEqual( diff --git a/test/test_selection_options_menu.py b/test/test_selection_options_menu.py index b7fd83a..6637e3b 100644 --- a/test/test_selection_options_menu.py +++ b/test/test_selection_options_menu.py @@ -1,6 +1,8 @@ from test.test_selenium import TestSelenium from unittest import TestCase +from selenium.webdriver.common.by import By + DBI = [ 'button-for-showing-sort-option', 'button-for-showing-columns', @@ -29,25 +31,25 @@ FLEXROWS = [ class TestSelectionOptionsMenu(TestSelenium, TestCase): def setUp(self): super(TestSelectionOptionsMenu, self).setUp() - self.driver.find_element_by_id('plus-button').click() - self.div = self.driver.find_element_by_id('selection-options-menu') + self.driver.find_element(By.ID, 'plus-button').click() + self.div = self.driver.find_element(By.ID, 'selection-options-menu') def display_is_d_test(self, y_list, d): for x in y_list: self.assertEqual( - self.driver.find_element_by_id( - x).value_of_css_property('display'), d) + self.driver.find_element( + By.ID, x).value_of_css_property('display'), d) def test_default_selection_options_menu_buttons_exist(self): self.display_is_d_test(DBI, 'block') ids = [x.get_attribute( - 'id') for x in self.div.find_elements_by_tag_name('button')] + 'id') for x in self.div.find_elements(By.TAG_NAME, 'button')] self.assertEqual(ids, DBI) def test_buttons(self): self.display_is_d_test(DBI, 'block') for i, x in enumerate(DBI): - button = self.driver.find_element_by_id(x) + button = self.driver.find_element(By.ID, x) button.click() self.assertEqual(button.value_of_css_property('display'), 'none') self.display_is_d_test([*DBI[0:i], *DBI[i + 1:]], 'block') diff --git a/test/test_selenium.py b/test/test_selenium.py index d453ffd..65f4e6f 100644 --- a/test/test_selenium.py +++ b/test/test_selenium.py @@ -1,8 +1,11 @@ -from unittest import TestCase from pathlib import Path +from unittest import TestCase + from selenium import webdriver -from selenium.webdriver.chrome.service import Service from selenium.webdriver.chrome.options import Options +from selenium.webdriver.chrome.service import Service +from selenium.webdriver.common.by import By + OPTIONS = Options() OPTIONS.add_argument('--ignore-certificate-errors') OPTIONS.add_argument('--incognito') @@ -25,5 +28,5 @@ class TestSelenium(TestCase): class TestIDsForDuplicates(TestSelenium, TestCase): def test_for_unique_ids(self): ids = [x.get_attribute( - 'id') for x in self.driver.find_elements_by_xpath('//*[@id]')] + 'id') for x in self.driver.find_elements(By.XPATH, '//*[@id]')] self.assertEqual(len(ids), len(set(ids))) diff --git a/test/test_showing_columns.py b/test/test_showing_columns.py index 1fd38dd..5221a70 100644 --- a/test/test_showing_columns.py +++ b/test/test_showing_columns.py @@ -1,41 +1,43 @@ import re +from ast import literal_eval +from test.database import get_themes_orderedby_cname from test.test_selenium import TestSelenium from unittest import TestCase + from bs4 import BeautifulSoup as Bs -from test.database import get_themes_orderedby_cname -from ast import literal_eval +from selenium.webdriver.common.by import By class TestShowingColumns(TestSelenium, TestCase): def setUp(self): super(TestShowingColumns, self).setUp() - self.driver.find_element_by_id('plus-button').click() - self.driver.find_element_by_id( - 'button-for-showing-sort-option').click() - self.driver.find_element_by_id('sortByName').click() - self.driver.find_element_by_id( - 'button-for-showing-columns').click() + self.driver.find_element(By.ID, 'plus-button').click() + self.driver.find_element( + By.ID, 'button-for-showing-sort-option').click() + self.driver.find_element(By.ID, 'sortByName').click() + self.driver.find_element( + By.ID, 'button-for-showing-columns').click() self.themes = get_themes_orderedby_cname() self.tc = len(self.themes) def test_non_default_table(self): - self.driver.find_element_by_id( - 'min_ver-column-selection-input').click() - self.driver.find_element_by_id( - 'license-column-selection-input').click() - self.driver.find_element_by_id( - 'desc-column-selection-input').click() - self.driver.find_element_by_id( - 'tags-column-selection-input').click() - self.driver.find_element_by_id( - 'features-column-selection-input').click() - self.driver.find_element_by_id( - 'date-column-selection-input').click() - self.driver.find_element_by_id( - 'num_stars-column-selection-input').click() - self.driver.find_element_by_id( - 'commit-column-selection-input').click() - results_table_div = self.driver.find_element_by_id('results') + self.driver.find_element( + By.ID, 'min_ver-column-selection-input').click() + self.driver.find_element( + By.ID, 'license-column-selection-input').click() + self.driver.find_element( + By.ID, 'desc-column-selection-input').click() + self.driver.find_element( + By.ID, 'tags-column-selection-input').click() + self.driver.find_element( + By.ID, 'features-column-selection-input').click() + self.driver.find_element( + By.ID, 'date-column-selection-input').click() + self.driver.find_element( + By.ID, 'num_stars-column-selection-input').click() + self.driver.find_element( + By.ID, 'commit-column-selection-input').click() + results_table_div = self.driver.find_element(By.ID, 'results') rows = Bs(results_table_div.get_attribute( 'innerHTML'), features='lxml').find('table').findAll('tr') @@ -80,7 +82,7 @@ class TestShowingColumns(TestSelenium, TestCase): ) def test_default_table(self): - results_table_div = self.driver.find_element_by_id('results') + results_table_div = self.driver.find_element(By.ID, 'results') rows = Bs(results_table_div.get_attribute( 'innerHTML'), features='lxml').find('table').findAll('tr') diff --git a/test/test_sort_by.py b/test/test_sort_by.py index 827db30..7859ab7 100644 --- a/test/test_sort_by.py +++ b/test/test_sort_by.py @@ -5,6 +5,7 @@ from itertools import permutations from test.theme_compare import theme_compare from functools import cmp_to_key from bs4 import BeautifulSoup +from selenium.webdriver.common.by import By SBB = [ 'sortByDate', @@ -26,7 +27,7 @@ class TestsSortBy(TestSelenium, TestCase): 'license-column-selection-input', 'button-for-showing-sort-option', ]: - self.driver.find_element_by_id(x).click() + self.driver.find_element(By.ID, x).click() self.themes = get_themes_as_dicts_of_sortable_columns() self.tc = len(self.themes) @@ -43,11 +44,11 @@ class TestsSortBy(TestSelenium, TestCase): reverse order of the current permutation ''' for x in y[::-1]: - self.driver.find_element_by_id(x).click() + self.driver.find_element(By.ID, x).click() sort_by_inputs = [x.get_attribute( - 'id') for x in self.driver.find_element_by_id( - 'sortByRow').find_elements_by_tag_name('input')] + 'id') for x in self.driver.find_element( + By.ID, 'sortByRow').find_elements(By.TAG_NAME, 'input')] ''' and then assert that the sort_by button row is now in the same order left->right, as the current @@ -61,7 +62,7 @@ class TestsSortBy(TestSelenium, TestCase): self.themes.sort( key=cmp_to_key(lambda a, b: theme_compare(a, b, y))) - results_table_div = self.driver.find_element_by_id('results') + results_table_div = self.driver.find_element(By.ID, 'results') rows = BeautifulSoup(results_table_div.get_attribute( 'innerHTML'), features='lxml').find('table').findAll('tr') diff --git a/test/test_title.py b/test/test_title.py index 0db49a6..99548d9 100644 --- a/test/test_title.py +++ b/test/test_title.py @@ -1,11 +1,13 @@ from test.test_selenium import TestSelenium from unittest import TestCase +from selenium.webdriver.common.by import By + class TestTitle(TestSelenium, TestCase): def setUp(self): super(TestTitle, self).setUp() - self.x = self.driver.find_elements_by_tag_name('h1') + self.x = self.driver.find_elements(By.TAG_NAME, 'h1') def test_title(self): self.assertEqual(len(self.x), 1) @@ -21,7 +23,7 @@ class TestTitle(TestSelenium, TestCase): self.x[0].value_of_css_property('font-family'), 'sans-serif') def test_title_anchor(self): - x_anchors = self.x[0].find_elements_by_tag_name('a') + x_anchors = self.x[0].find_elements(By.TAG_NAME, 'a') self.assertEqual(len(x_anchors), 1) self.assertEqual( x_anchors[0].get_attribute('href'),