Prompting User Input during automation

Hi, I am new to Katalon. Is there a way to prompt user for input? what is the code if any please. share . thank you Phil

1 Like

I don’t think you can unless your web application allows you to do this using some triggers.

I am using Java default JOptionPane, and it seems to be working fine for me.

Code:

JFrame frame = new JFrame(“User Input Frame”)

frame.requestFocus()

String url = JOptionPane.showInputDialog(frame, “Enter the website you would like to visit!”)

WebUI.openBrowser(’’)

WebUI.navigateToUrl(url)

WebUI.delay(10)

WebUI.closeBrowser()

5 Likes

Ng Sek Long said:

I am using Java default JOptionPane, and it seems to be working fine for me.

Code:

JFrame frame = new JFrame(“User Input Frame”)

frame.requestFocus()

String url = JOptionPane.showInputDialog(frame, “Enter the website you would like to visit!”)

WebUI.openBrowser(’’)

WebUI.navigateToUrl(url)

WebUI.delay(10)

WebUI.closeBrowser()

Thanks for sharing this, that worked like a charm.

Just to add to the above, I needed to import the below as well to get it to work

import javax.swing.JFrame
import javax.swing.JOptionPane

3 Likes

I second that. Solid!

for some reason i need to adjust the given code on my side to have it working.
nevertheless it indeed worked like a charm.

Here’s the adjusted code from my side.

//below are added manually libraries
import javax.swing.JOptionPane as JOptionPane
import javax.swing.JFrame as JFrame

JFrame frame = new JFrame(‘User Input Frame’)

frame.requestFocus()

url = JOptionPane.showInputDialog(frame, ‘Enter the website you would like to visit!’)

WebUI.openBrowser(url)

Unfortunately I am getting an error when using this.

"Expecting ‘(’ or ‘[’ after type name to continue new expression @line 90 column 20.

Can anyone help? Thanks!

Worked well for me!

Thanks for sharing the code!

i had to manually add the following libraries, but that was okay! :slight_smile:

import javax.swing.JFrame
import javax.swing.JOptionPane
import java.awt.Component

1 Like

Wasn’t expecting this to blow up :slight_smile: So forget to add how library should be included… Thanks for adding comment about how to add library.

Another tips is that, instead of manually adding library, you can also use the following shortcut to add the missing library automatically:
Cltr + Shift + O

Although be ware that some library was added to you manually by Katalon like import internal.GlobalVariable as GlobalVariable, those would be remove upon pressing the above shortcut.

Hope this helps~

I am also facing the same issue.
“Expecting ‘(’ or ‘[’ after type name to continue new expression @line 28 column 20”
Is there any fix for that.

Thanks!