Fixed #30975 -- Replaced custom get_select_option with Selenium's select_by_value.
This commit is contained in:
parent
69dbb6b708
commit
249a6190ae
|
@ -141,17 +141,23 @@ class AdminSeleniumTestCase(SeleniumTestCase, StaticLiveServerTestCase):
|
||||||
return self.selenium.execute_script(
|
return self.selenium.execute_script(
|
||||||
'return django.jQuery("%s").css("%s")' % (selector, attribute))
|
'return django.jQuery("%s").css("%s")' % (selector, attribute))
|
||||||
|
|
||||||
def get_select_option(self, selector, value):
|
def select_option(self, selector, value):
|
||||||
"""
|
"""
|
||||||
Return the <OPTION> with the value `value` inside the <SELECT> widget
|
Select the <OPTION> with the value `value` inside the <SELECT> widget
|
||||||
identified by the CSS selector `selector`.
|
identified by the CSS selector `selector`.
|
||||||
"""
|
"""
|
||||||
from selenium.common.exceptions import NoSuchElementException
|
from selenium.webdriver.support.ui import Select
|
||||||
options = self.selenium.find_elements_by_css_selector('%s > option' % selector)
|
select = Select(self.selenium.find_element_by_css_selector(selector))
|
||||||
for option in options:
|
select.select_by_value(value)
|
||||||
if option.get_attribute('value') == value:
|
|
||||||
return option
|
def deselect_option(self, selector, value):
|
||||||
raise NoSuchElementException('Option "%s" not found in "%s"' % (value, selector))
|
"""
|
||||||
|
Deselect the <OPTION> with the value `value` inside the <SELECT> widget
|
||||||
|
identified by the CSS selector `selector`.
|
||||||
|
"""
|
||||||
|
from selenium.webdriver.support.ui import Select
|
||||||
|
select = Select(self.selenium.find_element_by_css_selector(selector))
|
||||||
|
select.deselect_by_value(value)
|
||||||
|
|
||||||
def _assertOptionsValues(self, options_selector, values):
|
def _assertOptionsValues(self, options_selector, values):
|
||||||
if values:
|
if values:
|
||||||
|
|
|
@ -4503,7 +4503,7 @@ class SeleniumTests(AdminSeleniumTestCase):
|
||||||
|
|
||||||
# Main form ----------------------------------------------------------
|
# Main form ----------------------------------------------------------
|
||||||
self.selenium.find_element_by_id('id_pubdate').send_keys('2012-02-18')
|
self.selenium.find_element_by_id('id_pubdate').send_keys('2012-02-18')
|
||||||
self.get_select_option('#id_status', 'option two').click()
|
self.select_option('#id_status', 'option two')
|
||||||
self.selenium.find_element_by_id('id_name').send_keys(' this is the mAin nÀMë and it\'s awεšomeııı')
|
self.selenium.find_element_by_id('id_name').send_keys(' this is the mAin nÀMë and it\'s awεšomeııı')
|
||||||
slug1 = self.selenium.find_element_by_id('id_slug1').get_attribute('value')
|
slug1 = self.selenium.find_element_by_id('id_slug1').get_attribute('value')
|
||||||
slug2 = self.selenium.find_element_by_id('id_slug2').get_attribute('value')
|
slug2 = self.selenium.find_element_by_id('id_slug2').get_attribute('value')
|
||||||
|
@ -4515,7 +4515,7 @@ class SeleniumTests(AdminSeleniumTestCase):
|
||||||
# Stacked inlines ----------------------------------------------------
|
# Stacked inlines ----------------------------------------------------
|
||||||
# Initial inline
|
# Initial inline
|
||||||
self.selenium.find_element_by_id('id_relatedprepopulated_set-0-pubdate').send_keys('2011-12-17')
|
self.selenium.find_element_by_id('id_relatedprepopulated_set-0-pubdate').send_keys('2011-12-17')
|
||||||
self.get_select_option('#id_relatedprepopulated_set-0-status', 'option one').click()
|
self.select_option('#id_relatedprepopulated_set-0-status', 'option one')
|
||||||
self.selenium.find_element_by_id('id_relatedprepopulated_set-0-name').send_keys(
|
self.selenium.find_element_by_id('id_relatedprepopulated_set-0-name').send_keys(
|
||||||
' here is a sŤāÇkeð inline ! '
|
' here is a sŤāÇkeð inline ! '
|
||||||
)
|
)
|
||||||
|
@ -4536,7 +4536,7 @@ class SeleniumTests(AdminSeleniumTestCase):
|
||||||
num_initial_select2_inputs + 2
|
num_initial_select2_inputs + 2
|
||||||
)
|
)
|
||||||
self.selenium.find_element_by_id('id_relatedprepopulated_set-1-pubdate').send_keys('1999-01-25')
|
self.selenium.find_element_by_id('id_relatedprepopulated_set-1-pubdate').send_keys('1999-01-25')
|
||||||
self.get_select_option('#id_relatedprepopulated_set-1-status', 'option two').click()
|
self.select_option('#id_relatedprepopulated_set-1-status', 'option two')
|
||||||
self.selenium.find_element_by_id('id_relatedprepopulated_set-1-name').send_keys(
|
self.selenium.find_element_by_id('id_relatedprepopulated_set-1-name').send_keys(
|
||||||
' now you haVe anöther sŤāÇkeð inline with a very ... '
|
' now you haVe anöther sŤāÇkeð inline with a very ... '
|
||||||
'loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog text... '
|
'loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog text... '
|
||||||
|
@ -4551,7 +4551,7 @@ class SeleniumTests(AdminSeleniumTestCase):
|
||||||
# Tabular inlines ----------------------------------------------------
|
# Tabular inlines ----------------------------------------------------
|
||||||
# Initial inline
|
# Initial inline
|
||||||
self.selenium.find_element_by_id('id_relatedprepopulated_set-2-0-pubdate').send_keys('1234-12-07')
|
self.selenium.find_element_by_id('id_relatedprepopulated_set-2-0-pubdate').send_keys('1234-12-07')
|
||||||
self.get_select_option('#id_relatedprepopulated_set-2-0-status', 'option two').click()
|
self.select_option('#id_relatedprepopulated_set-2-0-status', 'option two')
|
||||||
self.selenium.find_element_by_id('id_relatedprepopulated_set-2-0-name').send_keys(
|
self.selenium.find_element_by_id('id_relatedprepopulated_set-2-0-name').send_keys(
|
||||||
'And now, with a tÃbűlaŘ inline !!!'
|
'And now, with a tÃbűlaŘ inline !!!'
|
||||||
)
|
)
|
||||||
|
@ -4567,7 +4567,7 @@ class SeleniumTests(AdminSeleniumTestCase):
|
||||||
num_initial_select2_inputs + 4
|
num_initial_select2_inputs + 4
|
||||||
)
|
)
|
||||||
self.selenium.find_element_by_id('id_relatedprepopulated_set-2-1-pubdate').send_keys('1981-08-22')
|
self.selenium.find_element_by_id('id_relatedprepopulated_set-2-1-pubdate').send_keys('1981-08-22')
|
||||||
self.get_select_option('#id_relatedprepopulated_set-2-1-status', 'option one').click()
|
self.select_option('#id_relatedprepopulated_set-2-1-status', 'option one')
|
||||||
self.selenium.find_element_by_id('id_relatedprepopulated_set-2-1-name').send_keys(
|
self.selenium.find_element_by_id('id_relatedprepopulated_set-2-1-name').send_keys(
|
||||||
r'a tÃbűlaŘ inline with ignored ;"&*^\%$#@-/`~ characters'
|
r'a tÃbűlaŘ inline with ignored ;"&*^\%$#@-/`~ characters'
|
||||||
)
|
)
|
||||||
|
|
|
@ -1038,15 +1038,17 @@ class HorizontalVerticalFilterSeleniumTests(AdminWidgetSeleniumTestCase):
|
||||||
self.assertActiveButtons(mode, field_name, False, False, True, False)
|
self.assertActiveButtons(mode, field_name, False, False, True, False)
|
||||||
|
|
||||||
# Choose some options ------------------------------------------------
|
# Choose some options ------------------------------------------------
|
||||||
from_lisa_select_option = self.get_select_option(from_box, str(self.lisa.id))
|
from_lisa_select_option = self.selenium.find_element_by_css_selector(
|
||||||
|
'{} > option[value="{}"]'.format(from_box, self.lisa.id)
|
||||||
|
)
|
||||||
|
|
||||||
# Check the title attribute is there for tool tips: ticket #20821
|
# Check the title attribute is there for tool tips: ticket #20821
|
||||||
self.assertEqual(from_lisa_select_option.get_attribute('title'), from_lisa_select_option.get_attribute('text'))
|
self.assertEqual(from_lisa_select_option.get_attribute('title'), from_lisa_select_option.get_attribute('text'))
|
||||||
|
|
||||||
from_lisa_select_option.click()
|
self.select_option(from_box, str(self.lisa.id))
|
||||||
self.get_select_option(from_box, str(self.jason.id)).click()
|
self.select_option(from_box, str(self.jason.id))
|
||||||
self.get_select_option(from_box, str(self.bob.id)).click()
|
self.select_option(from_box, str(self.bob.id))
|
||||||
self.get_select_option(from_box, str(self.john.id)).click()
|
self.select_option(from_box, str(self.john.id))
|
||||||
self.assertActiveButtons(mode, field_name, True, False, True, False)
|
self.assertActiveButtons(mode, field_name, True, False, True, False)
|
||||||
self.selenium.find_element_by_id(choose_link).click()
|
self.selenium.find_element_by_id(choose_link).click()
|
||||||
self.assertActiveButtons(mode, field_name, False, False, True, True)
|
self.assertActiveButtons(mode, field_name, False, False, True, True)
|
||||||
|
@ -1061,12 +1063,14 @@ class HorizontalVerticalFilterSeleniumTests(AdminWidgetSeleniumTestCase):
|
||||||
])
|
])
|
||||||
|
|
||||||
# Check the tooltip is still there after moving: ticket #20821
|
# Check the tooltip is still there after moving: ticket #20821
|
||||||
to_lisa_select_option = self.get_select_option(to_box, str(self.lisa.id))
|
to_lisa_select_option = self.selenium.find_element_by_css_selector(
|
||||||
|
'{} > option[value="{}"]'.format(to_box, self.lisa.id)
|
||||||
|
)
|
||||||
self.assertEqual(to_lisa_select_option.get_attribute('title'), to_lisa_select_option.get_attribute('text'))
|
self.assertEqual(to_lisa_select_option.get_attribute('title'), to_lisa_select_option.get_attribute('text'))
|
||||||
|
|
||||||
# Remove some options -------------------------------------------------
|
# Remove some options -------------------------------------------------
|
||||||
self.get_select_option(to_box, str(self.lisa.id)).click()
|
self.select_option(to_box, str(self.lisa.id))
|
||||||
self.get_select_option(to_box, str(self.bob.id)).click()
|
self.select_option(to_box, str(self.bob.id))
|
||||||
self.assertActiveButtons(mode, field_name, False, True, True, True)
|
self.assertActiveButtons(mode, field_name, False, True, True, True)
|
||||||
self.selenium.find_element_by_id(remove_link).click()
|
self.selenium.find_element_by_id(remove_link).click()
|
||||||
self.assertActiveButtons(mode, field_name, False, False, True, True)
|
self.assertActiveButtons(mode, field_name, False, False, True, True)
|
||||||
|
@ -1079,8 +1083,8 @@ class HorizontalVerticalFilterSeleniumTests(AdminWidgetSeleniumTestCase):
|
||||||
self.assertSelectOptions(to_box, [str(self.jason.id), str(self.john.id)])
|
self.assertSelectOptions(to_box, [str(self.jason.id), str(self.john.id)])
|
||||||
|
|
||||||
# Choose some more options --------------------------------------------
|
# Choose some more options --------------------------------------------
|
||||||
self.get_select_option(from_box, str(self.arthur.id)).click()
|
self.select_option(from_box, str(self.arthur.id))
|
||||||
self.get_select_option(from_box, str(self.cliff.id)).click()
|
self.select_option(from_box, str(self.cliff.id))
|
||||||
self.selenium.find_element_by_id(choose_link).click()
|
self.selenium.find_element_by_id(choose_link).click()
|
||||||
|
|
||||||
self.assertSelectOptions(from_box, [
|
self.assertSelectOptions(from_box, [
|
||||||
|
@ -1093,8 +1097,8 @@ class HorizontalVerticalFilterSeleniumTests(AdminWidgetSeleniumTestCase):
|
||||||
])
|
])
|
||||||
|
|
||||||
# Choose some more options --------------------------------------------
|
# Choose some more options --------------------------------------------
|
||||||
self.get_select_option(from_box, str(self.peter.id)).click()
|
self.select_option(from_box, str(self.peter.id))
|
||||||
self.get_select_option(from_box, str(self.lisa.id)).click()
|
self.select_option(from_box, str(self.lisa.id))
|
||||||
|
|
||||||
# Confirm they're selected after clicking inactive buttons: ticket #26575
|
# Confirm they're selected after clicking inactive buttons: ticket #26575
|
||||||
self.assertSelectedOptions(from_box, [str(self.peter.id), str(self.lisa.id)])
|
self.assertSelectedOptions(from_box, [str(self.peter.id), str(self.lisa.id)])
|
||||||
|
@ -1102,12 +1106,12 @@ class HorizontalVerticalFilterSeleniumTests(AdminWidgetSeleniumTestCase):
|
||||||
self.assertSelectedOptions(from_box, [str(self.peter.id), str(self.lisa.id)])
|
self.assertSelectedOptions(from_box, [str(self.peter.id), str(self.lisa.id)])
|
||||||
|
|
||||||
# Unselect the options ------------------------------------------------
|
# Unselect the options ------------------------------------------------
|
||||||
self.get_select_option(from_box, str(self.peter.id)).click()
|
self.deselect_option(from_box, str(self.peter.id))
|
||||||
self.get_select_option(from_box, str(self.lisa.id)).click()
|
self.deselect_option(from_box, str(self.lisa.id))
|
||||||
|
|
||||||
# Choose some more options --------------------------------------------
|
# Choose some more options --------------------------------------------
|
||||||
self.get_select_option(to_box, str(self.jason.id)).click()
|
self.select_option(to_box, str(self.jason.id))
|
||||||
self.get_select_option(to_box, str(self.john.id)).click()
|
self.select_option(to_box, str(self.john.id))
|
||||||
|
|
||||||
# Confirm they're selected after clicking inactive buttons: ticket #26575
|
# Confirm they're selected after clicking inactive buttons: ticket #26575
|
||||||
self.assertSelectedOptions(to_box, [str(self.jason.id), str(self.john.id)])
|
self.assertSelectedOptions(to_box, [str(self.jason.id), str(self.john.id)])
|
||||||
|
@ -1115,8 +1119,8 @@ class HorizontalVerticalFilterSeleniumTests(AdminWidgetSeleniumTestCase):
|
||||||
self.assertSelectedOptions(to_box, [str(self.jason.id), str(self.john.id)])
|
self.assertSelectedOptions(to_box, [str(self.jason.id), str(self.john.id)])
|
||||||
|
|
||||||
# Unselect the options ------------------------------------------------
|
# Unselect the options ------------------------------------------------
|
||||||
self.get_select_option(to_box, str(self.jason.id)).click()
|
self.deselect_option(to_box, str(self.jason.id))
|
||||||
self.get_select_option(to_box, str(self.john.id)).click()
|
self.deselect_option(to_box, str(self.john.id))
|
||||||
|
|
||||||
# Pressing buttons shouldn't change the URL.
|
# Pressing buttons shouldn't change the URL.
|
||||||
self.assertEqual(self.selenium.current_url, original_url)
|
self.assertEqual(self.selenium.current_url, original_url)
|
||||||
|
@ -1186,14 +1190,14 @@ class HorizontalVerticalFilterSeleniumTests(AdminWidgetSeleniumTestCase):
|
||||||
# Choosing a filtered option sends it properly to the 'to' box.
|
# Choosing a filtered option sends it properly to the 'to' box.
|
||||||
input.send_keys('a')
|
input.send_keys('a')
|
||||||
self.assertSelectOptions(from_box, [str(self.arthur.id), str(self.jason.id)])
|
self.assertSelectOptions(from_box, [str(self.arthur.id), str(self.jason.id)])
|
||||||
self.get_select_option(from_box, str(self.jason.id)).click()
|
self.select_option(from_box, str(self.jason.id))
|
||||||
self.selenium.find_element_by_id(choose_link).click()
|
self.selenium.find_element_by_id(choose_link).click()
|
||||||
self.assertSelectOptions(from_box, [str(self.arthur.id)])
|
self.assertSelectOptions(from_box, [str(self.arthur.id)])
|
||||||
self.assertSelectOptions(to_box, [
|
self.assertSelectOptions(to_box, [
|
||||||
str(self.lisa.id), str(self.peter.id), str(self.jason.id),
|
str(self.lisa.id), str(self.peter.id), str(self.jason.id),
|
||||||
])
|
])
|
||||||
|
|
||||||
self.get_select_option(to_box, str(self.lisa.id)).click()
|
self.select_option(to_box, str(self.lisa.id))
|
||||||
self.selenium.find_element_by_id(remove_link).click()
|
self.selenium.find_element_by_id(remove_link).click()
|
||||||
self.assertSelectOptions(from_box, [str(self.arthur.id), str(self.lisa.id)])
|
self.assertSelectOptions(from_box, [str(self.arthur.id), str(self.lisa.id)])
|
||||||
self.assertSelectOptions(to_box, [str(self.peter.id), str(self.jason.id)])
|
self.assertSelectOptions(to_box, [str(self.peter.id), str(self.jason.id)])
|
||||||
|
@ -1209,7 +1213,7 @@ class HorizontalVerticalFilterSeleniumTests(AdminWidgetSeleniumTestCase):
|
||||||
# -----------------------------------------------------------------
|
# -----------------------------------------------------------------
|
||||||
# Pressing enter on a filtered option sends it properly to
|
# Pressing enter on a filtered option sends it properly to
|
||||||
# the 'to' box.
|
# the 'to' box.
|
||||||
self.get_select_option(to_box, str(self.jason.id)).click()
|
self.select_option(to_box, str(self.jason.id))
|
||||||
self.selenium.find_element_by_id(remove_link).click()
|
self.selenium.find_element_by_id(remove_link).click()
|
||||||
input.send_keys('ja')
|
input.send_keys('ja')
|
||||||
self.assertSelectOptions(from_box, [str(self.jason.id)])
|
self.assertSelectOptions(from_box, [str(self.jason.id)])
|
||||||
|
|
Loading…
Reference in New Issue