deokyong song
deokyong song

Reputation: 160

Can I convert Selenium Automation scripts to GUI program?

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.

Upvotes: 2

Views: 1131

Answers (2)

Enrique Lopez
Enrique Lopez

Reputation: 172

You don't need to create a UI from scratch, there are some tools that you can use for that particular purpose, for example Jenkins.

Jenkins is a CI/CD tool that helps us to trigger our automated tests, no matter which automation framework you are using you can integrate your tests there, but you can also use this tool as a UI to trigger your tests suite.

So, if your team needs to run some tests they should be able to do it directly on Jenkins. You just need to create a new Jenkins job and configure it base on your needs and then provide the link to your peers. You can make it as easy as you want, from a single button or as hard as having many options, is up to your needs.

If you want to know more about how to use Jenkins you can find several courses just by typing "Jenkins" in youtube, Udemy or any other learning platform, it is pretty easy, you will save tons of time an energy with it.

Upvotes: 0

Nandan A
Nandan A

Reputation: 2922

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:

enter image description here

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;

Upvotes: 3

Related Questions