Saturday, December 30, 2017

To resolve the issue in Selenium WebDriver

driver = new  PhantomJSDriver(caps);
Dimension dim= new Dimension(1440, 900);
driver.manage().window().setSize(dim);

Click here for more topics

Saturday, December 23, 2017

try{
Image image = ImageIO.read(new File("Path\\images\\system-tray-icon.png"));
frame.setIconImage(image);
            }
             catch(NullPointerException | IOException n1){
             n1.printStackTrace();
             }
Image image = ImageIO.read(new File("Path\\images\\system-tray-icon.png"));
        // create a popup menu
         PopupMenu popup = new PopupMenu();
         // create menu item for the default action
         MenuItem defaultItem = new MenuItem("Run");
         defaultItem.addActionListener(listener);
         popup.add(defaultItem);
         /// ... add other items
         // construct a TrayIcon
         TrayIcon icon = new TrayIcon(image, "Tray Demo", popup);
       
     
        icon.setImageAutoSize(true);

Sunday, October 16, 2016

  • JAVA_HOME : C:\Program Files\Java\jdk1.8.0_102
  • JDK_HOME : %JAVA_HOME%
  • JRE_HOME : %JAVA_HOME%\jre
  • CLASSPATH :.;%JAVA_HOME%\lib;%JAVA_HOME%\jre\lib
  • PATH : your-unique-entries;%JAVA_HOME%\bin (make sure that the longish your-unique-entries does not contain any other references to another Java installation folder.
Notice that all these environment variables are derived from the "root" environment variable JAVA_HOME. This makes it easy to update your environment variables when updating the JDK. Just point JAVA_HOME to the fresh installation.

Click here for more Selenium topics
In this I will show the code for creating TrayIcon for your Selenium Automation Suite User Interface


public class javaframe extends JFrame {

    private static JPanel contentPane;
    public static JTextField textField;
    public javaframe frame;
    /**
     * Launch the application.
     */
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
                    //UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
                } catch (UnsupportedLookAndFeelException ex) {
                    ex.printStackTrace();
                } catch (IllegalAccessException ex) {
                    ex.printStackTrace();
                } catch (InstantiationException ex) {
                    ex.printStackTrace();
                } catch (ClassNotFoundException ex) {
                    ex.printStackTrace();
                }
                try {
                    javaframe frame = new javaframe();
                    frame.setVisible(true);                   
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the frame.
     */
    public javaframe() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(100, 100, 450, 300);
        contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        setContentPane(contentPane);
       
        JLabel lblNewLabel = new JLabel("URL");
       
        textField = new JTextField();
        textField.setColumns(10);
        textField.setText("http://www.");
       
        JButton btnNewButton = new JButton("Run");
        btnNewButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                Multi3 m1=new Multi3(); 
                Thread t1 =new Thread(m1); 
                t1.start(); 
            }
        });


                //Check the SystemTray is supported
        if (!SystemTray.isSupported()) {
            System.out.println("SystemTray is not supported");
            return;
        }
        final PopupMenu popup = new PopupMenu();
        final TrayIcon trayIcon =
                new TrayIcon(createImage("/images/selenium.gif", "tray icon"));
        final SystemTray tray = SystemTray.getSystemTray();
      
        // Create a pop-up menu components
        MenuItem aboutItem = new MenuItem("About");
        CheckboxMenuItem cb1 = new CheckboxMenuItem("Set auto size");
        CheckboxMenuItem cb2 = new CheckboxMenuItem("Set tooltip");
        Menu displayMenu = new Menu("Display");
        MenuItem errorItem = new MenuItem("Error");
        MenuItem warningItem = new MenuItem("Warning");
        MenuItem infoItem = new MenuItem("Info");
        MenuItem noneItem = new MenuItem("None");
        MenuItem exitItem = new MenuItem("Exit");
      
        //Add components to pop-up menu
        popup.add(aboutItem);
        popup.addSeparator();
        popup.add(cb1);
        popup.add(cb2);
        popup.addSeparator();
        popup.add(displayMenu);
        displayMenu.add(errorItem);
        displayMenu.add(warningItem);
        displayMenu.add(infoItem);
        displayMenu.add(noneItem);
        popup.add(exitItem);
      
        trayIcon.setPopupMenu(popup);
      
        try {
            tray.add(trayIcon);
        } catch (AWTException e) {
            System.out.println("TrayIcon could not be added.");
        }
       
    }
   
   

    protected static Image createImage(String path, String description) {
        URL imageURL = javaframe.class.getResource(path);
        
        if (imageURL == null) {
            System.err.println("Resource not found: " + path);
            return null;
        } else {
            return (new ImageIcon(imageURL, description)).getImage();
        }
    }
   
   
}
class Multi3 implements Runnable{ 

public void run(){ 
    Url url= new Url();
    url.openurl(javaframe.textField.getText());
}
}
This error usually happens if there is a conflict in the Java installations. It means there may be more than one installation of Java in your system. Mostly presence of Oracle Jinitiator in C:\Program Files (x86)\Oracle creates this problem.


Perhaps your file associations got messed up. At the command prompt, try running
ftype | find "jarfile"
On my 64-bit Windows 7 computer, that shows
jarfile="C:\Program Files (x86)\Java\jre6\bin\javaw.exe" -jar "%1" %*
You can also change it with ftype:
ftype jarfile="C:\Program Files (x86)\Java\jre6\bin\javaw.exe" -jar "%1" %*
 
and reboot the system. 
 
You may also uninstall the Jinitiator which is no longer supported by Oracle as per our knowledge. 
UI elements in a User Interface will not respond to the user while execution if a thread is not implemented. Here I will explain how to create a thread so that User Interface will keep responding to the user even when the execution is happening.

Create a class outside the Jframe class
class Multi3 implements Runnable{ 

public void run(){ 
    Url url= new Url();
    url.openurl(javaframe.textField.getText());
}
}

Call the Thread from any actionlistener like below

Multi3 m1=new Multi3(); 
                Thread t1 =new Thread(m1);
                t1.start();  
>

Selenium useful links

Powered by Blogger.

Featured Post

Benefits of having a user Interface for a Selenium Automation Suite/Regression Suite

Once you are able to work independently on Selenium scripting, another important task is how to ease your automation test execution. There a...

Video

Popular Posts

Our Facebook Page