Monday, January 12, 2015

Display Alert Message of Test case

We can display alert message in screen to know which test case is executing or to show user of respective action.



Method to display alert Message of test case -

public void Show_ScriptMessage_Close(String Message , int time) throws Exception
  {
     
      time = time * 1000; // 1 value to 1000
       final ImageIcon icon = new ImageIcon("C:\\Selenium\\Test_data\\prathip.png");
        final JOptionPane optionPane = new JOptionPane(Message, JOptionPane.INFORMATION_MESSAGE, JOptionPane.DEFAULT_OPTION, icon , new Object[]{}, null);

        final JDialog dialog = new JDialog();
        dialog.setTitle("Selenium Scripting - Prathip");
       
        dialog.setModal(true);
       
        dialog.setLocationRelativeTo(null);
        dialog.setLocation((Toolkit.getDefaultToolkit().getScreenSize().width)/2 - dialog.getWidth()/2, (Toolkit.getDefaultToolkit().getScreenSize().height)/2 - dialog.getHeight()/2);
        dialog.setContentPane(optionPane);

        dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
         
     
        dialog.pack();
       
      //create timer to dispose of dialog after 5 seconds
        // 1 sec = 1000
        Timer timer = new Timer(time, new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent ae) {
                dialog.dispose();
            }
        });
        timer.setRepeats(false);//the timer should only go off once

        //start timer to close JDialog as dialog modal we must start the timer before its visible
        timer.start();

        dialog.setVisible(true);
     
  }




how to call the function -

Show_ScriptMessage_Close("Google Search" , 5);


No comments:

Post a Comment