Cannot access Browser Login prompt/dialog

Hi,

When I access the login page for a network device, a credentials popup opens as shown below. Katalon studio does not record actions or we cannot do any spy object within this window.Is this because that window is not a web element? I am using Katalon Studio web version 7.7.2. Thanks.

hope this helps you browserpopup

add in your script

import java.awt.Robot as Robot
import java.awt.event.KeyEvent as KeyEvent

def th = new Thread((({
for (i = 0; i < 10; i++) {
Robot robot = new Robot()
Thread.sleep(5000)
robot.keyPress(KeyEvent.VK_ENTER)
Thread.sleep(1000)
break
}
}) as Runnable))

and add below code just before the action where popup displays

th.start()

Hello, i have followed your recommendation above but it fails after the th.start() line. Here is my code:

@Keyword
def activateSCP(result,username,password){

	def th = new Thread((({
		for (i = 0; i < 10; i++) {
			Robot robot = new Robot()
			Thread.sleep(5000)
			robot.keyPress(KeyEvent.VK_ENTER)
			Thread.sleep(1000)
			break
		}
	}) as Runnable))



	//Enter username and password
	WebUI.executeJavaScript('window.open();', [])
	String currentWindow =  WebUI.getWindowIndex()
	//Go in to new tab
	WebUI.switchToWindowIndex(currentWindow + 1)
	WebUI.navigateToUrl(GlobalVariable.activationURL)

	th.start()

	WebUI.click(findTestObject(inputUsername))
	WebUI.setText(findTestObject(inputUsername),username)
	WebUI.click(findTestObject(inputPassword))
	WebUI.setText(findTestObject(inputPassword),password)
	WebUI.click(findTestObject(signIn))
	//Click on activation field
	WebUI.click(findTestObject(inputActivationCode))
	WebUI.setText(findTestObject(inputActivationCode),result)
	WebUI.click(findTestObject(activateButton))
	//Coming back
	WebUI.switchToWindowIndex(currentWindow)
	//Verify that the camera has been enrolled
}

FYI, it says it cannot find the test object. That is normal because i cannot spy on that object. Is there a solution/workaround for this? Thanks.

Hello,

Any comments on this? Thanks.

I m sorry for delay, not sure why it is not identifying the popup, can you try on another browser. if still face the issue, ask your developers (try to enable popup) . let me know what they say thanks

Hi, it does not work on edge also. I think the reason is because this is not an html popup.If i right click on any element, i cannot inspect.

What is “it”?

Always include the complete error message.


Aside: It is my strong belief that when writing test case code, there are very, very few situations where threading is a requirement or even a benefit. So few, in fact, I have never come across one.

If you don’t need added complexity, don’t add it.

Basically, when I select the spy web to spy on any object in that popup, I dont have the option to capture the object. Even if I record a test case, it will not record any actions on any object within that popup.

You posted that statement beneath Test Case code. Therefore, what the Spy tool does is irrelevant.

Ok lets ignore the code, I was using that code because it was suggested to me to fix the problem. Let’s recap. I have an HTML URL (see below) that I would need to access to change something within that web page. When I access the web page, a credentials popup is shown (See below). Katalon Studio web will not let me do a spy object on any of the elements within that popup (eg: username/password, sign In, etc). That is the issue I am encountering. Any thoughts? comments?

I see no reason why Robot wouldn’t work there, as long as you get the timing right (I noticed you need to switch windows/tabs). Be sure you arrive at the new window in a timely manner and run the robot code. To move from Name to Password, use a Tab key.

My advice, remove the thread stuff but keep the closure (everything between { and }) and call it from your test case at the correct step position (i.e. after the new window/tab is open and ready).

Lastly, let’s see if we can get @Brandon_Hein to take a look - I think he posted something relevant to basic auth dialogs a while back…

1 Like

From within the robot code, I fail to see where the actually setting of the username and password is done. Note that I have copied the code given to me exactly as is.DO i need to adapt it to my needs?
It is currently failing at where the setText command is ran. This is because it cannot find the object. DO i need to include this somehow in the robot part of the code? If so, how? Thanks.

