I am wanting to build web-based testing tools for test website environments utilizing the Selenium Web Driver. I am building a GUI which will contain the following: Drop-down for selecting the website, toggle button for selecting the testing environment and a button for launching the specified browser you wish to test the previous criteria in. The drop-down for the website and the toggles will dynamically build a URL based off of the choices (not currently in this code).
Example: I pick Google, then toggle I want to test on TestEnv1 and I want the program to launch the website on env1 using Firefox.
Future goals:
Drop-down implementation that can read the tests that are to be auto-ran which will have selenium tests created for them. This drop-down would be incorporated to allow nearly full-automation for testing.
After creating my mock-up GUI and putting in some sample code my current version looks something similar to:
package automationFramework;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.JFrame;
import javax.swing.JComboBox;
import java.awt.BorderLayout;
import javax.swing.JButton;
import javax.swing.JRadioButton;
import javax.swing.JToggleButton;
import javax.swing.AbstractButton;
import javax.swing.ButtonGroup;
import javax.swing.ButtonModel;
import javax.swing.DefaultButtonModel;
import javax.swing.DefaultComboBoxModel;
public class Dynamic_Browser_and_Site {
private JFrame frame;
public int n;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Dynamic_Browser_and_Site window = new Dynamic_Browser_and_Site();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public Dynamic_Browser_and_Site() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 500, 250);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
// Site Drop-Down
JComboBox siteList = new JComboBox();
siteList.setToolTipText("Choose the website you would like to begin testing on.");
siteList.setModel(new DefaultComboBoxModel(new String[] {"\"Choose your site...\"", "Google", "Yahoo", "Microsoft", "Apple"}));
siteList.setMaximumRowCount(5);
siteList.setBounds(0, 0, 484, 20);
frame.getContentPane().add(siteList);
// Browser Buttons
JButton btnFF = new JButton("Firefox");
btnFF.setBounds(10, 146, 125, 55);
frame.getContentPane().add(btnFF);
btnFF.setEnabled(false);
JButton btnIE = new JButton("Internet Explorer");
btnIE.setBounds(349, 146, 125, 55);
frame.getContentPane().add(btnIE);
btnIE.setEnabled(false);
JButton btnCH = new JButton("Chrome");
btnCH.setBounds(180, 146, 125, 55);
frame.getContentPane().add(btnCH);
btnCH.setEnabled(false);
// Toggle Buttons
JToggleButton tglbtnEnv1 = new JToggleButton("TestEnv1");
tglbtnEnv1.setBounds(10, 65, 90, 55);
frame.getContentPane().add(tglbtnEnv1);
JToggleButton tglbtnEnv2 = new JToggleButton("TestEnv2");
tglbtnEnv2.setBounds(135, 65, 90, 55);
frame.getContentPane().add(tglbtnEnv2);
JToggleButton tglbtnEnv3 = new JToggleButton("TestEnv3");
tglbtnEnv3.setBounds(260, 65, 90, 55);
frame.getContentPane().add(tglbtnEnv3);
JToggleButton tglbtnEnv4 = new JToggleButton("TestEnv4");
tglbtnEnv4.setBounds(384, 65, 90, 55);
frame.getContentPane().add(tglbtnEnv4);
// Button Group Array for toggling environments
ButtonGroup group = new ButtonGroup();
group.add(tglbtnEnv1);
group.add(tglbtnEnv2);
group.add(tglbtnEnv3);
group.add(tglbtnEnv4);
// System.out.println(tglbtnEnv1.getAction());
// TestEnv1 toggle prompt
tglbtnEnv1.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent ev) {
if(ev.getStateChange()==ItemEvent.SELECTED){
System.out.println(tglbtnEnv1.getActionCommand( ));
System.out.println("button is selected");
// Toggle browser buttons
btnFF.setEnabled(true);
btnCH.setEnabled(true);
btnIE.setEnabled(true);
System.out.println("Firefox button enabled");
System.out.println("Chrome button enabled");
System.out.println("Internet Explorer button enabled");
} else{
System.out.println("button is not selected");
}
}
});
// TestEnv2 toggle prompt
tglbtnEnv2.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent ev) {
if(ev.getStateChange()==ItemEvent.SELECTED){
System.out.println(tglbtnEnv2.getActionCommand( ));
System.out.println("button is selected");
// Toggle browser buttons
btnFF.setEnabled(true);
btnCH.setEnabled(true);
btnIE.setEnabled(true);
System.out.println("Firefox button enabled");
System.out.println("Chrome button enabled");
System.out.println("Internet Explorer button enabled");
} else{
System.out.println("button is not selected");
}
}
});
// TestEnv3 toggle prompt
tglbtnEnv3.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent ev) {
if(ev.getStateChange()==ItemEvent.SELECTED){
System.out.println(tglbtnEnv3.getActionCommand( ));
System.out.println("button is selected");
// Toggle browser buttons
btnFF.setEnabled(true);
btnCH.setEnabled(true);
btnIE.setEnabled(true);
System.out.println("Firefox button enabled");
System.out.println("Chrome button enabled");
System.out.println("Internet Explorer button enabled");
} else{
System.out.println("button is not selected");
}
}
});
// TestEnv4 toggle prompt
tglbtnEnv4.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent ev) {
if(ev.getStateChange()==ItemEvent.SELECTED){
System.out.println(tglbtnEnv4.getActionCommand( ));
System.out.println("button is selected");
// Toggle browser buttons
btnFF.setEnabled(true);
btnCH.setEnabled(true);
btnIE.setEnabled(true);
System.out.println("Firefox button enabled");
System.out.println("Chrome button enabled");
System.out.println("Internet Explorer button enabled");
} else{
System.out.println("button is not selected");
}
}
});
}
}
I am wanting to know of any concerns or tips to further improve and optimize this code.