benjamin84 / fest

Automatically exported from code.google.com/p/fest
0 stars 0 forks source link

'selectItem' in JComboBoxFixture is not using CellReader. #140

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
From Wim:

I'm using the new cellReader functionality to select something in a
JComboBox. However, it does not seem to work or I'm doing something wrong.

This is part of my test:

        DialogFixture dialogFixture = WindowFinder.findDialog(
CharacteristicFilterDataSelectionPanel.CharacteristicFilterEditDialog.class
).using( m_window.robot );
        dialogFixture.requireVisible();
        JComboBoxFixture comboBoxFixture = dialogFixture.comboBox(
CharacteristicFilterPanel.CHARACTERTISTIC_ID_COMBO_BOX );
        comboBoxFixture.cellReader( new JComboBoxCellReader()
        {
            public String valueAt( JComboBox comboBox, int index )
            {
                CharacteristicId id = (CharacteristicId)comboBox.getItemAt(
index );
                return id.getName();
            }
        } );
        comboBoxFixture.selectItem( "Olala" );

I get the following error:

org.fest.swing.exception.LocationUnavailableException: Unable to find item
'Olala' among the JComboBox contents (['BlaBla', 'Olala'])
    at
org.fest.swing.driver.JComboBoxDriver.selectItem(JComboBoxDriver.java:104)
    at
org.fest.swing.fixture.JComboBoxFixture.selectItem(JComboBoxFixture.java:287)
    at
com.traficon.app.tms.scenario.ui.inhibition.InhibitionConfigurationDialogTest.te
stAddInhibition(InhibitionConfigurationDialogTest.java:133)

The JCombBox has a renderer as follows:

    private static class CharacteristicIdListCellRenderer extends
DefaultListCellRenderer
    {
        @Override
        public Component getListCellRendererComponent( JList list, Object
value, int index, boolean isSelected, boolean cellHasFocus )
        {
            JLabel label = (JLabel)super.getListCellRendererComponent(
list, value, index, isSelected, cellHasFocus );
            if (value != null)
            {
                label.setText( ((CharacteristicId)value).getName() );
            }
            return label;
        }
    }

Original issue reported on code.google.com by Alex.Rui...@gmail.com on 27 May 2008 at 4:28

GoogleCodeExporter commented 9 years ago
I think I'm experiening the same problem, I did a little research and seems 
like if
sometimes in the class JComboBoxDriver the value in the list is compared 
againest the
actual object (which I doing a GUI test shouldn't even know) and in other 
methods
it's compared againest the right value also represented in the combo box.

For example if I require a selection
org.fest.swing.driver.JComboBoxDriver.requireSelection(JComboBox, String), I 
would
have to require the selection 'Olala'. But to select the item 'Olala' I might 
have to
select an object. In my opinion in the method
org.fest.swing.driver.JComboBoxDriver.selectItem(JComboBox, Object) the 
comparision
be changed from

      if (areEqual(itemAt(comboBox, i), value)) {

to

      if (areEqual(value(comboBox, i), value)) {

In my opinion if I'm testing the GUI and want to select the item 'Olala', I 
can't
know the object behind this item. The end-user neither knows it.

Original comment by matthi...@gmail.com on 28 May 2008 at 7:20

GoogleCodeExporter commented 9 years ago
Hi Mattias,

You are right. We were comparing to the value in the model instead of using the 
cell
reader. I just checked-in a fix :)

Best regards,
-Alex.

Original comment by Alex.Rui...@gmail.com on 28 May 2008 at 3:57

GoogleCodeExporter commented 9 years ago
Set the module as a label, instead of being part of the title.

Original comment by Alex.Rui...@gmail.com on 1 Dec 2008 at 1:59