@Keyword
def activateSCP(result,username,password){
//Enter username and password
WebUI.executeJavaScript(‘window.open();’, [])
String currentWindow = WebUI.getWindowIndex()
//Go in to new tab
WebUI.switchToWindowIndex(currentWindow + 1)
WebUI.delay(5)
int i
def th = new Thread((({
for (i = 0; i < 10; i++) {
Robot robot = new Robot()
Thread.sleep(5000)
robot.keyPress(KeyEvent.VK_ENTER)
Thread.sleep(1000)
break
}
}) as Runnable))

	th.start()

	WebUI.navigateToUrl(GlobalVariable.mobotixActivationURL)
	WebUI.setText(findTestObject(inputUsername),username)
	WebUI.click(findTestObject(inputPassword))
	WebUI.setText(findTestObject(inputPassword),password)
	WebUI.click(findTestObject(signIn))
	//Click on activation field
	WebUI.click(findTestObject(inputActivationCode))
	WebUI.setText(findTestObject(inputActivationCode),result)
	WebUI.click(findTestObject(activateButton))
	//Coming back
	WebUI.switchToWindowIndex(currentWindow)
	//Verify that the camera has been enrolled

}

In essence, the Robot API targets the OS, just like a user does when (s)he uses the keyboard or mouse - no user ever has to specify the text input directly, they type into the control with focus, or set it first with a click. Then the OS directs the keyboard keys to the control.

See?

That’s why I said, as long as you get the timing right and Be sure you arrive at the new window in a timely manner. The dialog should be allowed time to appear, THEN you can execute the Robot code.

Again - that thread stuff is NOT included in my advice. I’m working under the assumption it’s not there.

Sorry i’m confused. How is the text set in the username/password fields? What am I missing in the code I provided? Right now it just shows the sign-in popup and stops there. Thanks.

I removed the thread stuff, here is what my code looks like. Also, the for look iterates 10 times, not sure what that is for to be honest. I used this code as suggested in my script. What do i need to do to adapt it to my test case? Ie: login to the web page with credentials.
Thanks.

@Keyword
def activateSCP(result,username,password){
//Enter username and password
WebUI.executeJavaScript(‘window.open();’, [])
String currentWindow = WebUI.getWindowIndex()
//Go in to new tab
WebUI.switchToWindowIndex(currentWindow + 1)
WebUI.delay(5)
int i
//def th = new Thread((({
for (i = 0; i < 10; i++) {
Robot robot = new Robot()
//Thread.sleep(5000)
//robot.keyPress(KeyEvent.VK_ENTER)
//Thread.sleep(1000)
break
}
//}) as Runnable))

	//th.start()

	WebUI.navigateToUrl(GlobalVariable.mobotixActivationURL)
	//WebUI.click(findTestObject(inputUsername))
	WebUI.setText(findTestObject(inputUsername),username)
	WebUI.click(findTestObject(inputPassword))
	WebUI.setText(findTestObject(inputPassword),password)
	WebUI.click(findTestObject(signIn))
	//Click on activation field
	WebUI.click(findTestObject(inputActivationCode))
	WebUI.setText(findTestObject(inputActivationCode),result)
	WebUI.click(findTestObject(activateButton))
	//Coming back
	WebUI.switchToWindowIndex(currentWindow)
	//Verify that the camera has been enrolled

}

Like you said, you need to adapt that code for your purposes.

Yes I am aware of that. I would like to know how do i set text in the username/password field using the robot code? I haven;t found anything to help me with this. I was hoping I would get help from someone in the forum. Thanks.

Back in the day, we used to do something like this:

driver.get("http://username:password@www.example.com");

i.e. you provide the login credentials in the app URL. I’m not sure if this works anymore, but you could give it a try.

Hi Brandon, thanks for the tip. When I specify driver.get it shows it as underlined. Do i need to import something? Thanks

Yes, you need to get the driver instance like so:

def driver = DriverFactory.getWebDriver()

Once you enter this line of code, press ctrl + shift + o on your keyboard to organize the necessary imports.