Menu

LoginScreen Example - Finder method

Help
ramshyam
2008-11-05
2013-04-09
  • ramshyam

    ramshyam - 2008-11-05

    Hi all,

    I am new to JFCUnit. I went through the LoginScreen example and tried to simulate the same and found that the there is some problem in NamedComponentFinder finder object. Eventually, any component in the loginScreen panel is returned as null.
    Following is the code I have used -
    ==============================================

    NamedComponentFinder finder = new NamedComponentFinder(JComponent.class, "Log In" );
            JButton loginButton = ( JButton ) finder.find( loginPanel, 0);
            assertNotNull( "Could not find the Exit button", loginButton );
           
       
           
            finder.setName( "Username" );
            JTextField userNameField = ( JTextField ) finder.find( loginPanel, 1 );
            assertNotNull( "Could not find the userNameField", userNameField );
            assertEquals( "Username field is empty", "", userNameField.getText( ) );

            getHelper().enterClickAndLeave( new MouseEventData( this, loginButton ) );
            DialogFinder dFinder = new DialogFinder( "Log In" );
            List showingDialogs = dFinder.findAll();
            assertEquals( "Number of dialogs showing is wrong", 1, showingDialogs.size( ) );
            JDialog dialog = ( JDialog )showingDialogs.get( 0 );
            assertEquals( "Wrong dialog showing up", "Login Error", dialog.getTitle( ) );
            getHelper().disposeWindow( dialog, this );

    ===============================================

    where LoginPanel is of type JPanel and contains the following code -

    ===============================================
    final JTextField userNameField      = new JTextField(16);
            final JPasswordField passwordField  = new JPasswordField(16);
            loginPanel = new JPanel();
            GridLayout grid = new GridLayout(3,2);
            loginPanel.setLayout(grid);
           
            JLabel userNameLabel = new JLabel(Settings.getLocalString(SALabels.LOGIN_USERNAME), JLabel.RIGHT);
            userNameLabel.setFont(Settings.LABEL_FONT);
            userNameLabel.setForeground(Settings.LABEL_COLOR);
            loginPanel.add(userNameLabel);
            loginPanel.add(userNameField);
           
            JLabel passwordLabel = new JLabel(Settings.getLocalString(SALabels.LOGIN_PASSWORD), JLabel.RIGHT);
            passwordLabel.setFont(Settings.LABEL_FONT);
            passwordLabel.setForeground(Settings.LABEL_COLOR);
            loginPanel.add(passwordLabel);
            loginPanel.add(passwordField);
           
            loginPanel.add(new JButton("Log In"));
            loginPanel.add(new JButton("Cancel"));
    =================================================

    Please let me know if I am missing anything here and let me know why the components are always returned as null.

    Thanks in advance!!

     
    • Jero Cortés

      Jero Cortés - 2009-02-11

      Hi!

      you can download an Eclipse project with a correct example using NamedComponentFinder with the "Log in example".

      http://www.megaupload.com/es/?d=DHCMKNXL

       

Log in to post a comment.