Issue
I need you guys advice. I created Selenium Automation script in Java for our testers. However, testers do not prefer to using Selenium Script which is not tester-friendly interface. Hence, what I am going to do is to develop a client program that interacts with selenium code that I developed. Say, they simply open the client GUI program and tick the check boxes they want to test and enter the testing detail and run it.
The probelm is that I don't know where I start from to make this client program. If it is possilbe to do so, what GUI framework or language is recommended?
Thank you in advance.
Solution
Yes. You can do that.
Create a GUI using
Java Swing
In
ActionListeners
integrate your selenium code.
This project I created by using both Java Swing
and Selenium
. You can refer the code for your purpose.
How to integrate selenium with GUI?
Let's say your automation scripts needs to be executed in multiple environments.
Create UI by providing a drop-down or radio buttons to select environment.
Provide a button called Execute to run your scripts. In
ActionListner
of Execute button you need to integrate your selenium code.
Sample code:
public class FrameSample extends JFrame {
JPanel pane;
JButton execute = new JButton("Execute");
public FrameSample() {
/* Properties of JPanel */
pane = new JPanel(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;
gbc.fill = GridBagConstraints.EAST;
gbc.gridwidth = 2;
gbc.insets = new Insets(0, 0, 0, 0);
pane.add(execute, gbc);
setName("Automation");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new BorderLayout());
setSize(300, 300);
setContentPane(pane);
setResizable(false);
setLocationRelativeTo(null);
setVisible(true);
setAlwaysOnTop(true);
execute.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
System.setProperty("webdriver.chrome.driver",
System.getProperty("user.dir") + "//Drivers//chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://www.google.com");
Thread.sleep(5000);
// Do yuor stuff
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
});
}
public static void main(String[] args) {
new FrameSample();
}
}
Output:
Imports:
import java.awt.BorderLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
Answered By - Nandan A
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.