Cannot access Browser Login prompt/dialog

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.

OK i have done that but it brings be back to the same issue. I am at the sign-in page. To summarize what the test case is expected to do is the following.
a) It gets an activation code from a web page,
b) opens a new tab and navigates to the camera web page where this activation code will be used.
c) Need to sign-in to this activation web page.
d) The function takes username/password as parameters,

eg: lets say the username is “admin”.

How do i know what keys to press using the robot? What are the command lines I need to use for this?
robot.keyPress(KeyEvent.XXXX);

What is XXXX in this case? Is that even possible to achieve?
Thanks

I’ve never used Robot to do this. This is a browser-level notification, so aside from passing the credentials in the URL, you may try and handling it with desired capabilities:

@Brandon_Hein

Thanks for stepping up, Brandon.

@mgrandillo I was hoping your Robot code (with keypresses for “admin” etc) would just work after the login panel appears. Hopefully, the panel places the focus in the Username field - right? Then using Robot, you can TAB to the password field and issue the keypresses for the password. Then, finally, issue an ENTER keypress.

That said, and since the auth seems to be indicating plain-text, I fancy Brandon’s original idea (credentials in the URL) has a good chance of working. Try it. It’s the easiest approach, by far - then you can ditch all that Robot stuff.

I find a very easy solution thanks to Brandon.

WebUI.authenticate(URL, ‘admin’, ‘Password’, 12)

That will sign in and the rest is trivial. Thanks again Brandon for the idea :slight_smile:

1 Like

2 posts were split to a new topic: Can’t get value from field

yes, just got lazy lol, thank you sir!!!